Sunday, August 26, 2012

Why JSF date always minus one day?

On last Wednesday, I was assigned a defect on a date issue. "Give me 1 hour to fix this." I answered to my supervisor. At the end of the day, my supervisor come to me, and I reply "The defect still haven't fix. =.=" ".

Here is the problem background. I have a JSF date input control. Whenever the form is submitted, the date value capture in the backing bean will becomes GST time zone, but my expectation is GMT time zone. Without doing a deep research on this will never know there is a design issue in JSF. JSF was using UTF as default time zone whereas I am using GMT time zone. To secure my date, I always have this code standing by:

Anyhow, the problem still has not fix. It took me another one day for the research. And finally I found a work around on this issue by setting the time zone in JVM server.

I was using WAS Liberty Profile server, how could I set the time zone in JVM?

WLP uses jvm.options file to specify additional start up option at the runtime. Its usage can be found in the README in wlp.install.dir. What I did was I put the jvm.options file in the same level as server.xml file, which is here -> {wlp.user.dir}/servers/.

In the jvm.options file, put this line and done.
-Duser.timezone=GMT

Monday, August 20, 2012

IllegalArgumentException cause by Serlvet mapping

Caused by: java.lang.IllegalArgumentException: Servlet mapping specifies an unknown servlet name board

This error is a real shock when I was first look at it. That's why I put it at the top most in this post. I get error during the start up of Tomcat server. I was using Maven build, initially I though it was cause by this code in pom.xml file:

But in fact it is not. Look closer on the error, it mention servlet name board. Then I though was this code cause the error in web.xml.

Something was flashing in my mind. Then only I realize that I was actually missing this code:

Guess what? Problem fixed. :o)

Sunday, August 19, 2012

JSF doesn't work well with Spring

On last week, I had been struggling on how could I integrate JSF and Spring together in a proper way. Since I am using JSF 2.0, I do know that I am required to have the following code to be place in faces-config.xml file:

< application >
  < variable-resolver > 
    org.springframework.web.jsf.DelegatingVariableResolver
  < /variable-resolver >
< /application >

And my authentication bean and main screen bean was declared using session scope (consider the following code), but I am still not able to show my welcome string in the page.

@ManagedBean(name= "authBean" )
@SessionScoped
public class Authentication {

   @ManagedProperty( value="authVo" )
   private User user;

   /** getter and setter of user **/
}

@ManagedBean(name= "authVo" )
@SessionScoped
public class User {
   
  private String logonUser;

  /** getter and setter of logonUser **/
}

@ManagedBean(name= "mainBean" )
@SessionScoped 
public class MainScreen {
 

   private String welcome = "Welcome to main screen";
   
   /** getter and setter of welcome **/
}

After a long searching on the root cause, I found this code in mainScreen.xhtml file cause the problem:

< h5 >
  You are currently logon as: 
  < h:outputText value= "#{authBean.authVo.logonUser}"/ >
</ h5 >
...
...
...
< h:outputText value= "#{mainBean.welcome}"/ >

If I remove the first outputText, the setter of MainScreen class will get invoked, welcome string is shown, otherwise it don't. Meaning that, if I invoke the authBean first, then I can only see the property of authBean, otherwise I will only see mainBean. Now I know that each screen can only have one bean associate with it. Does it really behave in that way when Spring integrate into JSF?

One of my colleague argue that it shouldn't happen in this way, since the Bean was already declared in session scope, it should be seen globally. But that one was JBoss Seam.

Anyhow there is still work around on this. I just need to follow the Spring way, which is the Spring IoC way, to retrieve the logonUser and showing welcome string.

In the mean time, I need to look into the magic of JBoss Seam.

Sunday, August 12, 2012

Maven + Eclipse = Amazing!

On last weekend, I am starting to use Maven for my home development. Before this it was very clumsy, every time when I building the project, it is very annoying that the compiler could not find the appropriate jar dependencies on this particular jar. By using Maven, the compiler no longer complaining on jar dependencies, rather it manage the dependencies for me.

When I first setting up Maven, I use to write XML code. To be frank, I don't really like this work because it took me a lot of effort to figure out the coordinate. To me, this is so much annoying. I don't care, just give me the latest version will do.

Thus I pass this job to Eclipse. BTW, I am just Linux version of Juno Eclipse in Fedora 17, there might be some different with previous version because I found out that the plugins tab in my Eclipse was missing, not really sure does it happen to previous version as well. My previous experience with Maven is editing the POM file without going through the UI, please forgive me on the laziness to find out the truth.

Lets move on. When open up the POM file, there is a dependencies tab. Clink on that there is a Add button in it. Click on that will bring up a dialog just shown as the picture below:

Notice that the top section consist of Group Id field, Artifact Id field, and Version field. Forget about this section unless you really sure what you need on a particular jar. Then the section right below is my favourite, it consist of a search key field and a search result. Just type in anything here, and Eclipse will find it for me. When there is a result, just double click on the entry, Eclipse will handle the coordinate for me.

This is the greatest part of using Maven in Eclipse. Once done editing on the POM file, save it, and Eclipse will trigger the download. This was amazing!!

Anyhow, I still need to update the build path although Eclipse have done the download. Don't get me wrong, I am not require to configure the project build path. I just type this command:

mvn eclipse:eclipse -Dwtpversion=2.0

Go to Eclipse, right click on the project > Maven > Update Project, and then say "I am Done!".