Tuesday, 25 August 2009

Parameter passing in JSF

I have just started working on JSF but I have to admit that it is really less intuitive. Today I was trying to pass some parameters from my JSF to a bean. I had to do quite a research to get it done. I remember how easy it is to pass and get parameters if you use servlets. But I had to stick with JSF as we JBPM/Gravel and the default expression language supported by JBPM is JSF and all the existing code is written in JSF. it is not a straight forward programming language and is restrictive but I liked the challenge to get things done :).

Here are some code snippets on how to pass parameters. Definitely will come in handy for anybody who experiments in this area.

If you want to set some variables or do some actions when user clicks on a commandlink here is how you do it: I am passing the transition name and i am setting the transitionName variable in my taskBean


<h:commandLink id="transition#{rid}" style="display:none; visibility: hidden;" action="#{taskBean.action}">
<f:setPropertyActionListener target="#{taskBean.transitionName}" value="#{transition.name}" />
</h:commandLink>

Based on the transition, I want to be able to set the url for navigation..so if the transition name is for example, reject I need to go to the next screen where you can enter the reject reason..or else I go myportal.jsf in my case. You do all this when the action event taskBean.action is called when the commandlink is clicked.


<n:nav outcome="success" url= "#{taskBean.url}" storeMessages="true"/>


I found this excellent article with different ways to pass parameters. It almost covers every single way of accessing and passing variables.
http://balusc.blogspot.com/2006/06/communication-in-jsf.html

Here is another basic example:
http://kalanir.blogspot.com/2006/11/parameter-passing-in-jsf_5752.html

No comments:

Post a Comment

Please feel free to post your comments!

Welcome to Planet-Sujie!!

Here you can view technical articles, challenges and solutions and some of my BLOGS.


View My Stats