a4j:jsFunction with actionListener inside of h:dataTable
        Posted  
        
            by JQueryNeeded
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by JQueryNeeded
        
        
        
        Published on 2010-03-18T13:17:37Z
        Indexed on 
            2010/03/18
            13:21 UTC
        
        
        Read the original article
        Hit count: 1012
        
Hello all, I'm having problem with using a4j:jsFunction with actionListener inside of h:dataTable, when I want to invoke an action over particular row with a4j:commandLink it works flawless but when I want to invoke the action with a4j:jsFunction & actionListener it's always invoked over the last element in dataTable Let me give you an example:
    <a4j:form ajaxSubmit="true" reRender="mainForm" id="mainForm">
        <a4j:region>
            <t:saveState value="#{ts.list}" />
        </a4j:region>
        <h:dataTable value="#{ts.list}" var="el" binding="#{ts.bind}">
        <h:column>#{el}</h:column>>
        <h:column>
            <a4j:commandLink actionListener="#{ts.rem}">
                    <h:outputText value="delete by CMDLink" />
                </a4j:commandLink>
            </h:column>
        <h:column>
                <a href="#" onclick="okClicked();">delete by okClicked</a>
                <a4j:jsFunction name="okClicked"
                    actionListener="#{ts.rem}"
                />
        </h:column>
   </h:dataTable>
    </a4j:form>
now, the bean's code:
package com.sth;
import java.util.ArrayList;
import java.util.List;
import javax.faces.component.UIData;
import javax.faces.event.ActionEvent;
public class Ts {
    private List<String> list = new ArrayList<String>();
    private UIData bind;
    public Ts(){
        list.add("element1");
        list.add("element2");
        list.add("element3");
        list.add("element4");
    }
    public List<String> getList() {
        return list;
    }
    public void setList(List<String> list) {
        this.list = list;
    }
    public void rem(ActionEvent ae) {
        String toRem = (String) bind.getRowData();
        System.out.println("Deleting " + toRem);
        list.remove(toRem);
    }
    public UIData getBind() {
        return bind;
    }
    public void setBind(UIData bind) {
        this.bind = bind;
    }
}
when I use a4j:commandLink to remove element, it works as its expected, but when I use a4j:jsFunction to invoke actionListener it invokes action against last element :( Any ideas? Cheers
© Stack Overflow or respective owner