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

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

问题描述

我正在尝试使用带有 Java EE 7 XML 命名空间的 Glassfish 4.0 来测试下面的示例.

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.movi​​eId}null.换句话说, 没有设置这个请求参数.

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?

推荐答案

处理新 xmlns.jcp.org XML 命名空间的方式在第一个 Mojarra 版本 2.2.0 和2.2.1.它已在 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 版本中并不罕见(所有人都急于按时准备好).我建议等到 GlassFish 4.0.1 或 4.1 发布后再使用 Java EE 7,以避免将来出现意外.请注意,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天全站免登陆