S U N D A R R A J A N

Google Search Engine

Friday, December 30, 2011

JSF Performance Improvements


1.       View State – this will keep on increasing depends upon our page size. The performance might get degraded if the size of this view state increases. Use the following configuration to save the view state in the server side itself.
 < context-param >
      < param-name > javax.faces.STATE_SAVING_METHOD < / param-name >
      < param-value >server < / param-value >
< / context-param >
2.       Ajax – As we all know the async request is being made using java scripts. If we have more ajax components in the page, then the following config can be used to compress the script. This is applicable only if we use Rich faces
 < context-param > 
        < param-name > org.ajax4jsf.COMPRESS_SCRIPT < / param-name >      
         < param-value > true < / param-value >
< / context-param >
This config will enforce the container to compress all the richfaces resources including images, stylesheets, javascript to be compressed before sending to client. It will make significant reduced load time
3.       Ajax Parser – By default all the JSF responses are ‘tidied’, we can make only the JSF AJAX response to ‘tidied’.  This is applicable only if we use Rich faces 
< filter >
      < filter-name > richfaces < / filter-name >
      < display-name > RichFaces Filter < / display-name >
      < filter-class > org.ajax4jsf.Filter < / filter-class >
      < init-param > 
          < param-name > forceparser < / param-name >
         < param-value > false < / param-value >
    < / init-param >
< / filter >
This can be minimized by setting the forceparser setting to false. In that case only AJAX responses will be ‘tidied’. In the other case all JSF responses are ‘tidied’. That is because the filter is mapped on the Faces servlet: This can be used for partial page rendering.
4.       Load strategy  - Following configuration will make sure that all style related files should be loaded at client side at once on first request when richfaces application is accessed. This is applicable only if we use Rich faces 
< context-param >
     < param-name > org.richfaces.LoadStyleStrategy < / param-name >
    < param-value > all < / param-value >
< / context-param >
5.       Parsers in RichFaces - Richfaces has a few parsers onboard. The default one is based on Tidy, but it is quite slow. The Neko parser is faster and can be used by setting the following context-param’s.  This is applicable only if we use Rich faces 
< context-param >       
    < param-name > org.ajax4jsf.xmlparser.ORDER < / param-name >       
    < param-value > NEKO < / param-value >   
 < / context-param >    
< context-param >       
     < param-name > org.ajax4jsf.xmlparser.NEKO < / param-name >       
    < param-value > .*\..* < / param-value >   
< / context-param > 
6.       AJAX tricks :
1.       ajaxSingle = true - This attribute should be true for any ajax component whose only value is required at server time so that whole ajax request map should not be posted to server. 
2.       limitToList = ture – This attribute should be true for any ajax component who will reRender only the components specified in its reRender attribute list. All other components not specified in the reRender list will no longer reRender upon request completion
3.       immediate = true –  This property will submit the value and skips validation phase and set the value immediately into backing bean.  
Best Practices in JSF:

JSF Standards


JSF Standards:·
  • 1. Go for  “XHTML”  instead of “jsp”
    • XHTML is XML compatible, if use JSP extra overhead will be there for converting into DOM. 
  • 2. Go for “facelets”
    •  There is a viewhandler for JSF also as like other frameworks. The drawback in the JSF view handler is, there is no configurable support for multiple view in the JSF application.
    • Facelets: The mismatch between JSF and JSP technology is a serious problem in JSF development. The issue is how to integrate JSP’s dynamic content into JSF’s component-based model. JSP is singularly focused on generating dynamic output, whereas JSF requires JSP to coordinate building a component model. Facelets will overcome this. Facelets has several compelling features:-         
    • Facelets saves JSF from the burden of JSP - Great for templating and composition components plus bonuses like el functionsCreating component libraries-          No tld files and no tag classes to define a UIComponent
    • <%@ taglib uri=”http://java.sun.com/jsf/html” prefix=”h”%/>          
    • Will be written as  
    • http://www.w3.org/1999/xhtmlxmlns:h=”http://java.sun.com/jsf/html” >         
  • 3. Try to reuse the HTML components except for the component will needs to be binded in the backing beans. Data binding will not happen for the HTML components.
  • 4. Id is not mandatory conceptually but it is mandatory for developing websites and it should be meaningful and unique.
  • 5. Don’t use special charactersIf you want display special characters use Unicode or < h:outputText  value=” ”  escape=”false” /> ·        
  • 6. Don’t use JSTL tags (like c:if , c:for …), use rendered tags instead (UI:repeat instead of c:for). Place java script in separate file. Consolidate the java script function and have it as a separate JS file instead of adding functions in the head part of the page. ·        
  • 7. Don’t use style attribute to define styles, use styleClass and define those style classes in separate file and use them when you required. Do not use in-line styles. ·        
  • 8. Avoid changing the value of the fields dynamically using java script functions. ·        
  • 9. Do not use JSTL tags until it’s mandatory·        
  • 10. All the non JSF components should be inside tag.·        
  • 11. Use subview tag if we have are including another page in to the parent page.
Best practices:·
        
Use Neko parser for converting into XML DOM we can configure this in the in the web.xml context param. This is the parser used for parsing the XML in the AJAX call. This is used with Richfaces framework. Since we are going to made the ajax call using jquery, we will not be using this. Neko parser extends SAX parser and it is faster compared to others·        
State saving methodology
  • Client: Use this when you have more forms , navigations in the same page or AJAX code etc..
  • Server: otherwise go for server side. Use server. ·
Property file in JSF application:

Don’t use instead go for configuration in faces-context.xml

tag is used to load the recourse bundle and store it as a map in the request scope.  
Loading property file with :

JSF 1.1and 1.2 supports f:loadBundle feature Loading property file using faces-config.xml     

1.  If the properties file is present in WEB-INF/classes/com/test/resource/messages.properties:                          
                            
                                   
     com.test.resource.messages                        
        msgs
                           
       
2. Once loaded, message strings can be accessed using the value expression #{varName.keyName}. The advantage is it will load property file only once.  For managed beans use appropriate scope  

Monday, February 21, 2011

My House

House warming function went on really well :) :)

Thursday, February 10, 2011

My House

Wednesday, January 26, 2011

Thirupathi Trip

My House

Is this bolg useful?

Rate

S U N D A R R A J A N

Followers