I have a simple page that @RequestScopedbean support is tied to . I get to this page from another page on which I passed the "project" parameter. Therefore, when I get to the right page, I have a URL, for example 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"/>
Bean support:
@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");
}
}
}
, . GET . , bean - , . GET , .
f:viewParam ExternalContext ServletContext, .
@RequestScoped @SessionsScoped, @ViewScoped, beacuse CDI beans, .