1
votes

Sorry my English is not good. I have a issue with JSF2 Primefaces. I have a datatable with panigation which display list of customer and button at the end of each row. When user click on button website will redirect user to new page which to display customer's infomation. But it only work on the first page and when i next to other page button is not working. IDE not show any error. What am I doing wrong? Why is action method not called on any datatable page? Thank.

Screenshot

The View

<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>

Bean

@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();
}
}

Bean

@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
What does not work, <h:commandButton> on all but the first page? Besides, these verbose session scoped beans are completely unnecessary for performing this kind of tasks.Tiny
When i click to next page other first page then <h:commandButton> is not working, it only working at first page.mr.duongns
Only shooting in the dark : Try making <h:commandButton> Ajaxical using <f:ajax> or using <p:commandButton> to see, if it changes the behaviour.Tiny
Thank you but it not working for my issue :( when i click next to other page form is refresh and p:commandButton is not working, it only working at first page.mr.duongns
It's difficult give you an answer to this problem. Perhaps, you have a problem with JSF, if I were you I would try the old JSF notation without parameters in the action attribute. Here you have an example:Miguel

1 Answers

-1
votes

Replace

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

that will help you redirect to your customer's information page.