get GET parameters in JSF's managed bean
Posted
by mykola
on Stack Overflow
See other posts from Stack Overflow
or by mykola
Published on 2010-04-01T15:25:24Z
Indexed on
2010/04/01
15:43 UTC
Read the original article
Hit count: 390
Hello!
Can someone tell me how to catch parameters passed from URI in JSF's managed bean? I have a navigation menu all nodes of which link to some navigation case. And i have two similar items there: Acquiring products and Issuing products. They have the same page but one different parameter: productType. I try to set it just by adding it to URL in "to-view-id" element like this:
<navigation-case>
<from-outcome>acquiring|products</from-outcome>
<to-view-id>/pages/products/list_products.jspx?productType=acquiring</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>issuing|products</from-outcome>
<to-view-id>/pages/products/list_products.jspx?productType=issuing</to-view-id>
</navigation-case>
But i can't get this "productType" from my managed bean. I tried to get it through FacesContext like this:
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("productType")
And like this:
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
request.getParameter("productType");
And i tried to include it as a parameter of managed bean in faces-config.xml and then getting it through ordinary setter:
<managed-bean>
<managed-bean-name>MbProducts</managed-bean-name>
<managed-bean-class>my.package.product.MbProducts</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>productType</property-name>
<value>#{param.productType}</value>
</managed-property>
</managed-bean>
...
public class MbProducts {
...
public void setProductType(String productType) {
this.productType = productType;
}
...
}
But neither of these ways have helped me. All of them returned null. How can i get this productType? Or how can i pass it some other way?
© Stack Overflow or respective owner