f:viewParam doesn't pass required parameter when new xmlns.jcp.org namespace is used

时光怂恿深爱的人放手 提交于 2019-11-26 17:17:34

问题


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>

It links to the following page 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>

The #{appLoad} backing bean is

@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.        
}

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

result.xhtml?id=8

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.

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">

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?


回答1:


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.

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.

See also:

  • Using new xmlns.jcp.org namespace on composites causes java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.putIfAbsent


来源:https://stackoverflow.com/questions/18517384/fviewparam-doesnt-pass-required-parameter-when-new-xmlns-jcp-org-namespace-is

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