Hobione's Weblog

Living & Breathing in Web 2.0 Era

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

Advertisements

April 22, 2009 Posted by | Java Server Faces | 3 Comments

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.

April 7, 2009 Posted by | Facelets, ICEfaces | 1 Comment

org.springframework.web.context.ContextLoaderListener

Error: java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

The Spring projects has many modules.

  1. Spring Web MVC (spring-webmvc.jar)
  2. Spring Aop (spring-aop.jar)
  3. Spring Beans (spring-beans.jar)
  4. Spring Context (spring-context.jar)
  5. Spring Core (spring-core.jar)
  6. Spring Dao (spring-dao.jar)
  7. Spring Hibernate (spring-hibernate3.jar)
  8. Spring Ibatis (spring-ibatis.jar)
  9. Spring Jca (spring-jca.jar)
  10. Spring Jdbc (spring-jdbc.jar)
  11. Spring Jdo (spring-jdo.jar)
  12. Spring Jms (spring-jms.jar)
  13. Spring Jms (spring-jpa.jar)
  14. Spring Jmx (spring-jmx.jar)
  15. Spring Portlet (spring-portlet.jar)
  16. Spring Remoting (spring-remoting.jar)
  17. Spring Struts (spring-struts.jar)
  18. Spring Support (spring-support.jar)
  19. Spring Toplink (spring-toplink.jar)
  20. Spring Web (spring-web.jar)
  21. 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>

April 5, 2009 Posted by | Spring Framework | 5 Comments

MyEclipse “Unknown tag warning for jsf tag libraries”

1. Unknown tag warning for jsf tag libraries.

redxforfacelets
– 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 --&amp;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.
javabuildpathSuggestion: 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.

April 3, 2009 Posted by | MyEclipse IDE | Leave a comment