f:viewParam is not working

我的梦境 提交于 2019-12-11 13:13:54

问题


I am using JSF 2.2.4 on GlassFish 3.1.2.2.

I have this backing bean:

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import java.io.Serializable;

@ManagedBean(name="testMB")
@RequestScoped
public class TestMB implements Serializable {

    public long id;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }
}

And this view test.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">    

 <f:metadata>
    <f:viewParam name="id" value="#{testMB.id}"/>
 </f:metadata>

<h:body>
    <h:inputText value="#{testMB.id}" />
</h:body>
</html>

When I open /test.html?id=123, then the ID shows up as 0 instead of 123. Why didn't <f:viewParam> do its job?

Updated

I installed GlassFish 4.0.

Maven dependencies for JSF:

<dependency>
    <groupId>javax.faces</groupId>
    <artifactId>javax.faces-api</artifactId>
    <version>2.2</version>
</dependency>

faces-config.xml:

<?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://xmlns.jcp.org/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
              version="2.2">

    <!-- JSF and Spring are integrated -->
    <application>
        <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
    </application>

</faces-config>

And test.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:h="http://xmlns.jcp.org/jsf/html">

<f:metadata>
    <f:viewParam name="id" value="#{testMB.id}"/>
</f:metadata>

<h:body>
    <h:inputText value="#{testMB.id}" />
</h:body>
</html>

But the ID shows up as 0.

Maven project for test: https://www.dropbox.com/s/qbc05vysspvt46l/jsf-spring-mybatis-master.zip


回答1:


Problem solved

Pages named as *.xhtml.

In web.xml was:

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping> 

Right:

<url-pattern>*.xhtml</url-pattern>


来源:https://stackoverflow.com/questions/19983789/fviewparam-is-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!