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:
Advertisements

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