我试图在单击搜索按钮时在对话框中设置一些信息,但我面临的问题是 f:setPropertyActionListener 没有在辅助bean中设置目标值,所以当弹出窗口是空的。
对话框如下所示:
<h:form id="form">
<p:fieldset legend="Saved Branches" style="margin-bottom: 30px;">
<p:dataTable id="branches" var="branch" value="#{branchOnBoarding.savedBranches}">
<f:facet name="header">
Branch Information
</f:facet>
<p:column headerText="Branch Name">
<h:outputText value="#{branch.branchName}" />
</p:column>
<p:column headerText="Branch Code">
<h:outputText value="#{branch.branchCode}" />
</p:column>
<p:column headerText="Building">
<h:outputText value="#{branch.building}" />
</p:column>
<p:column headerText="Street">
<h:outputText value="#{branch.street}" />
</p:column>
<p:column headerText="City">
<h:outputText value="#{branch.city}" />
</p:column>
<p:column headerText="State">
<h:outputText value="#{branch.state}" />
</p:column>
<p:column headerText="Country">
<h:outputText value="#{branch.country}" />
</p:column>
<p:column style="width:32px;text-align: center">
<p:commandButton update=":form:branchDetail" oncomplete="PF('branchDialog').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{branch}" target="#{branchOnBoarding.selectedBranch}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Branch Info" widgetVar="branchDialog">
<p:outputPanel id="branchDetail" style="text-align:center;">
<p:panelGrid columns="2" rendered="#{not empty branchOnBoarding.selectedBranch.branchName}" columnClasses="label,value">
<h:outputText value="Branch Name:" />
<h:outputText value="#{branchOnBoarding.selectedBranch.branchName}" />
<h:outputText value="Branch Code:" />
<h:outputText value="#{branchOnBoarding.selectedBranch.branchCode}" />
<h:outputText value="Building:" />
<h:outputText value="#{branchOnBoarding.selectedBranch.building}" />
<h:outputText value="Street:" />
<h:outputText value="#{branchOnBoarding.selectedBranch.street}" />
<h:outputText value="City:" />
<h:outputText value="#{branchOnBoarding.selectedBranch.city}" />
<h:outputText value="State:" />
<h:outputText value="#{branchOnBoarding.selectedBranch.state}" />
<h:outputText value="Country:" />
<h:outputText value="#{branchOnBoarding.selectedBranch.country}" />
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</p:fieldset>
支持bean的代码如下所示:
@Component(value="branchOnBoarding")
@ManagedBean
@SessionScoped
@SpringScopeView
public class BranchOnBoarding implements Serializable{
private BranchUI branchUI = new BranchUI();
private List<Branch> savedBranches = new ArrayList<>();
private Branch selectedBranch;
public Branch getSelectedBranch() {
return selectedBranch;
}
public void setSelectedBranch(Branch selectedBranch) {
this.selectedBranch = selectedBranch;
}
public List<Branch> getSavedBranches() {
savedBranches = branchDao.findAll();
//for(Branch b:savedBranches)
//System.err.println(b.getBranchName());
return savedBranches;
}
public void setSavedBranches(List<Branch> savedBranches) {
this.savedBranches = savedBranches;
}
}
对话框如下所示: