Getters inside f: verbatim called before submitting a form

I have the following page:

<h:form id="gameSelectionForm"> <h:selectOneMenu id="gameSelection"> <f:selectItems value="#{gameBean.gameIds}" /> </h:selectOneMenu> <h:commandButton id="gameSelector" value="Play" action="#{gameBean.changeGame}" /> </h:form> <h:panelGroup id="gameDiv"> <f:verbatim> <iframe src="/levelup/resources/games/#{gameBean.gameId}/#{gameBean.htmlPage}" width="700px" height="800px" frameborder="0"/> </f:verbatim> </h:panelGroup> 

When I click the "gameSelector" button, here is the sequence of events: 1. GameBean.getGameId and gameBean.getHtmlPage are called. 2. GameBean.changeGame is called. 3. The page has been updated.

My problems are in order 1. and 2. ChangeGame changes the variable gameBean, which is used by getGameId and getHtmlPage. Therefore, I want it to be executed first, so that when the other panels are updated, they contain the correct data.

Note that this problem only occurs for a call inside the gameDiv element (other variables are properly updated).

Do you have any idea as to what I can do to return order 1. and 2. so that the changeGame () method is the first one called?

I am using JavaServer Faces 2.0 on Tomcat 7.0.

Thanks in advance

+2
java jsf
source share
3 answers

According to your own answer on this topic:

I removed the f: verbatim tag and now it works correctly. I still don't understand why this caused this behavior.

<f:verbatim> was introduced in JSF 1.0 a long time ago for the sole purpose of incorporating plain HTML into the JSF component tree. In JSF 1.0 (and 1.1), when the component tree was built, all plain HTML was ignored. First, the page is processed using all simple HTML, and then the HTML code of the JSF components is displayed. For example,

 <p>Hello</p> <h:inputText /> <p>World</p> <h:outputText value="outputtext" /> <p>This is weird</p> 

it will turn out like

 <p>Hello</p> <p>World</p> <p>This is weird</p> <input type="text" /> outputtext 

<f:verbatim> allowed developers to use simple HTML in the JSF component tree so that they appear "synchronously" as you would expect from coding.

 <f:verbatim><p>Hello</p></f:verbatim> <h:inputText /> <f:verbatim><p>World</p></f:verbatim> <h:outputText value="outputtext" /> <f:verbatim><p>This is weird</p></f:verbatim> 

However, they are inserted while viewing the build , and not while viewing the render . This is the cause of your problem, getters are called during the recovery phase, and not for rendering the response phase.

Since JSF 1.2, with an improved view handler, you could embed plain HTML "in sync" without any problems with the ugly <f:verbatim> tags. So this is no longer necessary. There are also no useful use cases for a tag, expect some premature performance optimizations, but you should not use it in conjunction with dynamic data obtained using an expression language.

Related questions:

  • (Dis) Benefits of JSF 2.0
+5
source share

Put in the commandButton attribute the immediate attribute set to true.

 <h:commandButton id="gameSelector" value="Play" action="#{gameBean.changeGame}" immediate="true" /> 

He will then execute the method in the ApplyRequestValues ​​step.

0
source share

I removed the f: verbatim tag and now it works correctly. I still don't understand why this caused this behavior.

0
source share

All Articles