Passing request scoped variable passed as EL action method parameter does not work

冷暖自知 提交于 2019-12-01 11:06:10

The action attribute is evaluated during apply request values phase of the HTTP request triggered by the form submit, which is thus a different HTTP request than the one which produced the HTML output with therin the form (and having the email parameter present in the request).

The <f:param> tag is evaluated during render response phase of the HTTP request which needs to produce the HTML output with therein the form. This thus ends up "hardcoded" in the generated HTML output (on contrary to the EL method arguments in the action attribute!). When the user submits the form, this just gets passed back to the server as a plain vanilla String request parameter (which you would need to convert back if it was originally a complex type).

This has got nothing to do with whether the value is an implicit EL object or not.

That said, there are 2 other ways:

  1. Pass it as hidden input (no, not with <h:inputHidden>).

    <h:form>
        <input type="hidden" name="email" value="#{param.email}" />
        ...
    </h:form>
    
  2. Set it as property of a view scoped bean, it'll stay in bean as long as the view lives.

    <f:metadata>
        <f:viewParam name="email" value="#{viewScopedBean.email}" />
    </f:metadata>
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!