How to find an UIComponent in ADF page root and region?

By W.Zh  Nov 2014

If you want to locate an UIComponent in view root with its component id, here is a recursive way to achieve this.
    public static UIComponent findComponentInRoot(String id) {
UIComponent component = null;

FacesContext facesContext = FacesContext.getCurrentInstance();
if (facesContext != null) {
UIComponent root = facesContext.getViewRoot();
component = findComponent(root, id);
}

return component;
}

public static UIComponent findComponent(UIComponent base, String id) {
if (id.equals(base.getId()))
return base;

UIComponent kid = null;
UIComponent result = null;
Iterator kids = base.getFacetsAndChildren();
while (kids.hasNext() && (result == null)) {
kid = (UIComponent)kids.next();
if (id.equals(kid.getId())) {
result = kid;
break;
}
result = findComponent(kid, id);
if (result != null) {
break;
}
}
return result;
}

 

And if a tag is in region, you need to use this method to look up in the region tree nodes.

public static UIComponent getUIComponentInRegion(String regionId,
String componentId) {
RichRegion region = (RichRegion)findComponentInRoot(regionId);
UIComponent component = null;
if (region != null) {
component = findComponent(region, componentId);
}
return component;
}

The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit

W.ZH Oct 2014

Issue:

 Compiling at Jdev for the project get this error:

The code of method _jspService(HttpServletRequest, HttpServletResponse) is exceeding the 65535 bytes limit

 

Reason:

When JAVA compile a JSP into a servlet, the entire body of a JSP file will be placed inside a single try block. The limit which a Java block can contain is 64KB.

So that is the reason you see this error.  your JSP/JSPX is too long.

 

Solution:

Sometimes we see a rebuild of project can solve this, if not, then you have to split the JSP into small portion and include them to main page.

Perhaps you have extremely a lot of HTML or conditionals in the JSP file. You need to split the JSP file in smaller parts which you include by
<jsp:include>. For example one JSP include file per header, footer, menu, body and/or conditionally displayed parts, etc. It has the additional advantage that it’s better reuseable.

for JSP case:+++++++++++++++++++++++++++++++++

Static include <%@ include %> – During the translation or compilation phase all the included JSP pages are compiled into a single Servlet.

Dynamic include <jsp:include …..> – The dynamically included JSP is compiled into a separate Servlet. It is a separate resource, which gets to process the request, and the content generated by this resource is included in the JSP response.

JVM has a 64kb limit on the size of the method and the entire JSP page is rendered as a single method

(i.e. _jspService (..)). If a JSP page is greater than 64kb. When this method

reaches its JVM limit of 64kb, the JVM throws an error. This error can be overcome by splitting the JSP files and including

them dynamically (i.e. using <jsp:include…….>) because the dynamic includes generate a separate JSP Servlet for each

included file.

javascript at ADF jspx page make the buttons unclick-able on IE 11+ Win 8

By W.ZH July 2014

 

We used to have this kind of code to insert some javascript to the ADF pages.

<f:verbatim>

      <![CDATA[<!DOCTYPE html>]]>

      <![CDATA[


//javascript code here

               

            ]]>

</f:verbatim>

But we found it may cause issue when browse from Win8 + IE 11. This piece JS running on IE 11, just make the many buttons cannot be clicked on the page.

How to solve this problem?

Use this format to insert the javascript to the bottom of the jspx page.

           <af:resource type=”javascript” > 

//javascript code here

          </af:resource>

        </af:pageTemplate>

How to adjust your ADF page focus or vertical position after the ADF PPR running

By W.ZH July 2014

Issue: After you use PPR in ADF Partial Page Rendering, sometime you find your page focus is changed as page is too long and PPR always put page focus to the top of the page.

Solution: You can use the javascript to adjust your page focus after the PPR. Either to change to an input field’s focus(). Or change the page window.location.hash by js. Here is an example.

 

  • 1.     Put this js methods to your jspx page.

 

  <![CDATA[

               

                    function setFocusId(id) {

                        var t=document.getElementById(id);

                        t.focus();

                       }

                    function setLocationHash(hsh) {

                        hsh=”#”+hsh;

                        //this.current.hash=hsh;

                        document.location.hash=hsh;

                    }

               

            ]]>

  • 2.     Add this two method to your manage bean

    public void changeClientInputFoucs(String tagID) {

        String clientId = “”;

        FacesContext facesContext = FacesContext.getCurrentInstance();

        ExtendedRenderKitService service =

            (ExtendedRenderKitService)Service.getRenderKitService(facesContext,

                                                                  ExtendedRenderKitService.class);

        UIComponent ip = facesContext.getViewRoot().findComponent(tagID);

        clientId = ip.getClientId(facesContext);

        service.addScript(facesContext, “setFocusId(‘” + clientId + “‘);”);

        return;

    }

 

    public void changeClientWindowHash(String tagID) {

        String clientId = “”;

        FacesContext facesContext = FacesContext.getCurrentInstance();

        ExtendedRenderKitService service =

            (ExtendedRenderKitService)Service.getRenderKitService(facesContext,

                                                                  ExtendedRenderKitService.class);

        clientId = tagID;

        service.addScript(facesContext,

                          “setLocationHash(‘” + clientId + “‘);”);

        return;

}

 

 

  • 3.     Then at your action listener method code, you can use sth like this to control your page vertical location of hash. You are done.

AdfFacesContext.getCurrentInstance().addPartialTarget(yourPPRtag);

        changeClientWindowHash(“your_ADF_or_HTML_tag_ID”);

        return;

  • 4.     Or

        AdfFacesContext.getCurrentInstance().addPartialTarget(yourPPRtagID);

        changeClientInputFoucs(“pt1:XXX-your_ADF_tag_ID “);

        return;

 

 

                Enjoy it!

 

 

How to run javascript from ADF backing bean

By W.ZH Feb 2014
There are two ways can help on this topic:

 

1. You want to run a piece of the js from ADF backing bean, directly

        FacesContext facesContext = FacesContext.getCurrentInstance();
ExtendedRenderKitService service =
Service.getRenderKitService(facesContext,
ExtendedRenderKitService.class);
service.addScript(facesContext, “alert('my js showing');“);

2. You have a js function on the UI side already, when user click some button on the UI, you want you button also trigger this js method from the backing bean.

If you bind your UI component to the backing bean as the
HtmlCommandButton, not as the RichCommandButton, then setOnclick, setOndblclick, can help you to set them to run a javascript, and you also have chance to compose for your js function input.  I just copy code from this post
https://community.oracle.com/thread/399961 to here:

1. Small JavaScript Function in JSPX Page which gives the alert message with Hitcount of Command Button

<script language=”JavaScript”>
function showHitCount(count) {
alert(“Hit Count : ” + count);
}

2.. A Command Button (JSF Component) in JSPX Page with Code

<h:commandButton id=”b1″
value=”Invoke JavaScript from Backing Bean”
binding=”#{backing_TestBean.hitCount}”/>

3. One Backing Bean property for this command button in TestBean Backing Bean.

public class TestBean {

private HtmlCommandButton hitCount;
private int HitCount;
public TestBean() {
HitCount=0; }

public void setHitCount(HtmlCommandButton hitCount) {
System.out.println(“TestBean : setAlert();”);
hitCount.setOnclick(“showHitCount(” + (++HitCount) + “);”); this.hitCount = hitCount;
}

public HtmlCommandButton getHitCount() {
System.out.println(“TestBean : getAlert();”);
return hitCount;
}
}

 

Reference:

ADF common optimization for production performance

WZh Feb 2014

For ADF project There are some settings  you need in development and debug model, or in Jdev environment. But when you deploy your project to the p reroduction server to make it run, you many need to set them to different values to fit the production requirement or to improve the performance of the server. So you need to design a deploy plan to dynamic change these values when deploying, here is a sample to show common values.

<?xml version=’1.0′ encoding=’UTF-8′?>
<deployment-plan xmlns=”http://xmlns.oracle.com/weblogic/deployment-plan&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://xmlns.oracle.com/weblogic/deployment-plan http://xmlns.oracle.com/weblogic/deployment-plan/1.0/deployment-plan.xsd”&gt;
<application-name>YourAppNameHere(no .ear extension)</application-name>
<variable-definition>
<variable>
<name>falseValue</name>
<value>false</value>
</variable>
<variable>
<name>trueValue</name>
<value>true</value>
</variable>
<variable>
<name>TwoBacks</name>
<value>3</value>
</variable>
<variable>
<name>adfJavascriptLoggerLevel</name>
<value>NONE</value>
</variable>
<variable>
<name>SessionValueInMins</name>
<value>20</value>
</variable>
</variable-definition>
<module-override>
<module-name>YOURPROJECT.war</module-name>
<module-type>war</module-type>
<module-descriptor external=”false”>
<root-element>web-app</root-element>
<uri>WEB-INF/web.xml</uri>
<variable-assignment>
<name>falseValue</name>
<xpath>/web-app/context-param/[param-name=”org.apache.myfaces.trinidad.DEBUG_JAVASCRIPT”]/param-value</xpath>
<operation>replace</operation>
</variable-assignment>
<variable-assignment>
<name>falseValue</name>
<xpath>/web-app/context-param/[param-name=”org.apache.myfaces.trinidad.resource.DEBUG”]/param-value</xpath>
<operation>replace</operation>
</variable-assignment>
<variable-assignment>
<name>falseValue</name>
<xpath>/web-app/context-param/[param-name=”oracle.adf.view.rich.ASSERT_ENABLED”]/param-value</xpath>
<operation>replace</operation>
</variable-assignment>
<variable-assignment>
<name>falseValue</name>
<xpath>/web-app/context-param/[param-name=”org.apache.myfaces.trinidad.DISABLE_CONTENT_COMPRESSION”]/param-value</xpath>
<operation>replace</operation>
</variable-assignment>
<variable-assignment>
<name>falseValue</name>
<xpath>/web-app/context-param/[param-name=”oracle.adf.view.rich.LOGGER_LEVEL”]/param-value</xpath>
<operation>replace</operation>
</variable-assignment>
<variable-assignment>
<name>falseValue</name>
<xpath>/web-app/context-param/[param-name=”org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION”]/param-value</xpath>
<operation>replace</operation>
</variable-assignment>
<variable-assignment>
<name>TwoBacks</name>
<xpath>/web-app/context-param/[param-name=”org.apache.myfaces.trinidad.CLIENT_STATE_MAX_TOKENS”]/param-value</xpath>
<operation>replace</operation>
</variable-assignment>
<variable-assignment>
<name>SessionValueInMins</name>
<xpath>/web-app/session-config/session-timeout</xpath>
<operation>replace</operation>
</variable-assignment>
</module-descriptor>
</module-override>
</deployment-plan>


Reference:

http://www.redheap.com/2014/01/configuring-adf-faces-for-development.html

MDS-00168 error in Webcenter/ADF

W.Zh Feb 2014
Issue:

For web center or ADF portal project, sometimes you see some pic or css or static file not not been load successfully when the page rendering, so just part or a page without style is displayed on browser.This issue happens especially after a redeploy, but not all the time.   When you go to WLS server log, you can see some thing like this:

oracle.mds.exception.MDSRuntimeException: MDS-00168: MDS object oracle.mds.core.MDSInstance@17ce029 is being used after it or its MDSInstance or PManager has been released.

This is caused by a oracle bug of 9034287, even they claim they have fixed that.

Solution:

Add a filter to web.xml to solve this:

<filter>     <filter-name>ServletADFContextFilter</filter-name>     <filter-class>oracle.adf.share.http.ServletADFFilter</filter-class>   </filter>   <!-- ... -->   <filter-mapping>     <filter-name>ServletADFContextFilter</filter-name>     <url-pattern>/*</url-pattern>     <dispatcher>REQUEST</dispatcher>     <dispatcher>FORWARD</dispatcher>   </filter-mapping>


Reference:

https://community.oracle.com/thread/1054259

https://community.oracle.com/message/4221494#4221494

http://my-java-planet.blogspot.com/2013/10/webcenter-portal-mds-error-mds-00168.html

How to call a backing bean method from the Javascript on the ADF UI

 By W.ZH Feb 2014

 

Request:

For the ADF jspx page, I want to trigger a backing bean method from UI side through Javascript. Such as a button is clicked, or when the page load happened.  Here is the way how it should go.

I use a  commandToolBar to demo this, clientListener will try to catch the “click” type method. If you want to load the js at the page load, you can put the  <af:clientListener type=”load”  under the <af:document to catch the page onload event.

 

1.      Create the <af:clientListener and <af:serverListener at the button tag.

                    <af:commandToolbarButton …>

 

               <af:clientListener type=”click” method=”jsClicked”/>

 

                              <af:serverListener type=”callServerMethod”

 

                       method=”#{MyBackingBean.triggeredByJSMethod}”/>

 

         </af:commandToolbarButton>     

 

 

2.      Create a javascript at the page UI to trigger the adfCustomeEvent.

 

<af:resource type=”javascript” >

    jsClicked = function(event){

            var param = {city:”New York”, name: “my name”, param1 : “param1s”};

            AdfCustomEvent.queue(event.getSource(), “callServerMethod”, param, true);

            event.cancel();

        }

</af:resource>

 

3.      At your backing bean, you need to create a server listener method to catch the client event and you also can get input data and clientEvent and its component in this method.

 

    public void triggeredByJSMethod(ClientEvent clientEvent) {

        System.out.println(“enter triggeredByJSMethod”);

        System.out.println(clientEvent.getParameters().get(“city”));

        System.out.println(clientEvent.getParameters().get(“name”));

        System.out.println(clientEvent.getParameters().get(“param1”));

     }

 

 

Reference:

http://docs.oracle.com/cd/E21764_01/apirefs.1111/e12419/tagdoc/af_clientListener.html

http://docs.oracle.com/cd/E21764_01/apirefs.1111/e12419/tagdoc/af_serverListener.html

 

 

How to map the user/group from WLS to Content Server internal role

W.ZH Dec 2013

For being able to map external user/groups to UCM roles you will need to use Credential Maps. In this way, a user login from the WLS to access the UCM content, could be able to be mapped to a role inside the UCM, by his group or by his user name defined inside the WLS or external LDAP.

Example:

User “editor1” is in the group of “Editor” (You can use administrator group too) in the embedded LDAP of the WLS. There is a piece of the content in the UCM server, located in the “Public” security group, created by the “weblogic” user. By default, this “Public” security group content can be read by any user. But for the editing permission of this content, you must at least have the “contributor” role in the UCM. User “editor1” will be the external user to UCM, do not have any role info by default in the UCM. when you login by editor1, it by default has the “guest” role to read a content in UCM. If we want the eidtor1 to have more permission to content,  what we need to do is to map the “Editor” group to the “contributor” role in the UCM.

Steps:

1. Suppose you have created user “editor1” is in the “Editor” group in the embedded LDAP of WLS.

2. On UCM – Administration – Credential Maps, add a map (for eg : testMap), put the following mapping content :

Editor, contributor

 

( if you want only one user is mapped, you should use:
&editor1, contributor )

3. Save/ update this map changes

4. In the UCM server, Navigate to <domain_home>/ucm/cs/data/providers/jpsuserprovider and open provider.hda in edit mode.

Add “ProviderCredentialsMap=testMap” before the end.

5. Save the file and restart UCM server. Make sure that WLS admin is running as well since that is needed for UCM JPS provider to be up.

6. After UCM is restarted, login with user editor1.

7. After user editor1 login, you can try checkin check out content features.

8. If you running the webcenter application, contributor role in fact give you the edit ablity to the content related taskflow, such as you can  use ctrl+shift+c  to trigger the ADF page to contribute mode to edit it on web page.

9. By similar method, external LDAP user’s group can be mapped to UCM role too.

Reference:
The following roles are predefined on Content Server:

Roles Description
admin The admin role is assigned to the system administrator. By default, this role has Admin permission to all security groups and all accounts, and has rights to all administration tools.
contributor The contributor role has Read and Write permission to the Public security group, which enables users to search for, view, check in, and check out content.
guest The guest role has Read permission to the Public security group, which enables users to search for and view content.
sysmanager The sysmanager role has privileges to access the Admin Server on the content server.

 

How to make the content ID keep same among different Content Server

W.ZH Dec 2013

When you install your UCM, by default you will have the a choice of “Automatically assign a content ID on check-in” enabled, this will cause you have no chance to define yourself content ID when you check in/ create a new content. UCM will create content ID automatically for you. But when you have multiple CS and you need content migration between servers, so you need to keep content ID same at all the servers.

  1. You need to disable this feature in all UCM.
  2. Login to your UCM with weblogic account
  3. Go to “general configuration” page , under Administration
  4. Uncheck the “Automatically assign a content ID on check-in”
  5. Click “save” button.
  6. You must restart the UCM server.
  7. After started. When you check in a new content, you will be asked to input the content ID. Just give meaningful name you want.

Question:

If you enable the “Automatically assign a content ID on check-in” and content has ID already when is was created. Can we change the ID when content is migrated from server A to another B?

A:

You cannot change your content ID for old content or in migration.
If you do the migration, there is some way you can map ID and add prefix to it when move to another UCM. But still, OLD ID cannot be changed or delete.