带有primefaces的数据表上的按钮仅适用于第一页

时间:2015-10-14 02:03:16

标签: jsf jsf-2 primefaces datatable

抱歉我的英语不好。我有JSF2 Primefaces的问题。我有一个带有panigation的数据表,它在每行末尾显示客户和按钮列表。当用户点击按钮网站时,会将用户重定向到显示客户信息的新页面。但它只适用于第一页,当我旁边的其他页面按钮不起作用。 IDE未显示任何错误。我究竟做错了什么?为什么不在任何数据表页面上调用action方法?感谢。

Screenshot

视图

<h:form>
    <p:fieldset legend="Danh sách khách hàng">
        <p:dataTable var="customer" value="#{listCustomerBean.customers}"
            paginator="true" rows="10" paginatorPosition="bottom"
            paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
            id="dskh" first="">
            <p:column headerText="Mã khách hàng">
                <h:outputText value="#{customer.customerId}"></h:outputText>
            </p:column>
            <p:column headerText="CMND">
                <h:outputText value="#{customer.idNo}"></h:outputText>
            </p:column>
            <p:column headerText="Ngày cấp">
                <h:outputText value="#{customer.idIssueDate}"></h:outputText>
            </p:column>
            <p:column headerText="Nơi cấp">
                <h:outputText value="#{customer.idIssuePlace}"></h:outputText>
            </p:column>
            <p:column headerText="Tên khách hàng">
                <h:outputText value="#{customer.name}"></h:outputText>
            </p:column>
            <p:column headerText="Ngày sinh">
                <h:outputText value="#{customer.dob}"></h:outputText>
            </p:column>
            <p:column headerText="Giới tính">
                <h:outputText value="#{customer.gender}"></h:outputText>
            </p:column>
            <p:column headerText="Quốc tịch">
                <h:outputText value="#{customer.nationality}"></h:outputText>
            </p:column>
            <p:column headerText="Tỉnh">
                <h:outputText value="#{customer.province}"></h:outputText>
            </p:column>
            <p:column headerText="Quận">
                <h:outputText value="#{customer.district}"></h:outputText>
            </p:column>
            <p:column headerText="Xã">
                <h:outputText value="#{customer.precinct}"></h:outputText>
            </p:column>
            <p:column headerText="Địa chỉ">
                <h:outputText value="#{customer.address}"></h:outputText>
            </p:column>
            <p:column headerText="Tài khoản">
                <h:outputText value="#{customer.accountId}"></h:outputText>
            </p:column>
            <p:column headerText="Email">
                <h:outputText value="#{customer.email}"></h:outputText>
            </p:column>
            <p:column headerText="Di động">
                <h:outputText value="#{customer.mobiNumber}"></h:outputText>
            </p:column>
            <p:column headerText="Thông báo Email">
                <h:outputText value="#{customer.emailNotification}"></h:outputText>
            </p:column>
            <p:column headerText="Thông báo SMS">
                <h:outputText value="#{customer.smsNotification}"></h:outputText>
            </p:column>
            <p:column headerText="Chọn">
                <h:commandButton value="Xem"
                    action="#{listSubscriberBean.view(customer.accountId)}"></h:commandButton>
            </p:column>
        </p:dataTable>
        <br></br>
    </p:fieldset>
</h:form>

@ManagedBean
@SessionScoped

public class ListCustomerBean implements Serializable {

private List<Customer> customers;
private CustomerDAO customerDAO = new CustomerDAO();

public List<Customer> getCustomers() {
    return customers;
}

public ListCustomerBean() {
    customers = customerDAO.findAll();
}
}

@ManagedBean
@SessionScoped

public class ListSubscriberBean implements Serializable {

private List<Subscriber> subscribers;
private Customer customer;
private SubscriberDAO subscriberDAO = new SubscriberDAO();
private CustomerDAO customerDAO = new CustomerDAO();
private Long accId;
private String text;

public Customer getCustomer() {
    return customer;
}

public void setCustomer(Customer customer) {
    this.customer = customer;
}

public Long getAccId() {
    return accId;
}

public void setAccId(Long accId) {
    this.accId = accId;
}

public List<Subscriber> getSubscribers() {
    return subscribers;
}

public String view(Long id) {
    this.setAccId(id);
    customer = customerDAO.findByAccountId(accId);
    subscribers = subscriberDAO.findByAccountId(accId);
    return "listSubscriber";
}

public String update() {
    if (customerDAO.addCustomer(this.getCustomer()) == true) {
        return "listSubscriber";
    } else {
        return "error";
    }
}

public String getText() {
    return text;
}

public void setText(String text) {
    this.text = text;
}

public ListSubscriberBean() {

}

}

1 个答案:

答案 0 :(得分:-1)

替换

<h:commandButton/> with <p:commandButton ajax="false"/>

可帮助您重定向到客户的信息页面。