Cant get lazy datatable with h:commandlink to work properly

UI Components for JSF
Post Reply
rabathos
Posts: 2
Joined: 24 Mar 2012, 05:40

24 Mar 2012, 10:21

Hi, i can't find a solution to my problem... please help: I have a lazy datatable with a h:commandlink like shown below... i am using PF 3.2, Mojarra 2.1.3 and Tomcat 6

Code: Select all

<ui:composition>
    <h:form id="userTableForm" prependId="false">
        <p:dataTable id="user_table" var="user" value="#{userTableBean.lazyUserList}"
                     paginator="true" rows="5" lazy="true" dynamic="true"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15">
             .
             .
             . (other columns for User object here)
             .
            <p:column headerText="Edit">
                <h:commandLink type="submit" action="#{userTableBean.deleteUser}">
                        <f:param name="paramUserId" value="#{user.id}"/>
                        <h:outputText value="delete" />
                </h:commandLink>
            </p:column>
        </p:dataTable>
    </h:form>
</ui:composition>
and the backing bean UserTableBean (currently request-scoped in my faces-config.xml) with editUser action:

Code: Select all

public class UserTableBean extends User {

    private UserDAO userDAO;
    private AuthorityDAO authorityDAO;
    private ExternalContext jsfContext;
    private LazyDataModel<User> lazyUserList;

    public UserTableBean() {
        System.out.println("++++++++++++++++++++++++++++++++++++ UserTableBean ++++++++++++++++++++++++++++++++"); // this is shown in the console so my bean constructor is being called
    }

    public void setUserDAO(UserDAO userDAO) {
        this.userDAO = userDAO;
    }

    public void setAuthorityDAO(AuthorityDAO authorityDAO) {
        this.authorityDAO = authorityDAO;
    }

    public void setLazyUserList(LazyDataModel<User> lazyUserList) {
        this.lazyUserList = lazyUserList;
    }

    public String deleteUser() throws SQLException { // this method does not get called at all if I'm using lazy loading of my User object! But it works fine otherwise
        jsfContext = FacesContext.getCurrentInstance().getExternalContext();

        Long id = Long.parseLong(jsfContext.getRequestParameterMap().get("paramUserId"));
        userDAO.deleteUserById(id);

        return "delete";
    }

    public LazyDataModel<User> getLazyUserList() {
        return lazyUserList;
    }
}
and my faces-config.xml managed bean configuration (I'm not yet used to using annotaions @ManagedBean, @RequestScoped... etc. please bear with me for now):

Code: Select all

    <managed-bean>
        <managed-bean-name>userTableBean</managed-bean-name>
        <managed-bean-class>com.wegc.bean.UserTableBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
        <managed-property>
            <property-name>userDAO</property-name>
            <value>#{userDAO}</value>
        </managed-property>
        <managed-property>
            <property-name>authorityDAO</property-name>
            <value>#{authorityDAO}</value>
        </managed-property>
        <managed-property>
            <property-name>lazyUserList</property-name>
            <value>#{userDAO.lazyUserList}</value>
        </managed-property>
    </managed-bean>
Without lazy loading, my current codes works perfectly fine and the deleteUser method is called when the h:commandLink and clicked. But after applying lazy loading, h:commandlink does not call the userTableForm.deleteUser method anymore... By the way, pagination works fine in both scenarioes

I know this issue has been asked countless times like in viewtopic.php?f=3&t=3346&p=15353&hilit= ... ink#p15353 and viewtopic.php?f=3&t=13613&p=41158&hilit ... ink#p41158 but I can't get it to work at all with PrimeFaces 3.2... Please tell me what to do to get this working, i know this was supposed to have been fixed in PF 2.2 and above versions (i.e. viewtopic.php?f=3&t=5893&p=25026&hilit= ... ink#p25026) but I'm probably doing something wrong here because mine is not working :(
Primefaces 3.2
Mojara 2.1.3
Tomcat 6.0.26

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

24 Mar 2012, 15:21

If you are experiencing the arithmetic by zero error, then search google for:

forum.primefaces.org smithh032772 lazy

Also, you can search for the same, if you are looking for sample code related to lazy datamodel. I use lazy datamodel a lot, I delete via p:dataTable row selection and p:commandButton outside of the p:dataTable.

Also, search for:

forum.primefaces.org smithh032772 lazy customer

I would recommend that you move your commandLink to outside of your dataTable, add multiple row selection, so users can select multiple rows to delete (if that is allowed in your business requirement), and then commandLink/Button can call bean.deleteUsers(), and bean.deleteUsers, can delete selectedRows[] array.

The google searches above should show you my modified version of lazyDataModel, which addresses getRowData() and arithmetic by zero issues.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

rabathos
Posts: 2
Joined: 24 Mar 2012, 05:40

28 Mar 2012, 10:27

hi smithh032772,

Yes I know this reply came too late, but thanks anyways for replying to my post and sharing your ideas quickly last time. Looks like I asked the wrong question, or an incomplete one. What our project requirement actually wanted to do was to have the functionality to edit the user and also delete it from the lazy datatable... thus I can't move my commandLinks outside the datatable. That was why in my previous post, the delete commandLink was wrongly and strangely labeled as "Edit" :mrgreen:

By the way, in the past I also encountered the divide by zero exception but thankfully was able to solved it with the link you mentioned back then. Now I tried to fix this current problem of mine again and recently was able to make it work,, so um, would you or anyone like to see my changes?
Primefaces 3.2
Mojara 2.1.3
Tomcat 6.0.26

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

28 Mar 2012, 17:44

Please, always, reply with your changes, because someone else may benefit from your solution (or code changes). Thanks.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

monkalways
Posts: 1
Joined: 02 May 2012, 21:27

02 May 2012, 21:29

Encountered the same problem when having p:commandButton in a p:dataTable with LazyDataModel. Waiting for answers ...

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 52 guests