Daily Archives: March 24, 2010

closer look at the FacesServlet instance


This is always ignored as a default servlet that gets generated in the web.xml, but do we know the actual usage of this servlet?

All the JSF applications should include a mapping to this servlet in the deployment Descriptor. The usage of this servlet is that it

  • accepts all the incoming request
  • passes them to the lifecycle for processing
  • intializes the resources

it is usually defined in the web.xml file as

<servlet>
 <display-name>FacesServlet</display-name>
 <servlet-name>FacesServlet</servlet-name>
 <servlet-class>javax.faces.webapp.FacesServlet
 </servlet-class>
 <load-on-startup>1</load-on-startup>
 </servlet>

with corresponding mapping as well

<servlet-mapping>
 <servlet-name>FacesServlet</servlet-name>
 <url-pattern>/faces/*</url-pattern>
 </servlet-mapping>

the servlet includes servlet lifecycle methods to initialize and process the request

init(ServletConfig)FacesContextFactory,LifeCycleFactory is identified and the lifeCycle reference is obtained with the default lifecycle id
service()the pathInfo is manipulated from WEB-INF and META-INF folder from the request, FacesContext is obtained, lifecycle is executed and rendered, later the context is released
destroy()all the instances are destroyed.. technically speaking nullified

Advertisements

Ways to setup Querymode programatically


How to set the query mode for the af:query component programatically?

The query component provides two ways of searching. BASIC and ADVANCED mode.
Basic mode renders the query panel with the viewcriteria defined and allows the user to search based on the query criteria
Advanced mode helps the user to provide advanced options for the user to search based on the operators. It also provides the user to add more fields to the query criteria.

public Boolean setAdvancedMode(){
String expression = "#{bindings.<searchregionbindingfrompagedef>.queryDescriptor}";
FacesContext facesContext = getFacesContext();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression,
Object.class);
QueryDescriptor descriptor =
(QueryDescriptor)valueExp.getValue(elContext)
;
descriptor.changeMode(QueryDescriptor.QueryMode.ADVANCED);
return true;
}

lets drill down deeply into the code to check what are we doing

String expression = "#{bindings.<searchregionbindingfrompagedef>.queryDescriptor}";
  • getting the expression for the query binding from the pagedef and storing it in a string
FacesContext facesContext = getFacesContext();
Application app = facesContext.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ELContext elContext = facesContext.getELContext();
  • getting the Facescontext reference from FacesContext.getCurrentInstance();
  • getting the application from the facesContext
  • getting the expresionFactory for the application
  • getting the elContext from the FacesContext
ValueExpression valueExp =
elFactory.createValueExpression(elContext, expression,
Object.class);

create a value expression by passing the elcontext and the expression where Object type is expected

QueryDescriptor descriptor =
(QueryDescriptor)valueExp.getValue(elContext);
descriptor.changeMode(QueryDescriptor.QueryMode.ADVANCED);

The value from the valueExpression object is casted to the QueryDescriptor object
As we got the reference to the QueryDescriptor, we call the changeMode method to change the mode to QueryDescriptor.ADVANCED

Enable FastSwap in Weblogic deployment


Enable fastswap to load java classes at runtime without relaoding the classloader
have the following entry in weblogic-application.xml

<fast-swap>
<enabled>true</enabled>
</fast-swap>

The following types of changes are supported with FastSwap:

  • Addition of static methods
  • Removal of static methods
  • Addition of instance methods
  • Removal of instance methods
  • Changes to static method bodies
  • Changes to instance method bodies
  • Addition of static fields
  • Removal of static fields
  • Addition of instance fields
  • Removal of instance fields