页面两次调用同一功能的JSF [英] Page calling same function twice JSF

查看:47
本文介绍了页面两次调用同一功能的JSF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在此页面中,两次调用此部分.我看不出原因.导致的问题是selectone菜单中的选择将被重置,然后为第二个调用返回错误的结果.

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是一个会话bean.

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>

推荐答案

如果我正确理解了您的问题描述,则为预期的行为;JSF有一个请求的6个生命周期,并且每个生命周期都可以调用相同的方法.根据我的经验,根据JSF调用的阶段以及跳过的阶段,在单个请求中有时会发生两次,有时会发生三遍.

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.

您的工作是知道何时可能发生这种情况(通过研究生命周期阶段)并相应地设计代码,例如,通过确保方法在每个生命周期阶段都返回完全相同的内容来进行.可能有多种策略可以应用,例如利用特定范围(视图,会话,对话),通过延迟初始化或使用带有PostConstruct注释的bean初始化方法对bean进行一次初始化.

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.

如果您需要进一步的帮助,建议您也发布相关的服务器端(Java)代码.问题出在那儿.

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

这可能会有所帮助: http://balusc.blogspot.nl/2006/09/debug-jsf-lifecycle.html

这篇关于页面两次调用同一功能的JSF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆