My problem is that the value of the parameter is null in the bean
In the xhtml I have this code:
<h:commandLink action="#{navigation.editNews}" value="#{new.title}">
<f:param name="newsId" value="#{new.id}" />
</h:commandLink>
In Navigation I redirect to news.xhtml
public String editNews(){
return "editNews";
}
This is the code in faces-config.xml
<navigation-case>
<from-action>#{navigation.editNews}</from-action>
<from-outcome>editNews</from-outcome>
<to-view-id>/news.xhtml</to-view-id>
<redirect />
</navigation-case>
I have a bean where I call method when I push a button in news.xhtml and I try to get param but it is null
FacesContext fc = FacesContext.getCurrentInstance();
Map<String,String> params = fc.getExternalContext().getRequestParameterMap();
String = params.get("newsId");
The <f:param> adds a request parameter. So this parameter has a lifetime of exactly one HTTP request. You've a <redirect/> in your navigation case which basically instructs the webbrowser to send a new request on the given location. This new request does not contain the parameter anymore.
You've basically 2 options:
Get rid of <redirect /> in the navigation case.
Make it a normal GET request instead. If you're on JSF2, use <h:link> instead.
<h:link action="news" value="#{news.title}">
<f:param name="newsId" value="#{news.id}" />
</h:link>
Or if you're still on JSF 1.x (the usage of navigation cases less or more hints this as they are superfluous in JSF 2 thanks to the new implicit navigation feature; or you must be reading outdated tutorials/books/answers targeted on JSF 1.x; also the absence of JSF 2.0 tag on your question is suspicious), then use a normal <a> link instead.
<a href="news.xhtml?newsId=#{news.id}">#{news.title}</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With