当我单击<p:dataTable>
中的一行并单击命令按钮时,我想显示一个新对话框并将行的值设置为一个表单(在新对话框中)。我使用会话bean来保存所选行的数据,但是当我选择一个新行时,数据不会改变。我认为这是因为会话bean会在会话到期之前保留数据。我已经尝试了所有范围,但没有人工作
这是我的dataTable
<p:dataTable var="customer"
widgetVar="customerTable"
value="#{customerFacade.findAll()}"
selectionMode="single"
rowKey="#{customer.customerid}"
selection="#{editCustomerBean.customer}"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:ajax event="rowSelect" listener="#{editCustomerBean.onRowSelect}" update=":form:growl"/>
这是我的命令按钮和对话框
<h:form>
<p:dialog id="edit" header="Edit Customer" widgetVar="editCustomerDlg" resizable="false" showEffect="fade">
<h:panelGrid id="editDisplay" columns="2" columnClasses="alignTop">
<p:outputLabel for="editCompanyName" value="Company Name" />
<p:inputText id="editCompanyName"label="Compnay Name" value="#{editCustomerBean.customer.companyname}" required="true" />
<h:panelGroup/>
<p:commandButton value="Edit Customer" update="editDisplay" oncomplete="if (!args.validationFailed){editCustomerDlg.hide()}" actionListener="#{customerController.editCustomer}" />
</h:panelGrid>
</p:dialog>
<p:commandButton widgetVar="editBut" icon="ui-icon-tag" value="Edit" oncomplete="editCustomerDlg.show()"/>
</h:form>
这是我的会话bean
@Named(value = "editCustomerBean")
@SessionScoped
public class EditCustomerBean implements Serializable {
private Customer customer;
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public void onRowSelect(SelectEvent event) {
customer = (Customer) event.getObject();
System.out.println(customer.getAddress());
FacesMessage msg = new FacesMessage("Customer Selected", ((Customer) event.getObject()).getPhone());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public EditCustomerBean() {
}
}