datatable pass parameter to action listener

UI Components for JSF
Post Reply
la.alberto
Posts: 2
Joined: 14 Apr 2012, 22:30

14 Apr 2012, 23:01

Hi.

I'm trying to implement data table with some actions on each row. It is very similar to this question viewtopic.php?f=3&t=19688

Code: Select all

<h:form id="userTableForm">
<p:dataTable id="userDataTable" var="user" value="#{userTable.users}" rows="10"
                             rowKey="#{user.userId}" selection="#{userTable.selectedUser}" selectionMode="single">
           <p:column headerText="ID">
                        <h:outputText value="#{user.userId}"/>
           </p:column>
           <p:column headerText="Actions">
                        <p:commandLink ajax="true" update=":userTableForm:userDataTable"
                                actionListener="#{userTable.disableUser(user.userId)}">
                            <h:graphicImage value="/images/user_blue_delete3.png" title="Disable" width="15" height="15"/>
                        </p:commandLink>
            </p:column>
</p:dataTable>
</h:form>
The problem is with actionListener attribute: Error Parsing: #{userTable.disableUser(user.userId)}. The only difference from that solved question which I mentioned is that I use commandLink instead of commandButton.

How can I solve this problem? Thank you.

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

15 Apr 2012, 01:17

p:commandLink works and p:commandButton not, right?
As you switched to commandLink, you didn't change anything else?
Can you try h:commandButton (ofc with p:ajax tag inside)?
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

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

15 Apr 2012, 15:22

Reply with your bean that is accessed by the following. So we can see what the bean is expecting.

Code: Select all

actionListener="#{userTable.disableUser(user.userId)}"
p:commandLink is working fine for me; as you can see below, I conditionally render p:commandLink if user prefers AJAX or not.

Code: Select all

<p:dataTable id="dt_rollingStockOrdersList" var="order" value="#{pf_ordersController.ordersList}" 
            paginator="true" paginatorAlwaysVisible="true" rows="100">

    <p:column headerText="Trip Date (From/To)">
        <p:commandLink rendered="#{pf_usersController.ajax}" update=":pageContentPanel"
                        actionListener="#{pf_ordersController.prepareViewFromRollingStock(order.orderId)}">
            <h:outputText escape="false" value="#{pf_ordersController.getTripDateDisplay(order)}" />
        </p:commandLink>
        <p:commandLink rendered="#{!pf_usersController.ajax}" ajax="false"
                        actionListener="#{pf_ordersController.prepareViewFromRollingStock(order.orderId)}">
            <h:outputText escape="false" value="#{pf_ordersController.getTripDateDisplay(order)}" />
        </p:commandLink>
    </p:column>
bean method referenced by p:commandLink

Code: Select all

    public String prepareViewFromRollingStock(Integer orderId) {
        current = null;
        try {
            current = getFacade().getOrder(orderId);
            if (current != null) {
                currentBankForBalance = current.getBankForBalanceId();
                currentBankForDeposit = current.getBankForDepositId();
                currentDetails = current.getDetailsId();
                currentNotes = current.getNotesId();
                currentRoutes = current.getRoutesId();
                browse = false;
                add = false;
                edit = false;
                view = true;
                viewToAdd = false;
                viewToEdit = false;
                getPageNavigation().setPage("/orders/pf_ViewOnlyFromRollingStock.xhtml");
            }
            else {
                messages.addFormErrorMsg("Error on attempt to view ORDERS data from ROLLING STOCK (orderId==null)", "");
            }
        } catch (Exception e) {
            e.printStackTrace();
            messages.addFormErrorMsg("Error retrieving ORDERS data to view from ROLLING STOCK", (e.getMessage() != null) ? e.getMessage() : "");
        }
        return null;
    }

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

la.alberto
Posts: 2
Joined: 14 Apr 2012, 22:30

15 Apr 2012, 15:59

Thank you. I found the problem, it was not in primefaces itself. I was trying to run my application on tomcat 6 and there is a problem with new el implementation(which is necessary to compile such expressions: #{userTable.disableUser(user.userId)}).

I used this post http://stackoverflow.com/questions/2333 ... cat-6-0-24, especially Lawrence McAlpin's reply (i don't know how to refer to specific answers on stackoverflow.com :( )

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 53 guests