1

我正在尝试使用 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...
    }    
}
4

1 回答 1

1

将 bean存储List<SelectItem> selectItems在一个单独的会话范围 bean 中(假设您当前的 bean 是请求范围的),在其构造过程中填充它并添加一个方法,您只能处理 action 方法中的选定项目后reload()调用该方法。您可以从一个范围为.@ManagedProperty

于 2010-08-23T21:20:00.697 回答