使用新的xmlns.jcp.org命名空间时,f:viewParam不传递必需的参数 [英] f:viewParam doesn't pass required parameter when new xmlns.jcp.org namespace is used

查看:137
本文介绍了使用新的xmlns.jcp.org命名空间时,f:viewParam不传递必需的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Glassfish 4.0与Java EE 7 XML名称空间一起使用,以测试下面的示例.

I am trying to use Glassfish 4.0 with Java EE 7 XML namespaces to test the sample below.

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Title</title>
    </h:head>
    <h:body>
        <h:form>
             <ul>
                 <ui:repeat value="#{appLoad.movieList}" var="movie">
                    <li>
                        <h:link value="#{movie.title}" outcome="movie" includeViewParams="true">
                            <f:param name="id" value="#{movie.id}"/>
                        </h:link>
                    </li>
                </ui:repeat>
            </ul>
        </h:form>
    </h:body>
</html>

它链接到以下页面movie.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
    xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <f:metadata>
            <f:viewParam name="id" value="#{appLoad.movieId}"/>
            <f:event listener="#{appLoad.movieDetail()}" type="preRenderView"/>
        </f:metadata>
    </h:head>
    <h:body>
        <h:form>
            <h:panelGrid columns="2">
                <h:panelGrid columns="1" width="400">
                    <h:panelGrid columns="1">
                        Title : <h:outputLabel value="#{appLoad.movie.title}"/>
                    </h:panelGrid>  
                </h:panelGrid> 
            </h:panelGrid>  
        </h:form>
    </h:body>
</html>

#{appLoad}支持bean是

@ManagedBean
@RequestScoped
public class AppLoad {

    @EJB
    private MovieFacade movieFacade;
    private Movie movie = new Movie();
    private List<Movie> movieList;
    private int movieId;

    @PostConstruct
    public void movieDetail(){
        movieList = movieFacade.findAll();
        movie = movieFacade.find(movieId);
        System.out.println(movieId);
    }

    // Getters+setters.        
}

运行索引页并单击链接时,URL完全更改为

When the index page is run, and the link is been clicked, the url outrightly changed to

result.xhtml?id = 8

result.xhtml?id=8

但未显示任何数据.它是空白的.我发现#{appLoad.movieId}null.换句话说,<f:viewParam>不会设置此请求参数.

But no data is been displayed. Its comes as blank. I figured out that #{appLoad.movieId} is null. In other words, the <f:viewParam> does not set this request parameter.

我唯一的解决方法是将XML名称空间改回旧版本.

The only work around I had was to change the XML namespaces back to the older version.

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

我想我在这里出了点问题.这个问题是怎么引起的,我应该如何使用新的XML名称空间?

I'm guessing I'm getting something wrong here. How is this problem caused and how am I supposed to use the new XML namespaces?

推荐答案

在第一个Mojarra版本2.2.0和2.2.1中,如何处理新的xmlns.jcp.org XML名称空间.它已在 Mojarra 2.2.2 中进行了修复(注意:链接中的票证描述了不同的名称问题症状,但在本质上,这是相同的原因).建议升级到Mojarra 2.2.2. GlassFish 4.0捆绑了Mojarra 2.2.0.您可以从 javaserverfaces.java.net 获取JAR.您需要做的就是用较新的版本替换GlassFish的/modules文件夹中的javax.faces.jar文件.

The way how the new xmlns.jcp.org XML namespaces are been handled is broken in the first Mojarra releases 2.2.0 and 2.2.1. It has been fixed in Mojarra 2.2.2 (note: ticket in the link describes different problem symptom, but under the covers, it's essentially the same cause). It's recommended to upgrade to Mojarra 2.2.2. GlassFish 4.0 has Mojarra 2.2.0 bundled. You can get the JAR from javaserverfaces.java.net. All you need to do is to replace javax.faces.jar file in GlassFish's /modules folder with the newer version.

顺便说一句,这种麻烦在GlassFish的第一个主要发行版中并不罕见(所有麻烦都无法按时完成).我建议等到Java EE 7才能发布GlassFish 4.0.1或4.1,以免日后出现意外情况.请注意,其他供应商(如Apache Tomcat和JBoss AS)花时间发布稳定的Java EE 7容器.他们目前还没有可用于生产的版本.

This kind of trouble is by the way not unusual with the very first major GlassFish release (all hastle to get it ready on time). I recommend to wait with Java EE 7 until GlassFish 4.0.1 or 4.1 has been released to avoid future surprises. Note that other vendors like Apache Tomcat and JBoss AS take their time to release a stable Java EE 7 container; they do currently not have a production ready version yet.

这篇关于使用新的xmlns.jcp.org命名空间时,f:viewParam不传递必需的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆