JSF @PostConstruct
Scenario: I needed to get some data for datatable when the bean get initiated.
So, I have tried these following code.
public TrainingClassForm() { //constructor
this.trainingListModel.getAllTrainingClasses();
}
Error:
me: javax.faces.FacesException: Problem in renderResponse: javax.faces.FacesException: Cant instantiate class: gov.faa.amc.nas.hrtrainingview.bean.backing.TrainingClassForm.. null
Issue: Banging my head after few hours, then I have discussed with JSF Expert, Jason Lee who helped me to sort this out. I was calling trainingListModel before it get initiated/born. So I was getting a null pointer in TrainingListModel class.
Lesson to learn: Use @PostConstruct instead.
1. If the bean has request scope, @PostConstruct will get executed every time. It will be called after the managed bean is instantiated, but before the bean is placed in scope. Such a method take no arguments, return void, and may not declare a checked exception to be thrown. Method may be public, protected, private, or package private. If the method throws an unchecked exception, the JSF implementation must not put the managed bean into service and no further menthods on that managed bean instance will be called.
// Constructor
public TrainingClassForm() {
}
@PostConstruct
public void init() {
if (this.trainingListModel.getListDataModel() != null) {
this.trainingListModel.getAllTrainingClasses();
}
}
2. @PreDestroy:Any scoped managed bean menthod annotated with @PreDestroy will be called before the bean is removed from the scope or before the scope in which the bean resides is destroyed, whichever comes first. The constraints placed on the method are the same as with @PostConstruct.
Ref Book: The Complete Reference – JavaServerFaces by Chris Schalk & Ed Burns
Icefaces, Null Pointer caused by DOMResponseWriter
I was using Icefaces 1.7.2 with Jsf 1.2_04
javax.faces.FacesException: Problem in renderResponse: /WEB-INF/facelets/template.xhtml Not Found in ExternalContext as a Resource Error code 500
When I took off the template.xhtml, I got this.
javax.faces.FacesException: Problem in renderResponse: null
INFO: 08:19:37,173 ERROR D2DFaceletViewHandler:292 - Problem in renderResponse: null <pre>java.lang.NullPointerException at com.icesoft.faces.context.DOMResponseWriter.enhanceAndFixDocument(DOMResponseWriter.java:270) at com.icesoft.faces.context.DOMResponseWriter.endDocument(DOMResponseWriter.java:159)
Upgraded to JSF 1.2_07 and Facelets 1.1.14. Did not help.
Solution: I was missing filepath. Instead of /WEB-INF/facelets/template.xhtml, I had to add ../WEB-INF/facelets/template.xhtml and it worked.
Thanks to Arran from Icefaces.com for his support.
org.springframework.web.context.ContextLoaderListener
Error: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
The Spring projects has many modules.
- Spring Web MVC (spring-webmvc.jar)
- Spring Aop (spring-aop.jar)
- Spring Beans (spring-beans.jar)
- Spring Context (spring-context.jar)
- Spring Core (spring-core.jar)
- Spring Dao (spring-dao.jar)
- Spring Hibernate (spring-hibernate3.jar)
- Spring Ibatis (spring-ibatis.jar)
- Spring Jca (spring-jca.jar)
- Spring Jdbc (spring-jdbc.jar)
- Spring Jdo (spring-jdo.jar)
- Spring Jms (spring-jms.jar)
- Spring Jms (spring-jpa.jar)
- Spring Jmx (spring-jmx.jar)
- Spring Portlet (spring-portlet.jar)
- Spring Remoting (spring-remoting.jar)
- Spring Struts (spring-struts.jar)
- Spring Support (spring-support.jar)
- Spring Toplink (spring-toplink.jar)
- Spring Web (spring-web.jar)
- Spring Aspects (spring-aspects.jar)
Solution: My project was missing Spring-web.jar Two ways to fix this.
1. Add Spring-web.jar to the WEB-INF/lib dir
2. Add a dependency tag to the pom.xml file (preferred). At this time I am using Spring 2.5.4
<dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>2.5.4</version> </dependency>
MyEclipse “Unknown tag warning for jsf tag libraries”
1. Unknown tag warning for jsf tag libraries.

- Using the -clean command line argument when starting up Eclipse can help a lot of strange problems disappear … more
eclipse.exe -clean or, right click the MyEclipse shortcut, Property --&gt; Shortcut Start in: "C:\Users\Sohail\AppData\Local\Genuitec\MyEclipse 7.0\myeclipse.exe" -clean
- If above strategy does not work, create a brand new Web Project using MyEclipse IDE, add JSF capability then add Facelets capabality.
- Create a .xhtml page and add ui composition tag. This should solve it.
2. My Eclipse is too damn slow.
- Create project in local drive and do compile and run instead of running of network drive.
- You can go to Windows > Preferences > General > Capabilities > Advanced and disable the capabilities that you are not using. That would enhance the performance of the IDE.
3. How do I know what version of java MyEclipse IDE is using.
- MyEclipse –> Install Summary …
- MyEclipse –> Examples On-Demand … (pretty cool)
4. How to see warning and error details?
- Windows –>Show View –> Problems
5. No grammar constraints (DTD or XMl schema) detected for the document.
- Window > Preferences > MyEclipse > Files and Editors > XML and select “Indicate when no grammar is specified” = Ignore.
6. java.lang.UnsupportedClassVersionError: Bad version number in .class file
- Downloaded Eclipse 7.1 and started getting above error even though I have successfully completed unit testing for all methods. MyEclipse IDE 7.1 by default runs on java 1.5. I needed to run my project on java 1.6.
*** Date: Friday, April 3, 2009 7:56:14 PM CDT ** System properties: OS=WindowsXP OS version=5.1.0 Java version=1.5.0_11
I have changed the default JDK Compliance level to 1.6 by going as follows:
Windows –> Preferences –> Java –> Compiler
I have also added Maven JDK to 1.6, Windows –> Preferences –> MyEclipseEnterprise Workbench –> Maven4MyEclipse –> Maven.
But I have forgot this following step:
Right click on the project –> Properties –> Java Build Path then click Order and Export tab and click JRE System Library [jre-6] checkbox.
Suggestion: Close and start the IDE after make any configuration changes also help to clean cache data. In order to run the project you need to add a server and JDK (not jre) home. Windows –> Preferences –> Servers –> Glassfish 2.x –> JDK
7.
-
Archives
- November 2009 (1)
- July 2009 (1)
- June 2009 (5)
- May 2009 (2)
- April 2009 (4)
- March 2009 (2)
- January 2009 (3)
- December 2008 (1)
- November 2008 (2)
- October 2008 (1)
- September 2008 (3)
- August 2008 (2)
-
Categories
-
RSS
Entries RSS
Comments RSS