I have simply page to which is associated @RequestScoped
backing bean. I get to this page from other page on which one I passed parameter "project". So when I get on right page I have url like contextRoot/faces/jsf.xhtml?project=123
.
View:
<f:metadata>
<f:viewParam name="project" value="#{entityBean.projectId}" />
</f:metadata>
...
<p:commandButton value="#{msg['button.add']}"
actionListener="#{entityBean.addNewEntity((entityName),(entityDescritpion))}"
ajax="true" update=":projectDetailForm"/>
Backing bean:
@Named("entityBean")
@RequestScoped
public class EntityBean implements Serializable{
private String projectId;
@PostConstruct
public void init() {
params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
for (Map.Entry<String, String> entry : params.entrySet()) {
System.out.println(entry.getKey() + " / " + entry.getValue());
}
if (params.get("project") != null) {
projectId = params.get("project");
} else {
HttpServletRequest request =
(HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
String projectId = request.getParameter("project");
}
}
//projectId getter and setter
//public void addNewEntity(String name, String desc) {}
}
Everything works fine when the page is opened for the first time. The GET parameter is successfully processed. However, as the bean is request scoped, it is destroyed by end of request and recreated on the subsequent postback(s). During those postbacks, the GET parameter is not available anymore even though it is visible in the browser address bar. I tried three methods of getting parameter
by f:viewParam
and ExternalContext
and even from ServletContext
but I can't get those parameters.
I don't want to change @RequestScoped
to @SessionsScoped
and I can't use @ViewScoped
, beacuse I'm using CDI beans and I don't want to mix them.