Can I “pass” an object with a JSF param tag?

后端 未结 1 1000
孤街浪徒
孤街浪徒 2020-12-14 19:58

What I\'m looking for is to have an f:param tag with an Object of my own choosing in the value attribute. Then, in the backing bean method for the action, I would like to be

相关标签:
1条回答
  • 2020-12-14 20:51

    You can't do that with <f:param>. It needs to be appended to the URL of the request, so it really needs to be a String. Just use <f:setPropertyActionListener> instead.

    E.g.

    <h:commandLink value="Submit" action="#{bean.submit}">
        <f:setPropertyActionListener target="#{bean.otherBean}" value="#{otherBean}" />
    </h:commandLink>
    

    This way the #{otherBean} is just available as this.otherBean inside submit() method. This way you also don't need to mess with the request parameter map (for which in case of <f:param> I would rather have used managed property injection with #{param.name} instead).

    Alternatives are using <h:inputHidden> in combination with a Converter or using Tomahawk's <t:saveState>. Also see this blog article for more background info and examples.

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