1 2 Previous Next 16 Replies Latest reply on Aug 16, 2007 11:07 AM by Jose Miguel Loor

    Dinamic a4j:commandLink not working

    Jose Miguel Loor Apprentice

      Hi

      Hi created some a4j:commandLinks inside an a4j:repeater; theese commandLinks have an action and actionListener method declared

      But the thing is that the code asociated to the actionListener or action is never triggered

      This is my jsf relevant code:

      <a4j:form id="headForm">
      <a4j:commandLink id="companyCommandLink" value="#{userDataManager.compania.nombre}"
       action="#{headManager.commandAction}"
       actionListener="#{headManager.commandActionListener}" reRender="selectPanel" />
      <a4j:commandLink id="agencyCommandLink" value="#{userDataManager.usuarioCentro.agencia.nombre}"
       action="#{headManager.commandAction}"
       actionListener="#{headManager.commandActionListener}" reRender="selectPanel" />
      <a4j:outputPanel id="selectPanel" layout="block" style="float:left;margin-top:5px;margin-left:5px;width:200px;">
      <a4j:repeat id="selectDataList" binding="#{headManager.selectDataList}"
       value="#{headManager.valueList}" var="item" ajaxKeys="#{headManager.keys}">
      <a4j:commandLink id="selectCommandLink" binding="#{headManager.selectCommandLink}" value="#{item.value}"
       action="#{headManager.selectAction}" actionListener="#{headManager.selectActionListener}"
       styleClass="headerSelectLink" reRender="companyCommandLink,agencyCommandLink" />
      </a4j:repeat>
      </a4j:outputPanel>
      </a4j:form>
      

      I am not sure if the source code of selectActionListener or selectAction methods are relevant here; they only get some data from a list and place it in the session

      thanks

        • 1. Re: Dinamic a4j:commandLink not working
          Sergey Smirnov Master

          This was a bug of 1.1.0.
          Take Ajax4jsf 1.1.1-snapshot and test with it.

          • 2. Re: Dinamic a4j:commandLink not working
            Jose Miguel Loor Apprentice

            Hi Sergey:

            I downloaded the ajax4jsf-1.1.1-SNAPSHOT.jar, richfaces-3.0.1-SNAPSHOT.jar and oscache-2.3.2.jar (the snapshots are from six weeks ago) but still no go; the action and actionListener methods are not triggered

            This is the output of the a4j:log:

            debug[18:06:34,984]: Have Event [object Object] with properties: target: http://localhost:8080/administracion/faces/jsp/main/head.jsp#,
            srcElement: undefined, type: click
            debug[18:06:35,000]: NEW AJAX REQUEST !!! with form :headForm
            debug[18:06:35,000]: parameter headForm:selectDataList:2:selectCommandLink with value headForm:selectDataList:2:selectCommandLink
            debug[18:06:35,015]: Start XmlHttpRequest
            debug[18:06:35,015]: Reqest state : 1
            debug[18:06:35,015]: QueryString: AJAXREQUEST=_viewRoot&headForm=headForm&autoScroll=
            &headForm%3A_idcl=&headForm%3A_link_hidden_=
            &jsf_tree_64=rO0ABXNyweHg%3D
            &jsf_viewid=%2Fjsp%2Fmain%2Fhead.jsp
            &headForm%3AselectDataList%3A2%3AselectCommandLink=headForm
            %3AselectDataList%3A2%3AselectCommandLink&
            debug[18:06:35,015]: Reqest state : 1
            debug[18:06:35,140]: Reqest state : 2
            debug[18:06:35,140]: Reqest state : 3
            debug[18:06:35,140]: Reqest state : 3
            debug[18:06:35,140]: Reqest state : 3
            debug[18:06:35,140]: Reqest state : 3
            debug[18:06:35,156]: Reqest state : 4
            debug[18:06:35,156]: Reqest end with state 4
            debug[18:06:35,156]: Response with content-type: text/xml;charset=UTF-8
            debug[18:06:35,156]: Full response content: <?xml version="1.0"?>
            debug[18:06:35,156]: Header Ajax-Update-Ids not found, search in
            debug[18:06:35,156]: search for elements by name 'meta' in element #document
            debug[18:06:35,156]: getElementsByTagName found 2
            debug[18:06:35,156]: Find
            warn[18:06:35,156]: No information in response about elements to replace
            debug[18:06:35,156]: call getElementById for id= ajax-update-ids
            debug[18:06:35,156]: Hidden JSF state fields: [object HTMLSpanElement]
            debug[18:06:35,156]: search for elements by name 'input' in element span
            debug[18:06:35,156]: getElementsByTagName found 3
            debug[18:06:35,156]: Replace value for inputs: 7 by new values: 3
            debug[18:06:35,156]: Input in response: jsf_tree_64
            debug[18:06:35,171]: Found same input on page with type: hidden
            debug[18:06:35,171]: Input in response: jsf_state_64
            debug[18:06:35,171]: Found same input on page with type: hidden
            debug[18:06:35,171]: Input in response: jsf_viewid
            debug[18:06:35,171]: Found same input on page with type: hidden
            debug[18:06:35,171]: search for elements by name 'INPUT' in element span
            debug[18:06:35,171]: getElementsByTagName found 0
            debug[18:06:35,171]: Replace value for inputs: 7 by new values: 0
            debug[18:06:35,171]: Call request oncomplete function after processing updates
            debug[18:06:35,234]: call getElementById for id= _ajax:data

            can it be some other library that i am missing ??

            i also have tomahawk-1.1.5.jar in my classpath

            thanks

            • 4. Re: Dinamic a4j:commandLink not working
              Jose Miguel Loor Apprentice

              where can i get a latest snapshot

              • 6. Re: Dinamic a4j:commandLink not working
                Jose Miguel Loor Apprentice

                ok, i replaced the snapshot jars with the most recent from the repository and still i have the same problem

                I replaced the a4j:form with h:form and dynamically created a4j:commandLink with h:commandLink and nothing

                any other suggestion ???


                thanks

                • 7. Re: Dinamic a4j:commandLink not working
                  Sergey Smirnov Master

                  do you have a small application where the problem is reproducible?

                  • 8. Re: Dinamic a4j:commandLink not working
                    Jose Miguel Loor Apprentice

                    Hi, i have prepared a little application reproducing the error

                    I will place the code, if you have an e-mail where i can send you a war with both the classes and source code, i will send you:

                    Controls.jsp:

                    <%@page contentType="text/html"%>
                    <%@page pageEncoding="UTF-8"%>
                    <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
                    <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
                    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                    <f:view>
                     <html xmlns="http://www.w3.org/1999/xhtml">
                     <head>
                     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                     <a4j:loadStyle src="/css/global.css"/>
                     </head>
                     <body>
                     <a4j:form id="headForm">
                     <div id="infoBarContainer">
                     <div id="infoBarContent">
                     <a4j:outputPanel id="companyOutputPanel" layout="inline" styleClass="linePanel">
                     <a4j:commandLink id="companyCommandLink" value="#{dataManager.selectedCompany.desc}"
                     action="#{dataManager.commandAction}" actionListener="#{dataManager.commandActionListener}"
                     reRender="selectPanel" />
                     </a4j:outputPanel>
                     <a4j:outputPanel id="agencyOutputPanel" layout="inline" styleClass="linePanel">
                     <a4j:commandLink id="agencyCommandLink" value="#{dataManager.selectedAgency.desc}"
                     action="#{dataManager.commandAction}" actionListener="#{dataManager.commandActionListener}"
                     reRender="selectPanel" />
                     </a4j:outputPanel>
                     </div>
                     </div>
                     <a4j:outputPanel id="selectPanel" layout="block"
                     style="float:left;margin-top:5px;margin-left:5px;width:200px;">
                     <a4j:repeat id="selectDataList" binding="#{dataManager.selectDataList}"
                     value="#{dataManager.selectData}" var="item" ajaxKeys="#{dataManager.keys}">
                     <a4j:commandLink id="selectCommandLink"
                     value="#{item.desc}" action="#{dataManager.selectAction}"
                     actionListener="#{dataManager.selectActionListener}"
                     reRender="companyOutputPanel,agencyOutputPanel" style="display:block" />
                     </a4j:repeat>
                     </a4j:outputPanel>
                     </a4j:form>
                     </body>
                     </html>
                    </f:view>
                    


                    ControlBackingBean.java
                    package control.test;
                    
                    import java.util.ArrayList;
                    import java.util.HashSet;
                    import java.util.List;
                    import java.util.Set;
                    import javax.faces.event.ActionEvent;
                    import org.ajax4jsf.ajax.html.HtmlAjaxRepeat;
                    
                    /**
                     *
                     * @author Administrador
                     */
                    public class ControlBackingBean {
                    
                     private List<Data> companyData;
                    
                     private List<Data> agencyData;
                    
                     private List<Data> selectData;
                    
                     private Data selectedCompany;
                    
                     private Data selectedAgency;
                    
                     private HtmlAjaxRepeat selectDataList = new HtmlAjaxRepeat();
                    
                     private Set<Integer> keys;
                    
                     /** Creates a new instance of ControlBackingBean */
                     public ControlBackingBean() {
                     setCompanyData(new ArrayList<Data>());
                     getCompanyData().add(new Data("01","Company 01"));
                     getCompanyData().add(new Data("02","Company 02"));
                     getCompanyData().add(new Data("03","Company 03"));
                    
                     setSelectedCompany(getCompanyData().get(0));
                    
                     setAgencyData(new ArrayList<Data>());
                     getAgencyData().add(new Data("04","Agency 01"));
                     getAgencyData().add(new Data("05","Agency 02"));
                     getAgencyData().add(new Data("06","Agency 03"));
                    
                     setSelectedAgency(getAgencyData().get(0));
                     }
                    
                     public String commandAction() {
                     System.out.println("<<< commandAction >>>");
                     return null;
                     }
                    
                     public void commandActionListener(ActionEvent event) {
                     setSelectData(new ArrayList<Data>());
                     setKeys(new HashSet<Integer>());
                     String component = event.getComponent().getId();
                     if (component.indexOf("company") >= 0) {
                     setSelectData(this.companyData);
                     } else {
                     setSelectData(this.agencyData);
                     }
                    
                     for (int i=0; i < getSelectData().size(); i++) {
                     getKeys().add(i);
                     }
                     }
                    
                     public String selectAction() {
                     System.out.println("<<< selectAction >>>");
                     return null;
                     }
                    
                     public void selectActionListener(ActionEvent event) {
                     System.out.println("<<< selectActionListener >>>");
                     }
                    
                     public List<Data> getCompanyData() {
                     return companyData;
                     }
                    
                     public void setCompanyData(List<Data> companyData) {
                     this.companyData = companyData;
                     }
                    
                     public List<Data> getAgencyData() {
                     return agencyData;
                     }
                    
                     public void setAgencyData(List<Data> agencyData) {
                     this.agencyData = agencyData;
                     }
                    
                     public Data getSelectedCompany() {
                     return selectedCompany;
                     }
                    
                     public void setSelectedCompany(Data selectedCompany) {
                     this.selectedCompany = selectedCompany;
                     }
                    
                     public Data getSelectedAgency() {
                     return selectedAgency;
                     }
                    
                     public void setSelectedAgency(Data selectedAgency) {
                     this.selectedAgency = selectedAgency;
                     }
                    
                     public HtmlAjaxRepeat getSelectDataList() {
                     return selectDataList;
                     }
                    
                     public void setSelectDataList(HtmlAjaxRepeat selectDataList) {
                     this.selectDataList = selectDataList;
                     }
                    
                     public Set<Integer> getKeys() {
                     return keys;
                     }
                    
                     public void setKeys(Set<Integer> keys) {
                     this.keys = keys;
                     }
                    
                     public List<Data> getSelectData() {
                     return selectData;
                     }
                    
                     public void setSelectData(List<Data> selectData) {
                     this.selectData = selectData;
                     }
                    
                    }
                    


                    Data.java
                    package control.test;
                    
                    /**
                     *
                     * @author Administrador
                     */
                    public class Data {
                    
                     private String code;
                     private String desc;
                    
                     public Data(String code, String desc) {
                     this.code = code;
                     this.desc = desc;
                     }
                    
                     public String getCode() {
                     return code;
                     }
                    
                     public void setCode(String code) {
                     this.code = code;
                     }
                    
                     public String getDesc() {
                     return desc;
                     }
                    
                     public void setDesc(String desc) {
                     this.desc = desc;
                     }
                    
                    }
                    


                    web.xml
                    <?xml version="1.0" encoding="UTF-8"?>
                    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
                     <context-param>
                     <param-name>com.sun.faces.verifyObjects</param-name>
                     <param-value>false</param-value>
                     </context-param>
                     <context-param>
                     <param-name>com.sun.faces.validateXml</param-name>
                     <param-value>true</param-value>
                     </context-param>
                     <context-param>
                     <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
                     <param-value>client</param-value>
                     </context-param>
                     <context-param>
                     <param-name>org.ajax4jsf.SKIN</param-name>
                     <param-value>default</param-value>
                     </context-param>
                     <listener>
                     <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
                     </listener>
                     <servlet>
                     <servlet-name>Faces Servlet</servlet-name>
                     <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
                     <load-on-startup>1</load-on-startup>
                     </servlet>
                     <servlet-mapping>
                     <servlet-name>Faces Servlet</servlet-name>
                     <url-pattern>/faces/*</url-pattern>
                     </servlet-mapping>
                     <filter>
                     <display-name>Ajax4jsf Filter</display-name>
                     <filter-name>ajax4jsf</filter-name>
                     <filter-class>org.ajax4jsf.Filter</filter-class>
                     </filter>
                     <filter-mapping>
                     <filter-name>ajax4jsf</filter-name>
                     <servlet-name>Faces Servlet</servlet-name>
                     <dispatcher>REQUEST</dispatcher>
                     <dispatcher>FORWARD</dispatcher>
                     <dispatcher>INCLUDE</dispatcher>
                     </filter-mapping>
                     <session-config>
                     <session-timeout>
                     30
                     </session-timeout>
                     </session-config>
                     <welcome-file-list>
                     <welcome-file>
                     index.jsp
                     </welcome-file>
                     </welcome-file-list>
                    </web-app>
                    


                    faces-config.xml
                    <?xml version='1.0' encoding='UTF-8'?>
                    
                    
                    <!DOCTYPE faces-config PUBLIC
                     "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
                     "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
                    
                    <!-- =========== FULL CONFIGURATION FILE ================================== -->
                    
                    <faces-config>
                     <managed-bean>
                     <managed-bean-name>dataManager</managed-bean-name>
                     <managed-bean-class>control.test.ControlBackingBean</managed-bean-class>
                     <managed-bean-scope>request</managed-bean-scope>
                     </managed-bean>
                    </faces-config>
                    
                    


                    Libraries included:

                    ajax4jsf-1.1.1-SNAPSHOT.jar
                    oscache-2.3.2.jar
                    richfaces-3.0.1-SNAPSHOT.jar
                    tomahawk-1.1.5.jar

                    Thanks a lot for your time

                    • 9. Re: Dinamic a4j:commandLink not working
                      Jose Miguel Loor Apprentice

                      Ok, here is the code of the page, Controls.jsp

                      <%@page contentType="text/html"%>
                      <%@page pageEncoding="UTF-8"%>
                      <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
                      <%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich"%>
                      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
                      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
                      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                      <f:view>
                       <html xmlns="http://www.w3.org/1999/xhtml">
                       <head>
                       <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
                       <a4j:loadStyle src="/css/global.css"/>
                       </head>
                       <body>
                       <a4j:form id="headForm">
                       <div id="infoBarContainer">
                       <div id="infoBarContent">
                       <a4j:outputPanel id="companyOutputPanel" layout="inline" styleClass="linePanel">
                       <a4j:commandLink id="companyCommandLink" value="#{dataManager.selectedCompany.desc}"
                       action="#{dataManager.commandAction}" actionListener="#{dataManager.commandActionListener}"
                       reRender="selectPanel" />
                       </a4j:outputPanel>
                       <a4j:outputPanel id="agencyOutputPanel" layout="inline" styleClass="linePanel">
                       <a4j:commandLink id="agencyCommandLink" value="#{dataManager.selectedAgency.desc}"
                       action="#{dataManager.commandAction}" actionListener="#{dataManager.commandActionListener}"
                       reRender="selectPanel" />
                       </a4j:outputPanel>
                       </div>
                       </div>
                       <a4j:outputPanel id="selectPanel" layout="block" style="float:left;margin-top:5px;margin-left:5px;width:200px;">
                       <a4j:repeat id="selectDataList" binding="#{dataManager.selectDataList}"
                       value="#{dataManager.selectData}" var="item"
                       ajaxKeys="#{dataManager.keys}">
                       <a4j:commandLink id="selectCommandLink" value="#{item.desc}" action="#{dataManager.selectAction}"
                       actionListener="#{dataManager.selectActionListener}"
                       reRender="companyOutputPanel,agencyOutputPanel" style="display:block" />
                       </a4j:repeat>
                       </a4j:outputPanel>
                       </a4j:form>
                       </body>
                       </html>
                      </f:view>
                      


                      • 12. Re: Dinamic a4j:commandLink not working
                        Jose Miguel Loor Apprentice

                        this is the response in the Jira site about this matter:

                        Alexander Smirnov [03/May/07 07:54 PM]
                        This is not a ajax4jsf bug, but only incorrect use of a request-scope bin.
                        On decode phase, you bean dont't yet populate, and data for a repeat component is null.

                        so, how do i fix this, the response doesn't give any hints about how to make my application work

                        thanks a lot

                        • 13. Re: Dinamic a4j:commandLink not working
                          Jose Miguel Loor Apprentice

                          the same thing applies when i create a commandLink in a table, i assume this is because is based on the same repeater component

                          • 14. Re: Dinamic a4j:commandLink not working
                            Nikita Leonov Newbie

                            Also have same problem with dataTable. The action and actionListener doesn't work from dataTable but the same button works perfectly outside the dataTable. Is there any fix or clear explanation why such situation happens? Decription given in jira for this bug is not clear for me.

                            1 2 Previous Next