Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 433
oxax Avatar asked Jan 12 '23 12:01

oxax


1 Answers

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
like image 98
BalusC Avatar answered Jan 30 '23 23:01

BalusC