Error saying I need to use f:metadata even though

2019-05-12 06:20发布

问题:

After update from JSF 2.1 to 2.2, I start getting the following error message:

The metadata component needs to be nested within a f:metadata tag. Suggestion: enclose the necessary components within <f:metadata>

It's a bit weird as the code looks like this:

....
 <ui:composition template="./resources/templates/template_base.xhtml">

        <ui:define name="contentBody">

            <h:outputStylesheet library="css/table" name="tableContent.css" />
            <h:outputScript library="javascript" name="pagination.js" target="head" />

            <p:growl id="messages" autoUpdate="true" />

            <f:metadata>
                <f:viewParam name="topicId" value="#{topicBean.topic.id}" />
                <f:event type="preRenderView" listener="#{topicBean.init(true)}" />
            </f:metadata>

        </ui:define>

</ui:composition>
....

If the metadata component the error message refers to is either f:viewParam or f:event, then I do have it/them enclosed by f:metadata.

Any ideas about what I'm doing wrong? The error does not show if I set javax.faces.PROJECT_STAGE to Production, but I would like to keep it in Development until I'm finished.

Edit1 - Versions:

  • Netbeans: 7.3.1 (Build 201306052037)
  • Java: 1.7.0_25; Java HotSpot(TM) Client VM 23.25-b01
  • Runtime: Java(TM) SE Runtime Environment 1.7.0_25-b16
  • Java EE: Java EE 7 Web
  • JSF implementation: Mojarra 2.2.0
  • Glassfish: 4.0 build 89

回答1:

Bug reported for JSF 2.2. I was dealing with the same issue awhile back.

https://java.net/jira/browse/JAVASERVERFACES-2803

You might also want to stay away from f:viewActions also.

https://java.net/jira/browse/JAVASERVERFACES-2868



回答2:

I used exactly the same configuration (Glassfish, Mojarra 2.2.0) and found out that I could circumvent the error message if I use only one child in the metadata-tag and put the listener outside of it.

<f:event type="preRenderView" listener="#{bean.listener()}"/>
<f:metadata>
    <f:viewParam name="par1" value="#{bean.val1}" />
</f:metadata>

The problem occurs again if you use two viewParams, see https://java.net/jira/browse/JAVASERVERFACES-3080

An upgrade to the latest Mojarra Version (2.2.6 as of now) solved the problem for me.