代码之家  ›  专栏  ›  技术社区  ›  Anil Vishnoi

如何动态刷新h:selectmany复选框selectitems

  •  1
  • Anil Vishnoi  · 技术社区  · 16 年前

    我正在尝试使用JSF实现一个场景。我有一个 commandExButton 当用户点击这个按钮“A”时,它会显示 panelDialog 其中包含 selectManyCheckBox 项目。我通过解析一个不断更新的文件,在后端bean中生成这些项。我想要的是,每当我单击这个按钮“a”时,我应该通过后端bean解析文件来获取最新的selectitems。但我得到的是第一次呈现页面时生成的同一个selectitem。因此,到目前为止,我有一个解决方法,其中包括一个刷新按钮,它实际上刷新页面,然后用户单击“a”通过解析当前文件的内容来获取最新的selectitem。但是,它是否可以在不添加新按钮和使用现有按钮的情况下实现?

    下面是我使用的代码

    <td>
        <hx:commandExButton id="preferenceButton" styleClass="form" value="#{nls.preferenceLink}"
            title="#{nls.preferenceLinkTitle}" type="submit" />
    </td>
    <td>
        <h:form id="PrefForm" rendered="#{Test.isCurrent}">
            <hx:panelDialog type="modal" id="preferenceSet" styleClass="panelDialog" for="preferenceButton"
                title="#{nls.preferenceDialogTitle}">
                <h:outputText styleClass="panelStartMessage" style="display:block;"
                    value="#{nls.preferenceDialogWindowText}" />
                <h:panelGroup rendered="#{Test.hasSelectItem }"
                    style="display:block;width:300px;height:360px;overflow:auto;" styleClass="panelGroup"
                    id="prefPanelGroup">
                    <h:selectManyCheckbox value="#{Test.selectedItems}" layout="pageDirection">
                        <f:selectItems value="#{Test.selectItems}" />
                    </h:selectManyCheckbox>
                </h:panelGroup>
                <hx:panelBox styleClass="information_box" id="noCommandWindow" layout="lineDirection"
                    rendered="#{!Test.hasSelectItem }">
                    <h:outputText styleClass="outputText" id="cmdInfo" value="#{nls.noCommands}" />
                </hx:panelBox>
                <hx:panelBox id="buttonBox1" styleClass="panelStartBox" layout="lineDirection">
                    <hx:commandExButton id="submitPref" styleClass="commandExButton" type="submit"
                        value="#{nls.submit}" action="#{Test.action}">
                        <hx:behavior event="onclick" behaviorAction="hide" targetAction="preferenceSet"
                            id="behaviorSubmitPref" />
                    </hx:commandExButton>
                    <hx:commandExButton id="CancelPref" styleClass="commandExButton" type="submit"
                        value="#{nls.cancel}" action="Test">
                        <hx:behavior event="onclick" behaviorAction="hide" targetAction="preferenceSet"
                            id="behaviorCancelPref" />
                    </hx:commandExButton>
                </hx:panelBox>
            </hx:panelDialog>
        </h:form>
    </td>
    

    bean中的代码:

    public class Test{
        private List<String> selectedItems;
        private List<SelectItem> selectItems;
    
        public List<SelectItem> getSelectItems() {
            // populate the selectItem here...
        }    
    }
    
    1 回复  |  直到 12 年前
        1
  •  1
  •   BalusC    16 年前

    存储 List<SelectItem> selectItems 在单独的会话作用域bean中(假设您当前的会话作用域是请求作用域),在其构造过程中填充它并添加类似 reload() 你只调用它 之后 正在处理操作方法中的选定项。您可以从请求范围内访问会话范围的bean @ManagedProperty .

    推荐文章