In components.xml we place the below line
Then in the Seam component where we want to retrieve the value for a given property (key), we inject the ResourceBundle as below.
java.util.ResourceBundle resourceBundle;
The retrieval is done as below
I was using JSF and trying to refresh data automatically using ajax4jsf.
Scenario & Problem :
1. Server is started and the dashboard.seam page is viewed.
2. Now stop the server and do not close the browser…
3. Now restart the server, following error is getting displayed on the server console.
SEVERE: JSF1054: (Phase ID: RESTORE_VIEW 1, View ID: ) Exception thrown during phase execution: javax.faces.event.PhaseEvent
Feb 4, 2010 12:07:37 PM org.jboss.seam.web.ExceptionFilter doFilter
WARNING: handling uncaught exception
javax.servlet.ServletException: viewId:/dashboard.seam – View /dashboard.seam could not be restored.
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:270)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:532)
Caused by: javax.faces.application.ViewExpiredException: viewId:/dashboard.seam – View /dashboard.seam could not be restored.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:186)
Feb 4, 2010 12:07:37 PM org.jboss.seam.web.ExceptionFilter doFilter
WARNING: exception root cause
javax.faces.application.ViewExpiredException: viewId:/dashboard.seam – View /dashboard.seam could not be restored.
at com.sun.faces.lifecycle.RestoreViewPhase.execute(RestoreViewPhase.java:186)
Feb 4, 2010 12:07:37 PM org.ajax4jsf.webapp.BaseXMLFilter doXmlFilter
SEVERE: Exception in the filter chain
javax.servlet.ServletException: viewId:/dashboard.seam – View /dashboard.seam could not be restored.
Solution :
1. Once the server is stopped, the page that is trying to get the fresh data should also be closed. Otherwise the page will try to get the data and will throw the above error will occur.
2. Once the server is started, now refresh the previously opened page.
Regards,
Ram
If one application depends on another one — you may want to alter the deployment order of JBoss.
1. One way to accomplish this is to change the order in the ${serverconfig}/conf/xmdesc/org.jboss.deployment.MainDeployer-xmbean.xml file.
<attribute access=’read-write’ setMethod=’setEnhancedSuffixOrder’ getMethod=’getEnhancedSuffixOrder’>
<description>Allows the override of the suffix order declared by subdeployers, using the syntax [order:]suffix
</description>
<name>EnhancedSuffixOrder</name>
<type>[Ljava.lang.String;</type>
<descriptors>
<value value=”250:.rar,300:-ds.xml,400:.jar,500:.war,550:.jse,650:.ear,800:.bsh”/>
</descriptors>
</attribute>
2. One way to accomplish this is to create a deploy.last directory inside the deploy directory and put the application that needs to be deployed after the other in the deploy.last directory.
Another one is to modify ${serverconfig}/conf.xmdesc/org.jboss.deployment.MainDeployer-xmbean.xml
and add your application before the othes in the EnhancedSuffixOrder list.
<attribute access=’read-write’ setMethod=’setEnhancedSuffixOrder’ getMethod=’getEnhancedSuffixOrder’>
<description>Allows the override of the suffix order declared by subdeployers, using the syntax [order:]suffix
</description>
<name>EnhancedSuffixOrder</name>
<type>[Ljava.lang.String;</type>
<descriptors>
<value value=”250:.rar,300:-ds.xml,400:.jar,500:.war,550:.jse,600:mynewapp.ear,650:.ear,800:.bsh”/>
</descriptors>
</attribute>
In this tutorial you will learn how to configure a startup class for a web application in Tomcat 5.5.x or Tomcat 6.
Step 1:Let us assume Tomcat is installed in C:\tomcat. Let us assume you want to define a startup class for a web application named reminder. Navigate to C:\tomcat\webapps\reminder\WEB-INF and open the file web.xml. Configure the startup class ApplicationStartUpListener under the package com.corelabs as in the screen shot below.
<web-app>
<listener>
<listener-class>com.corelabs.ApplicationStartUpListener</listener-class>
</listener>
Step 2: The startup class ApplicationStartUpListener should follow certain rules like implementing javax.servlet.ServletContextListener. The Java source of the ApplicationStartUpListener is provided in the below screen shot.
package com.corelabs;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.log4j.Logger;
/**
* @author ramb
*/
public class ApplicationStartUpListener implements ServletContextListener {
private static final Logger log = Logger.getLogger(ApplicationStartUpListener.class);
private ServletContext context = null;
public ApplicationStartUpListener() {
}
public void contextInitialized(ServletContextEvent event) {
//Do Something you wish when application is loaded.
}
public void contextDestroyed(ServletContextEvent event) {
this.context = null;
}
}
// Read properties file.
Properties prop = new Properties();
try {
prop.load(new FileInputStream("filename.properties"));
} catch (IOException e) {
}
// Write properties file.
try {
prop.store(new FileOutputStream("filename.properties"), null);
} catch (IOException e) {
}
The trick to sort a java.util.Set
is to use the implementation of a java.util.SortedSet
such as the java.util.TreeSet
class. The example below shows you the result of using the java.util.TreeSet
class, in which the items in it will be sorted based on the element’s natural order.
package com.corelabs.example.util; import java.util.Set; import java.util.TreeSet; public class TreeSetDemo { public static void main(String[] args) { // The TreeSet class is an implementation of a SortedSet, this means // that when your are using the TreeSet to store you data collections // you'll get the items ordered base on its elements natural order. Set<String> set = new TreeSet<String>(); // In the example below we add some letters to the TreeSet, this mean // that the alphabets will be ordered based on the alphabet order // whichs is from A to Z. // set.add("Z"); set.add("A"); set.add("F"); set.add("B"); set.add("H"); set.add("X"); set.add("N"); for (String item : set) { System.out.print(item + " "); } } } |
This demo prints:
A B F H N X Z
Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation.
SAX |
DOM |
Parses node by node |
Stores the entire XML document into memory before processing |
Doesn’t store the XML in memory |
Occupies more memory |
We can’t insert or delete a node |
We can insert or delete nodes |
Top to bottom traversing |
Traverse in any direction. |
SAX is an event based parser |
DOM is a tree model parser |
SAX is a Simple API for XML |
Document Object Model (DOM) API |
import javax.xml.parsers.*; |
import javax.xml.parsers.*; |
doesn’t preserve comments |
preserves comments |
SAX generally runs a little faster than DOM |
SAX generally runs a little faster than DOM |
If we need to find a node and doesn’t need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory.
More Info: SAX Parser is the one which is developed to run the java programs especially. It uses a memory resident model. DOM is developed by w3c consortium so that it is an open standard. In DOM the xml file is arranged as a tree and backward and forward search is possible for searching the tags and evaluating the data which it holds. It depends upon the application and ease of data accessiblity. If we want to extract the data from a xml file once we have to move to SAX which is one time top to bottom read approach and if we want ot randomly pick the data in an xml file then the tree reperesentation of DOM model is to be put into use.
In components.xml we place the below line
Then in the Seam component where we want to retrieve the value for a given property (key), we inject the ResourceBundle as below.
The retrieval is done as below