Tips for handling JSF controls in portlets

2 comments



Below are some of the tips and tricks for handling controls in JSF based portlets.
  •  When we use html in JSF, we can’t specify any action method since this tag doesn’t have action attribute like JSF components.
  • While using hidden fields, they can be read in Pagecode only after the full rendering of the JSP. so it should be declared in the beginning of the jsp.
  • We can avoid submitting a form, by calling a javascript method in the action/onclick, which returns “false”.
  • <h:commandLink> will not submit the form, but <hx:outputLinkEx> will submit the form. In case of <h:commandLink> through javascript we can submit the form forcefully.
  • JavaScript void (): To prevent the load from refreshing, you could use the JavaScript void () function and pass a parameter of 0 (zero). Refer http://www.quackit.com/javascript/tutorial/javascript_void_0.cfm.
  • In JSF, will take us to the next page, to prevent the loading the next page, we can give value="javascript:void(0);".By default, will submit the page.
  • When we try to call a pagecode method from a Datatable row, then the pagecode method is not called, because the pagecodeclass name defined in the faces-config.xml has to be session scope instead of “request”.
  • For each row, JSF component’s dynamic name is appended with the dynamic id obtained through pagecodeclass, so the pagecodeclass name cannot be found for every request(for each row rendering in Datatable), if the pagecode class is session scoped, then pagecode name will be retrained throughout the datatable rendering.
  • So in order to call a pagecode method from a Datatable row, then we need to change the scope of ManagedBean (pagecode) from “session” to “request”.
  • PortletConfig class has a method getTitle() which returns the PortletTitle (which is read from portlet.xml) at runtime. In WPS 5.1 there is no way to change this title dynamically at runtime.
  • Parameters can be passed from JSP to pagecode through tag, in the pagecode actionmethod, we can get the param values through getRequestParam(“variablename”).
  • In the same way, after getting values through getRequestParam(), it is set in the request to pass value through wiring.
  • PortletSession is not available in javascript.
  • Inside theme jsps(eg. SearchBarInclude.jsp), only HTTP session is available.
  • Redirecting to a JSP through URL mapping will submit the form.
  • If we implements Serializable in pagecode means the request type is Action Request.
  • If two portlets are in different JSF version means wiring fails there.
  • In order to retrieve the value of the var productType =document.getElementById(productTxtID).firstChild.nodeValue ; 
  • Use #{facesContext.externalContext.response.namespace}  to get the portlet namespace from the JSF EL. This can be useful to append this unique portlet identifier to the JavaScript functions (for example) defined inside the portlet page.

2 comments:

Anonymous said...

HI Arun, Thank You for sharing wonderful tips.
How do we access our bean parameters from portlet.java files?

Arun Khurana said...

If you want to access the bean parameters from portlet java file then you can simply do it by setting them in request or session scope something like
//Get the Faces Context object
//Get the request / session object from the same faces context object and set the value in either request or session scope.

Try this. It should work

Post a Comment

Recent Posts

Popular Posts

© 2011-2019 Web Portal Club