简体   繁体   中英

Multiple <f:viewAction> in <f:metadata>

I am developing a CMS using JSF 2.3. I need to pass a GET parameter to every page indicating the site that the user is managing. To do this I am using <f:viewParam> in all pages, but I have the following doubts:

  1. Is it OK to use multiple <f:viewAction> for multiple managed beans like the following example?
<f:metadata>
    <f:viewParam name="form" value="#{editFormWebBean.formIdParam}"/>
    <f:viewParam name="site" value="#{headerWebBean.siteIdParam}"/>
    <f:viewAction action="#{editFormWebBean.init}" />
    <f:viewAction action="#{headerWebBean.init}" />
</f:metadata>

This works, but I am not sure if it is OK.

  1. Is there a way to avoid replicating in every page the <f:viewParam> for the site parameter? I tried with includeViewParams, but doesn't worked if I don't include the <f:viewParam> in the source and destination page (from page1.xhtml to page2.xhtml)

3) Can I define multiple <f:metadata> tags? For example if I am using templates and multiple ManagedBeans pare page (one for the header, one for the menu and so on).

Thank you and sorry about my english.

  1. it's okay to have as many <f:viewParam> and <f:viewAction> as long as they work well together, but please make sure these are meant to initialize the view "JSF page" not the backing beans, use @PostConstruct on the baking beans to initialize them, also but in your mind that <f:viewAction> is only executed on GET request by default any subsequent POST (postback) requests don't invoke the action unless it has onPostBack="true" attribute. more on these tags can be found in this great answer [What can <f:metadata> , <f:viewParam> and <f:viewAction> be used for?][1]

  2. put it in a template using the templating feature of JSF like this:

template.xhtml

<f:metadata>
   <f:viewParam name="site" value="#{headerWebBean.siteIdParam}"/>
   <ui:insert name="metadata"/>
</f:metadata>

page.xhtml

<ui:composition template="template.xhtml">
    <ui:define name="metadata">
        <!-- whatever metadata you want to add-->
    </ui:define>
 </ui:comosition>
  1. no it's one metadata tag per page, use it like the example above. [1]: https://stackoverflow.com/a/6377957/4649524

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM