Restoring request parameters in @ViewScoped bean after session expires

后端 未结 2 849
不知归路
不知归路 2021-01-06 08:46

I have a page that has the setup as below with url like my.page.com/table.xhtml?id=123:

+--------------         


        
相关标签:
2条回答
  • 2021-01-06 08:48

    As to bypassing the expired view by just completely recreating it, add <o:enableRestorableView> to the metadata:

    <f:metadata>
        ...
        <o:enableRestorableView />
    </f:metadata>
    

    As to retaining the request parameter, either add a plain HTML hidden input field to the form:

    <h:form>
        ...
        <input type="hidden" name="id" value="#{dataTable.id}" />
    </h:form>
    

    or use <o:form> with includeViewParams="true",includeRequestParams="true" or useRequestURI="true", depending on whether you'd like to submit to the JSF view ID with all view params, or to the JSF view ID with the entire request query string, or to the entire request URI (including query string):

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

    As to reinitializing the bean's state on postback before it going through all phases of the JSF lifecycle, you'd need to replace the <o:viewParam> by manually grabbing it and the <f:viewAction> by @PostConstruct:

    @PostConstruct
    public void initialize() {
        id = Faces.getRequestParameter("id");
        // ...
    }
    
    0 讨论(0)
  • 2021-01-06 08:58

    I tried all these above and not working in mojarra 2.2.5

    Just change mojara to mojarra 2.2.8 and it will be solved without adding any code

    0 讨论(0)
提交回复
热议问题