【问题标题】:JSF 2.x <p:selectManyMenu>, <f:selectItems>, <p:selectOneMenu> default selectionJSF 2.x <p:selectManyMenu>, <f:selectItems>, <p:selectOneMenu> 默认选择
【发布时间】:2015-06-23 11:36:50
【问题描述】:

我有一个&lt;p:selectOneMenu&gt;,您可以在其中选择一个级别;填充有一个列表,当单击其中一个&lt;f:selectItems&gt; 然后使用&lt;p:ajax&gt; 我用另一个列表更新我的&lt;p:selectManyMenu&gt; 条目。我希望它默认选择该条目列表中的第一个元素并标记它,这不是发生的情况。

实际情况是,它采用保存在属性submittedValue 中的旧值并使用该属性中存储的值,这在当前列表中不存在,因此没有标记。

selectOneMenu

<p:selectOneMenu id="levelSelection" style="width:342px;text-align:left"
       panelStyle="width:180px"
       value="#{cc.attrs.agOptionObj.levelTemp}"
       onchange="onLevelSelectionChange(this), updateChild();"
       panelStyleClass="auto-close-panel"
       converter="lyngsoe.catellae.converter.LongOptionConverter"
       rendered="#{!cc.attrs.agOptionObj.hidePartitionSelection}">
           <f:selectItems
               value="#areaGroupSelection.getLevelsForHierarchy
                      (cc.attrs.agOptionObj,
                      cc.attrs.controller.model.periodSelectionOption,                        
                      cc.attrs.controller.reportName)}"
               var="levelOpt" 
               itemLabel="#{levelOpt.text}" 
               itemValue="#{levelOpt}"/>

           <p:ajax 
               update="levelEntries"
               listener="#{areaGroupSelection.levelChanged
                    (cc.attrs.agOptionObj,
                    cc.attrs.controller.model.periodSelectionOption)}"
               partialSubmit="true"/>
</p:selectOneMenu>

selectManyMenu

<p:selectManyMenu id="levelEntries"
        value="#{cc.attrs.agOptionObj.entriesTemp}"
        style="width:342px;text-align:left;height:150px"
        onchange="onEntriesSelectionChange(this);"
        converter="lyngsoe.catellae.converter.StringOptionConverter"
        rendered="#{!cc.attrs.hidePartitionSelection}"
        required="true"
        requiredMessage="#{msg['areaGroupSelection.areaError']}">
            <f:selectItems
               value="#{areaGroupSelection.getHierarchyNodesAtLevel
                         (cc.attrs.agOptionObj,
                         cc.attrs.controller.model.periodSelectionOption)}"
               var="entryOpt" itemLabel="#{entryOpt.text}" itemValue="#               
                           {entryOpt}"/>
</p:selectManyMenu>

我已阅读并尝试了以下链接:

我不确定,我正在寻找的是使用以下之一:

澄清一下:我需要能够从我的&lt;p:selectOneMenu&gt; 中进行选择,然后填充我的&lt;p:selectManyMenu&gt; 并且将&lt;p:selectManyMenu&gt; 中的第一个元素默认选中。

如果需要进一步澄清,请写信 - 我会像鹰一样监视这篇文章。

【问题讨论】:

  • 有了这些链接,你的意思是说&lt;p:ajax resetValues="true"&gt; 不起作用?
  • primefaces 中有类似的吗? showcase.omnifaces.org/eventlisteners/… ? @BalusC:将仔细检查
  • @BalusC 我又试了一次,这次成功了——起初我遇到了某种 og gui 故障;无法复制它,所以我相信它是有效的。

标签: jsf-2 primefaces


【解决方案1】:

这个问题与这里已经解释和回答的理由相同:How can I populate a text field using PrimeFaces AJAX after validation errors occur?

在您的具体情况下,只需使用&lt;p:ajax resetValues="true"&gt;。您只需要确保&lt;p:ajax update&gt; 覆盖了需要重置的输入组件,而&lt;p:ajax process&gt; 没有覆盖它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 2012-12-12
    • 2012-05-26
    • 1970-01-01
    • 1970-01-01
    • 2014-06-11
    相关资源
    最近更新 更多