Keep original GET request parameters in reverse order

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");
        }
    }

    //projectId getter and setter
    //public void addNewEntity(String name, String desc) {}
}

, . GET . , bean - , . GET , . f:viewParam ExternalContext ServletContext, .

@RequestScoped @SessionsScoped, @ViewScoped, beacuse CDI beans, .

+5
1

<f:param> UICommand . .

<p:commandButton ...>
    <f:param name="project" value="#{param.project}" />
</p:commandButton>

<o:form> JSF OmniFaces, <h:form> includeViewParams, , <f:viewParam> .

<o:form includeViewParams="true">
    ...
</o:form>

, / ajax.

URL- , ajax. URL-, <form action> HTML rightclick - View Source , GET.


, postconstruct, <f:viewParam>. , , :

+9

All Articles