0

I use JSF 2.2, Mojarra 2.13. The code of my page (i tried to simplify as much as possible):

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
            template="./WEB-INF/templates/template.xhtml"
            xmlns:f="http://xmlns.jcp.org/jsf/core"
            xmlns:h="http://xmlns.jcp.org/jsf/html">

<ui:define name="metadata">
  <f:metadata>
    <f:viewParam name="id" value="#{bean.id}"/>
    <f:viewAction action="#{bean.myAction}"/>
  </f:metadata>
</ui:define>

<ui:define name="content">
  <h:form>
    Text:
    <h:inputText value="#{bean.question.text}"/>
    <h:commandButton value="Register" action="#{bean.register}"/>
  </h:form>
</ui:define>

</ui:composition>

I used a viewscoped backing bean (named bean) and it did not work. To test, I put it in a session scope and it does not work yet. This bean get an id in the URL, get a question in the database from this id and put the instance of Question in the property "question".

The problem is that 2 other beans are created after the page is displayed (without any action from me). So, if I change the text of the question, I get an error during the validation phase: FATAL: /page.xhtml @21,54 value="#{bean.question.text}": Target Unreachable, 'null' returned null.

If I remove the template, all is OK. I don't understand why the template causes the creation of several beans even though the scope of the bean is session!

Someone can help me? Have I made a mistake or is it a bug of Mojarra?

The template:

<?xml version='1.0' encoding='UTF-8' ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
  xmlns:h="http://xmlns.jcp.org/jsf/html">

 <ui:insert name="metadata"/>

 <h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <h:outputStylesheet name="/css/default.css"/>
    <h:outputStylesheet name="/css/cssLayout.css"/>
    <title>Quizz - by ITUA</title>
 </h:head>

<h:body>

    <div id="top">
        Quizz
    </div>
    <div>
        <div id="left">
            <ui:insert name="left">
                <ui:include src="menu.xhtml"/>
            </ui:insert>
        </div>
        <div id="content" class="left_content">
            <ui:insert name="content">Content</ui:insert>
        </div>
    </div>
  </h:body>

 </html>
Jasper de Vries
  • 19,370
  • 6
  • 64
  • 102
user1643352
  • 2,635
  • 2
  • 19
  • 25
  • http://stackoverflow.com/questions/7574115/jsf-2-facelets-fmetadata-in-template-and-page – Jasper de Vries May 06 '17 at 07:22
  • @JasperdeVries: in the reference you give, the problem was that `` was in the template and it is not the case for me (it is in the client of the template). – user1643352 May 06 '17 at 19:06
  • Sorry for the inconvenience. The problem comes from a stupid error: in the template a had an outcome returned by a method and this method closed the session! So a new session was created at each (re)display of a page. – user1643352 May 12 '17 at 14:49

0 Answers0