• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble passing request params to redirect in navigation rule

 
Daniel Bittner
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops
#{Payer.company.id} should be #{Person.company.id} to be consistent with the example
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!