简体   繁体   English

jsf中的CommandButton

[英]CommandButton in jsf

In my code the CommandButton action does not work when I put it in the second or third PanelGroup. 在我的代码中,将CommandButton操作放入第二个或第三个PanelGroup时不起作用。 It only works when I put in the first PanelGroup. 它仅在我放入第一个PanelGroup时有效。 My code is shown below. 我的代码如下所示。 What may be the problem? 可能是什么问题?

<ui:define name="pageLocations">
    <h:panelGroup layout="block" id="pageLocations">
        <c:if test="#{param.typeTab == null &amp;&amp; param.relationTab == null &amp;&amp; param.propertyTab == null}">
            <ui:param name="defaultHeaderTitle" value="Properties"/>
            <!--<h:outputText value="Properties" />--> 
        </c:if>
        <p class="breadcrumb">Admin <ezcomp:out value="raquo" /> 
            Fields <ezcomp:out value="raquo" /> 
            <strong>
                #{param.pageHeaderTitle}#{defaultHeaderTitle} 
            </strong>
        </p>
    </h:panelGroup>
</ui:define>
<!--<ui:define></ui:define>-->
<ui:define name="pageHeaderTitle">
    <h:outputText value="#{param.pageHeaderTitle}#{defaultHeaderTitle}" id="soso" /> 
</ui:define>

<ui:define name="sidemenu">
    <ui:param name="fieldsPage" value="active"/>
</ui:define>

<ui:define name="admin-content">
    <h:form prependId="false">
        <h:panelGroup layout="block" class="well well-small" id="mainPanel">
            <h:panelGroup layout="block" class="row-fluid">
                <div class="span1"><ezcomp:out value="nbsp"/></div>
                <div class="span4">
                    <ul class="nav nav-pills" style="margin-top:4px;margin-bottom:0">
                        <c:if test="#{param.typeTab == null &amp;&amp; param.relationTab == null &amp;&amp; param.propertyTab == null }">
                            <ui:param name="default" value="active"/>
                            <ui:param name="defaultHeaderTitle" value="Properties"/>
                        </c:if>
                        <li class="#{param.propertyTab} #{default}">
                            <p:commandLink  value="Properties" immediate="true" update="mainPanel,fields,:soso,:pageLocations" >
                                <f:param name="propertyTab" value="active"/>
                                <f:param name="pageHeaderTitle" value="Properties"/> 
                            </p:commandLink>
                        </li>
                        <li class="#{param.typeTab}">
                            <p:commandLink  value="Types" immediate="true" async="true" update="mainPanel,fields,:soso,:pageLocations" >
                                <f:param name="typeTab" value="active"/>
                                <f:param name="pageHeaderTitle" value="Types"/>
                            </p:commandLink>
                        </li>
                        <li class="#{param.relationTab}">
                            <p:commandLink value="Fields Relations" immediate="true" update="mainPanel,fields,:soso,:pageLocations">
                                <f:param name="relationTab" value="active"/>
                                <f:param name="pageHeaderTitle" value="Fields Relations"/>
                            </p:commandLink>
                        </li>
                    </ul>
                </div>

            </h:panelGroup>
        </h:panelGroup>
        <h:panelGrid id="fields" width="100%">

            <h:panelGroup layout="block" rendered="#{param.propertyTab == 'active' || default == 'active' }">
                <ui:include src="property/properties.xhtml"></ui:include>
            </h:panelGroup>
            <h:panelGroup layout="block" rendered="#{param.typeTab == 'active'}">
                <ui:include src="type/types.xhtml"></ui:include>
            </h:panelGroup>
            <h:panelGroup layout="block" rendered="#{param.relationTab == 'active'}">
                <ui:include src="fields-relations.xhtml"></ui:include>
                <h:commandButton value="Create" actionListener="#{fieldsRelationsController.createRelations()}"  >
                    <f:ajax listener="#{fieldsRelationsController.createRelations()}"/>
                </h:commandButton>

            </h:panelGroup>

        </h:panelGrid>

    </h:form>
</ui:define>

It's because those panel groups are conditionally rendered based on a request parameter which is not present anymore in the subsequent POST request initiated by the command button. 这是因为这些面板组是基于请求参数有条件地呈现的,该请求参数在命令按钮启动的后续POST请求中不再存在。

When JSF processes the POST request, the rendered condition is also re-evaluated. 当JSF处理POST请求时,还将重新评估rendered条件。 Due to lack of the request parameter, it evaluates false , so the command button component won't be processed, so the associated action won't be invoked. 由于缺少request参数,它的值为false ,因此不会处理命令按钮组件,因此不会调用关联的动作。

To fix this, you need to pass the request parameter responsible for calculating the result of the rendered attribute in a <f:param> of the command button. 要解决此问题,您需要在命令按钮的<f:param>中传递负责计算rendered属性结果的请求参数。

<h:commandButton value="Create" action="#{fieldsRelationsController.createRelations}">
    <f:ajax />
    <f:param name="relationTab" value="active"/>
</h:commandButton>

(note that I've replaced the actionListener by action and removed the double f:ajax listener as well, I don't know what you were thinking, but I'll assume it to be a leftover of unthoughtful shoots in the dark) (请注意,我已经用action替换了actionListener ,并且还删除了双重f:ajax listener ,我不知道您在想什么,但是我认为它是黑暗中未经考虑的拍摄的残余)

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM