我有下一个 JSF 代码:
按钮:
<p:layoutUnit id="centerLayoutUnit" position="center">
<h:form id="form" styleClass="my_form">
<p:growl id="msgs" showDetail="false" />
<p:toolbar id="alarmTableToolbar">
<p:toolbarGroup align="left">
<p:commandButton value="Ack/comment" disabled="false"
action="#{alarmTable.checkAllSelectedAlarmsIsInOneAckCondition()}"
icon="ui-icon-close" update="msgs :ackDialog"
style="min-width : 75px; height : 26px" />
...........
并在同一个form和layoutUnit的dataTable中:
<p:dataTable id="alarmTable" value="#{alarmTable.alarms}"
selection="#{alarmTable.selectedAlarm}" selectionMode="multiple"
var="alarm" resizableColumns="true" paginator="true" rows="50"
emptyMessage="No alarms" sortBy="#{alarm.alarmTs}"
sortOrder="descending"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="25, 50, 75, 100" lazy="true"
style="table-layout: auto" dblClickSelect="true">
同一个 LayoutUnit 中的对话框,但不是同一个表单:
<p:dialog id="ackDialog" header="Acknowledge/comment dialog"
widgetVar="ackDlg" modal="false" height="143" width="285"
dynamic="false" resizable="false" appendToBody="false">
<h:form id="formAckDialog">
<h:selectOneMenu id="ackTemplate"
value="#{alarmTable.selectedIdOfAckTemplate}" required="false"
disabled="#{alarmTable.checkSelectedAlarmsIsAck()}">
<f:selectItem itemLabel="template selection" itemValue="" />
<f:selectItems value="#{alarmTable.initAckTemplatesName()}" />
</h:selectOneMenu>
<p:inputTextarea rows="4" cols="47" counter="counter"
maxlength="1024" counterTemplate="{0} characters remaining."
autoResize="true" value="#{alarmTable.commentText}" />
<h:outputText id="counter" />
<div align="right">
<p:commandButton id="ackComment" value="Ack/comment" disabled="false"
actionListener="#{alarmTable.sumbitAckComment}"
update=":form:msgs" style="min-width : 75px; height : 26px;" />
</div>
</h:form>
</p:dialog>
AlarmTable 它的 bean 具有:
@ManagedBean
@SessionScoped
和领域:
private MyClass[] selectedAlarm;
和方法:
public boolean checkAllSelectedAlarmsIsInOneAckCondition() {
if (selectedAlarm == null || selectedAlarm.length == 0) {
JSFUtil.addErrorMessage("No alarms are selected");
return false;
}
RequestContext context = RequestContext.getCurrentInstance();
for (AlarmMts alarm : selectedAlarm) {
if (!selectedAlarm[0].isAck.equals(alarm.isAck)) {
JSFUtil.addErrorMessage("Not all selected alarms are acknowledged or not acknowledged");
return false;
}
}
context.execute("ackDlg.show()");
return true;
}
public boolean checkSelectedAlarmsIsAck() {
if (selectedAlarm == null || selectedAlarm.length == 0)
return false;
for (AlarmMts alarm : selectedAlarm) {
if (!alarm.isAck.equals(new BigDecimal(1)))
return false;
}
return true;
}
public void sumbitAckComment(ActionEvent actionEvent) {
boolean closeDialog = false;
if ((selectedIdOfAckTemplate == null || selectedIdOfAckTemplate.equals(new BigDecimal(0))) && commentText.isEmpty())
JSFUtil.addErrorMessage("Please fill in something");
if (selectedIdOfAckTemplate != null && !selectedIdOfAckTemplate.equals(new BigDecimal(0))) {
closeDialog = ackSelectedAlarms(Factory.getInstance().getAcknowledgeTemplateDAO().getAckTemplateById(selectedIdOfAckTemplate));
}
if (commentText != null && !commentText.isEmpty()) {
closeDialog = commentSelectedAlarms(commentText);
}
if (closeDialog) {
RequestContext.getCurrentInstance().execute("ackDlg.hide()");
}
}
所以问题是,当在对话框创建方法checkAllSelectedAlarmsIsInOneAckCondition()和checkSelectedAlarmsIsAck()被调用时,它们在selectedAlarm字段中有一个正确的(!= null)选定项。但是当用户按下按钮 - 对话框中的 ackComment 时,selectedAlarm为空。有什么建议吗?