How to pass parameter value from JSF to backing bean
In my backing bean I have a variable, and I would like to give a value of that from the JSP page (the value of the parameter will be hardcoded in JSP) . I am thinking of using <f:param> tag using binding, but not able
to make it work.
public class mybean{
String myparam = "";
public void getMyparam(){
}
public String setMyparam(String myparam){
this.myparam = param
}
}
thanks
-K
[460 byte] By [
ketha] at [2007-10-3 0:36:41]

How about:
JSP page:
<h:commandLink action="#{myBean.someAction}">
<h:outputText value="Link Text"/>
<f:param name="someParamName" value="someValue"/>
</h:commandLink>
Backing bean code:
public String someAction() {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
HttpServletRequest request = (HttpServletRequest) context.getRequest();
String parameterValue = request.getParameter("someParamName");
// Code here
return null;
}
If it is a request scoped managed bean, you can confiure it so:
...
<managed-bean>
<managed-bean-name>bean>/managed-bean-name>
...
<managed-property>
<property-name>myParam</property-name>
<value>#{requestScope.myParam}</value>
</managed-property>
...
Before calling the JSP set the request attribute myParam.