【问题标题】:JSF combo box change to default valueJSF 组合框更改为默认值
【发布时间】:2026-01-21 20:55:02
【问题描述】:

我有一个 JSF 应用程序,其中有一个组合框。基于该组合框的值,我想更改其他两个组合框的值。

<h:outputText value="#{msgs.transformation_rule}"/>
      <h:panelGroup>
          <h:selectOneMenu id="dsTransformationRule" value="#{activityDataSource.selectedTransformationRule}"
                           disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}">
            <f:selectItems value="#{activityDataSource.transformationRules}"/>
          </h:selectOneMenu>
          <ui:fragment rendered="#{sp:hasRight(facesContext, 'ManageRules')}" >
              <input type="button" value="#{msgs.button_ellipsis}" class="ruleEditorBtn"
                     onclick="SailPoint.Rule.Editor.edit($('editForm:dsTransformationRule').value,
                             'ActivityTransformer',
                             $('editForm:refreshActivityDataSourceRulesButton'))" />
          </ui:fragment>
      </h:panelGroup>

      <h:outputText value="#{msgs.correlation_rule}"/>
      <h:panelGroup>
          <h:selectOneMenu id="dsCorrelationRule" value="#{activityDataSource.selectedCorrelationRule}"
                           disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}">
            <f:selectItems value="#{activityDataSource.correlationRules}"/>
          </h:selectOneMenu>
          <ui:fragment rendered="#{sp:hasRight(facesContext, 'ManageRules')}" >
              <input type="button" value="#{msgs.button_ellipsis}" class="ruleEditorBtn"
                     onclick="SailPoint.Rule.Editor.edit($('editForm:dsCorrelationRule').value,
                             'ActivityCorrelation',
                             $('editForm:refreshActivityDataSourceRulesButton'))" />
          </ui:fragment>
      </h:panelGroup>

      <h:outputText value="#{msgs.activity_data_src_type}"/>
      <h:panelGroup>
        <a4j:outputPanel id="collectorSettings">
          <h:selectOneMenu id="collectorType"
                           value="#{activityDataSource.object.type}"
                           rendered="#{empty activityDataSource.object.id}"
                           disabled="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           readonly="#{!sp:hasRight(facesContext, 'ManageApplication')}"
                           onchange="$('editForm:selectTypeButton').click();">
             <f:ajax event="change" 
                    execute="@this" 
                    render="dsTransformationRule dsCorrelationRule"
                    listener="#{activityDataSource.handleCollectorTypeChange}" />
            <f:selectItem itemValue="" itemLabel="#{msgs.select_collector_type}"/>
            <f:selectItems value="#{activityDataSource.collectorTypes}"/>
          </h:selectOneMenu>
          <h:selectOneMenu id="fixedCollectorType" value="#{empty activityDataSource.object.type ? 'None' : activityDataSource.object.type}"
                           rendered="#{not empty activityDataSource.object.id}"
                           disabled="true"
                           readonly="true">
            <f:selectItem itemValue="#{empty activityDataSource.object.type ? 'None' : activityDataSource.object.type}"
                          itemLabel="#{empty activityDataSource.object.type ? msgs.none : activityDataSource.object.type}"/>
          </h:selectOneMenu>
        </a4j:outputPanel>

<a4j:commandButton id="selectTypeButton" action="#{activityDataSource.selectType}" style="display:none"
                       render="configSettings, collectorSettings"
                       oncomplete="initializeSelectedConfigPage();"/>

现在的问题是我无法理解

onchange="$('editForm:selectTypeButton').click();">

我为collectorType 的更改事件编写了ajax 部分,其中我正在更改其他两个组合框的值。 此外,我希望 collectorType 中的一个值将另外两个组合框更改为默认文本,如“选择收集器类型”。我该怎么做。

在正常更改事件之前触发 ajax 事件。

【问题讨论】:

    标签: java jquery jsf jsf-2 combobox


    【解决方案1】:

    Richfaces 的原理与 Primefaces 相同。您的 ajax 调用应该更新其他支持 bean 的当前值

    这个 ajax 调用将更新当前的俱乐部。

    <p:ajax event="change" execute="@this" listener="#{serviceHCP.getClubs(player)
    
    serviceHCP.myCurrentClub // Will be set and used in the next menu.
    
    <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:ajax event="change" execute="@this" listener="#{serviceHCP.getClubs(player) }" update="clubMenu" render="clubMenu"/>
                </p:selectOneMenu>
    
                <h:outputText value="Klubb"></h:outputText>
                   <p:selectOneMenu value="#{serviceHCP.myCurrentClub}" converter="clubConverter" id="clubMenu" >
                        <f:selectItem itemLabel="---" noSelectionOption="true" />
                        <f:selectItems value="#{serviceHCP.myClubList}"
                     var="clb"
                     itemValue="#{clb}"
                     itemLabel="#{clb.name}"
                     itemLabelEscaped="true"/>
                </p:selectOneMenu>
    

    【讨论】:

    • 你能告诉我这行的意思吗? onchange="$('editForm:selectTypeButton').click();">
    • 它似乎模拟了点击按钮。