aspose file tools
The moose likes JSF and the fly likes Trouble passing request params to redirect in navigation rule Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSF
Reply Bookmark "Trouble passing request params to redirect in navigation rule" Watch "Trouble passing request params to redirect in navigation rule" New topic
Author

Trouble passing request params to redirect in navigation rule

Daniel Bittner
Greenhorn

Joined: Jan 11, 2007
Posts: 4
The following is an example to illustrate the problem I am having.

Suppose I have a page that lists people in a company and another page that will add a person to a company: "listPeople.jsp" and "addPerson.jsp".

For a specific company the urls would be as follows "contextroot/listPeople.jsp?company=x", "contextroot/addPerson.jsp?company=x".

A command button on addPerson.jsp enacts a method that tries to add the new user and returns the strings "Success" or "Fail". On success I would like to return the user to the list of people for that company.

Here is the navigation rule:

<navigation-rule>
<from-view-id>/addPerson.jsp</from-view-id>

<navigation-case>
<from-action>#{Person.addNew}</from-action>
<from-outcome>Success</from-outcome>
<to-view-id>/listPeople.jsp</to-view-id>
<redirect/>
</navigation-case>

</navigation-rule>

The form on addPerson.jsp has a hidden input for the companyId which is how the addNew method on the managed bean Person knows which company to associate the person with.

The backing bean on listPeople.jsp uses a request parameter named "company" to retrieve the list of people that will be displayed.

All of this works fine, except when the redirect tag is included in the navigation case. This is used to protect the user from accidentally adding the same user twice.

How can I pass the company from the form on addPerson.jsp to the new request that is generated from the redirect?
Daniel Bittner
Greenhorn

Joined: Jan 11, 2007
Posts: 4
I ended up creating a custom view handler to allow value binding expressions for the to-view-id as follows:

public class ValueBindingViewHandler extends ViewHandlerWrapper {

protected ViewHandler wrappedViewHandler;

public ValueBindingViewHandler(ViewHandler viewHandler) {
super();
this.wrappedViewHandler = viewHandler;
}

protected ViewHandler getWrapped() {
return this.wrappedViewHandler;
}

@Override
public String getActionURL(FacesContext context, String viewId) {
String result = viewId;
if(Util.isVBExpression(viewId)) {
ValueBinding vb =
context.getApplication().createValueBinding(viewId);
result = vb.getValue(context).toString();
}
return super.getActionURL(context, result);
}

}

I added the following to the faces-config file to use it:

<application>
<view-handler>com.cdrassociates.robopuppy.web.viewhandlers.ValueBindingViewHandler</view-handler>
</application>

That allowed me to use a dynamic to-view-id like this:

<to-view-id>listPeople.jsp?company=#{Payer.company.id}</to-view-id>

It seems odd that JSF doesn't support this without the custom view handler. Does anyone have a better way of accomplishing this?
Daniel Bittner
Greenhorn

Joined: Jan 11, 2007
Posts: 4
oops
#{Payer.company.id} should be #{Person.company.id} to be consistent with the example
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Trouble passing request params to redirect in navigation rule
 
Similar Threads
Clearing Form on "success" outcome
On a button click need to load a select one menu
JSF <h:commandButton action> not working
Redirecting to another page in Bean
Newbie question on RELOAD or REDIRECT?