简体   繁体   中英

Using more than one <f:viewParam .. /> in <f:metadata .. causes error

I want to parse two parameters from the URL but when I include two f:viewParam in header of page i get an error: The metadata component needs to be nested within af:metadata tag. Suggestion: enclose the necessary components within f:metadata

An example of a URL: http://domain.com?email=blah@dom.com&key=4793e258-518f-432d-9af2-8d639a13757d

I'm using JSF 2.2.6 and I tried swapping the name space (below) from xmlns.jcp.org to java.sun.com but that made no difference.

My simplified page is:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">
<f:view>
    <h:head>
        <f:metadata>
            <f:viewParam name="email" value="#{credentialsBacking.returnedEmail}"/>
            <f:viewParam name="key" value="#{credentialsBacking.returnedActivationKey}"/>
        </f:metadata>
    </h:head>
    <h:body>
    </h:body>
</f:view>
</html>

Thanks

Well, I don't know why, but I recreated the project from scratch and the issue went away. Curiously I had to use the name space of xmlns:f="http://java.sun.com/jsf/core" instead of xmlns:f="http://xmlns.jcp.org/jsf/core" to get the parameters to save to the bean.

This works for me with no problem in Mojarra 2.2.6 and Tomcat 7:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
    <h:head>
        <f:metadata>
            <f:viewParam name="email" />
            <f:viewParam name="key" />
        </f:metadata>
    </h:head>
    <h:body>
    #{email} - #{key}
    </h:body>
</f:view>
</html>

Also this one does:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core">
<f:view>
    <h:head>
        <f:metadata>
            <f:viewParam name="email" value="#{bean1.email}" />
            <f:viewParam name="key" value="#{bean1.key}" />
        </f:metadata>
    </h:head>
    <h:body>
    #{bean1.email} - #{bean1.key}
    </h:body>
</f:view>
</html>
@ManagedBean
@ViewScoped
public class Bean1 {

    public Bean1() {
        System.out.println("Bean created");
    }

    private String email;

    private String key;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
        System.out.println(email);
    }

    public String getKey() {
        return key;
    }

    public void setKey(String key) {
        this.key = key;
        System.out.println(key);
    }

}

It doesn't matter where I place the <f:metadata /> inside the <html /> , parameters are properly set.

Having seen your last comments, the issue seems to be related with your development tool not properly deploying resources to the server . Clean up your workspace and check the proper content is being copied.

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