0

当我单击一行<p:dataTable>并单击命令按钮时,我想显示一个新对话框并将该行的值设置为一个表单(在新对话框中)。我使用会话 bean 来保留所选行的数据,但是当我选择新行时数据不会更改。我认为这是因为会话 bean 会保留数据直到会话过期。我已经尝试了所有范围,但没有一个工作

这是我的数据表

<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() {
    }
}
4

0 回答 0