我正在尝试使用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...
}
}
答案 0 :(得分:1)
将List<SelectItem> selectItems
存储在一个单独的会话范围的bean中(假设您当前的一个是请求范围的),在构造期间填充它并添加一个仅在{em>之后调用的reload()
之类的方法处理操作方法中的选定项目。您可以通过@ManagedProperty
从请求范围内访问会话范围的bean。