0

In this page this part get called twice. I can't see the reason for this. The problem this leads to is that the selections in the selectonemenu will get reset and then return the incorrect result for the second call.

ServiceSeries is a session bean.

Can anyone tell me why this double call happens?

<c:forEach var="list" items="#{serviceSeries.getSeriesForPlayerInfo(club.name, player.stringID, st, calendarBean)}">

<!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:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:c="http://java.sun.com/jsp/jstl/core" 
      xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/template.xhtml">

    <ui:define name="content">

        <h:form>
        <div id="left">
        <h:commandLink action="player" value="Gå till spelare" />
        <br />
        <h:commandLink action="club" value="Gå till Klubb" />
        <br />
        <h:commandLink action="serieType" value="Gå till Serie typ" />
        <br />
        <h:commandLink action="serie" value="Gå till En serie" />
        <br />
        <h:commandLink action="serieTotal" value="Gå till Serie Total" />
        <br />
        <h:commandLink action="showAverages" value="Gå till snittlista" />
        <br />
        </div>

        <div id="right">
        <div id="pageHeader">Snitt information</div>

            <h:panelGrid columns="2">
            Spelare
            <p:selectOneMenu value="#{player}" 
                converter="playerConverter" id="playerList">
            <f:selectItem itemLabel="---" noSelectionOption="true" />
            <f:selectItems value="#{servicePlayer.allPlayers}"
             var="n"
             itemValue="#{n}"
             itemLabel="#{n.combinedName}"
             itemLabelEscaped="true"/>
            </p:selectOneMenu>

                <h:outputText value="Klubb"></h:outputText>
                <p:selectOneMenu id="ClubMenu" value="#{club.name}">
                    <f:selectItems value="#{serviceHCP.clubs}" />
                </p:selectOneMenu>
                <h:outputText value="Serietyp"></h:outputText>

                <p:selectOneMenu value="#{st}" 
                    converter="serieTypeConverter" id="serieTypeList">
                    <f:selectItem itemLabel="---" noSelectionOption="true" />
                <f:selectItems value="#{serviceSerieType.serieTypes}"
                     var="st"
                     itemValue="#{st}"
                     itemLabel="#{st.serie_type}"
                     itemLabelEscaped="true"/>
                </p:selectOneMenu>


                <h:outputText value="Startdatum"></h:outputText>
                <p:calendar value="#{calendarBean.date1}" id="popupButtonCal" showOn="button" pattern="yyyy-MM-dd HH:mm:ss" >
                    </p:calendar>
                <h:outputText value="Slutdatum"></h:outputText>
                <p:calendar value="#{calendarBean.date2}" id="popupButtonCal2" showOn="button" pattern="yyyy-MM-dd HH:mm:ss" >
                    </p:calendar>
                    <h:outputText value=""></h:outputText>
                <h:commandButton value="Visa lista" action="showSeriesInfo">

                </h:commandButton>
            </h:panelGrid>
            </div>


            <div id="right">
            Players
            <br />
            <!--  h:form  -->
            <h:panelGrid columns="9" border="1" cellpadding="3">
            <h:outputText value="Namn" />
            <h:outputText value="ID" />
            <h:outputText value="Klubb" />
            <h:outputText value="Datum" />
            <h:outputText value="typ" />
            <h:outputText value="Info" />
            <h:outputText value="Antal serier" />
            <h:outputText value="Total" />
            <h:outputText value="Snitt" />

            <c:forEach var="list" items="#{serviceSeries.getSeriesForPlayerInfo(club.name, player.stringID, st, calendarBean)}">
            <h:outputText value="   #{list[0].toString() }" />
            <h:outputText value="   #{list[1].toString() }" />
            <h:outputText value="#{serie.getSerieDateString(list[2]) }" />
            <h:outputText value="#{list[3].toString()}"/>
            <h:outputText value="   #{list[4].toString() }" />
            <h:outputText value="   #{list[5].toString() }" />
            <h:outputText value="   #{list[6].toString() }" />
            <h:outputText value="   #{list[7].toString() }" />
            <h:outputText value="   #{list[8].toString() }" />
            </c:forEach>

            </h:panelGrid>
            </div>
            </h:form>

    </ui:define>

</ui:composition>

</html>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user2130951
  • 2,601
  • 4
  • 31
  • 58
  • You might enjoy these two questions (and their answers): http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times and http://stackoverflow.com/questions/3342984/jstl-in-jsf2-facelets-makes-sense ; in particular, try replacing `` with a ``. – mabi Jan 14 '14 at 14:37

1 Answers1

0

If I understand your problem description correctly, its expected behavior; JSF has 6 lifecycles for a request and the same method may be invoked in each and every one of them; in my experience it sometimes happens twice and sometimes happens three times in a single request depending on which phases JSF invokes and which ones it skips.

Its your job to know that this can happen, when it can happen (by studying the lifecycle phases) and design your code accordingly, for example by ensuring that the methods return exactly the same thing for each and every lifecycle phase. There are multiple strategies that may apply, such as utilizing specific scopes (view, session, conversation), through lazy initialization or by using a bean init method annotated with PostConstruct to do one time initialization for a bean.

If you need further assistance, I suggest you post the relevant server side (Java) code too. the problem originates there somewhere.

This might help: http://balusc.blogspot.nl/2006/09/debug-jsf-lifecycle.html

Gimby
  • 5,095
  • 2
  • 35
  • 47
  • I had a stupid misstake in the code – user2130951 Jan 14 '14 at 14:19
  • Again: expected behavior, it will depend on what is done in the lifecycle phase what is passed and when. You really have to understand this stuff combined with how the statefulness of JSF works before JSF can start to work for you; until then it will surprise you at every corner. – Gimby Jan 14 '14 at 14:21
  • Understodd will check the link – user2130951 Jan 14 '14 at 14:29
  • That link will explain you how to debug specific lifecycle phases, but it won't teach you the what and the why. When I was dealing with that particularly difficult topic a few years ago (when it was still only JSF 1.2) I had trouble grasping it through the internet alone; I ended up getting the JSF reference book which made things a whole lot clearer for me. – Gimby Jan 14 '14 at 14:35
  • In particular, it won't help debug view build vs render time problems as they're both part of the render response phase... – mabi Jan 14 '14 at 14:42