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;
}

Advertisements

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