8 Replies Latest reply on May 7, 2007 4:38 AM by Juan Ignacio Sánchez Lara

    My java-created HtmlAjaxCommandLink won't render rerender

    Juan Ignacio Sánchez Lara Apprentice

      I'm trying to build a custom component composed mainly of two HtmlAjaxCommandLink.

      This is a working a4j:commandLink:

      <a4j:commandLink
       actionListener='#{convocatoriaPaginadorBean.resetDataScroller}'
       reRender="convocatoriasRiFa,convocatoriasRiFaScroller">
      
       <a4j:actionparam name="sortBy" value="tituloAsc"
       assignTo="#{convocatoriasPaginadorDataModel.filtro.orden.propiedadOrden}" />
      
       <h:outputText value="#{msg.campo_titulo}" />
      
      </a4j:commandLink>
      


      And this is the code that I'm trying to replicate it with:
      Application application = context.getCurrentInstance().getApplication();
      HtmlAjaxCommandLink enlace = new HtmlAjaxCommandLink();
      
      final String actionListener = (String) getValueBinding("actionListener").getExpressionString();
      final Class[] params = new Class[]{ ActionEvent.class };
      enlace.setActionListener(application.createMethodBinding(actionListener, params));
      
      enlace.setReRender((String) getAttributes().get("reRender"));
      /** AT THIS POINT ENLACE DOES HAVE THE PARAM ASSIGNED */
      enlace.setId(((String) getAttributes().get("id"))+"enlace");
      
      UIActionParameter actionParameter = new UIActionParameter();
      actionParameter.setName("sortBy");
      actionParameter.setValue((String) getAttributes().get("propiedad")+"Asc");
      actionParameter.setAssignToBinding(getValueBinding("asignarA"));
      enlace.getChildren().add(actionParameter);
      
      UIOutput texto = new UIOutput();
      texto.setValue((String) getValueBinding("texto").getValue(context));
      enlace.getChildren().add(texto);
      
      enlace.encodeBegin(context);
      enlace.encodeChildren(context);
      enlace.encodeEnd(context);
      


      As I say at the code comment, reRender property is setted ("convocatoriasRiFa,convocatoriasRiFaScroller").

      This is the output of the working link:
      <a onclick="A4J.AJAX.Submit('_viewRoot','paginadorConvocatoriasForm',event,{'parameters':{'sortBy':'tituloAsc','paginadorConvocatoriasForm:convocatoriasRiFa:_idJsp7':'paginadorConvocatoriasForm:convocatoriasRiFa:_idJsp7'} ,'actionUrl':'/gnomos/convocatorias/verConvocatorias.jsf;jsessionid=55c6ccd99504bffffffffaf211589b6c84a1'} );return false;" name="paginadorConvocatoriasForm:convocatoriasRiFa:_idJsp7" id="paginadorConvocatoriasForm:convocatoriasRiFa:_idJsp7" href="#">Título</a>
      


      Nevertheless, this is the output of the not working java link:
      <a id="_idJsp10enlace" onclick="A4J.AJAX.Submit('_viewRoot',null,event,{'parameters':{'_idJsp10enlace':'_idJsp10enlace','sortBy':'tituloAsc'} ,'actionUrl':'/gnomos/convocatorias/verConvocatorias.jsf;jsessionid=55c6ccd99504bffffffffaf211589b6c84a1'} );return false;" name="_idJsp10enlace" href="#">Título</a>
      


      As you can see, it doesn't have the reRerender ids.

      What am I missing?

        • 1. Re: My java-created HtmlAjaxCommandLink won't render rerende
          Juan Ignacio Sánchez Lara Apprentice

          I've done an improvement?

          I've changed

          enlace.setReRender((String) getAttributes().get("reRender"));


          for

          enlace.setReRender( AjaxRendererUtils.asSet((String) getAttributes().get("reRender")));


          reRender property at the link is no longer a String but a HashMap, but it still outputs the same html :-\

          • 2. Re: My java-created HtmlAjaxCommandLink won't render rerende
            Juan Ignacio Sánchez Lara Apprentice

            I've added

            enlace.setLimitToList(true);

            and now it does render, at least,
            (...)'affected':['convocatoriasRiFaScroller','convocatoriasRiFa'](...)
            

            It's not the same as reRender but it might do the trick... It doesn't work, either, but there're two error messages at log:

            (...)
            debug[12:44:30,717]: Full response content: <?xml version="1.0"?> <html lang="es" xmlns="http://www.w3.org/1999/xhtml"><head><title></title><link type="text/css" rel="stylesheet" href="/gnomos/faces/a4j.res/css/table.xcss/DATA/eAFbJaehBAADeAET" /><link type="text/css" rel="stylesheet" href="/gnomos/faces/a4j.res/css/datascroller.xcss/DATA/eAFbJaehBAADeAET" /><script type="text/javascript" src="/gnomos/faces/a4j.res/org.ajax4jsf.framework.ajax.AjaxScript"> </script><script type="text/javascript" src="/gnomos/faces/a4j.res/org.ajax4jsf.framework.resource.PrototypeScript"> </script></head><body><span id="paginadorConvocatoriasForm:_idJsp0"></span><meta name="Ajax-Update-Ids" content="paginadorConvocatoriasForm:_idJsp0" /><span id="ajax-update-ids"><input type="hidden" name="jsf_sequence" value="12" /><input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="rO0ABXVyABNbTGphdmEubGFuZy5PYmplY3Q7kM5YnxBzKWwCAAB4cAAAAAN0AAIxMnB0ACMvY29udm9jYXRvcmlhcy92ZXJDb252b2NhdG9yaWFzLmpzcA==" /></span><meta id="Ajax-Response" name="Ajax-Response" content="true" /></body></html>
            debug[12:44:30,717]: search for elements by name 'script' in element #document
            debug[12:44:30,733]: getElementsByTagName found 2
            debug[12:44:30,733]: <script> in response with src=/gnomos/faces/a4j.res/org.ajax4jsf.framework.ajax.AjaxScript
            debug[12:44:30,733]: Such element exist in document
            debug[12:44:30,733]: <script> in response with src=/gnomos/faces/a4j.res/org.ajax4jsf.framework.resource.PrototypeScript
            debug[12:44:30,733]: Such element exist in document
            debug[12:44:30,733]: search for elements by name 'link' in element #document
            debug[12:44:30,748]: getElementsByTagName found 2
            debug[12:44:30,748]: <link> in response with src=/gnomos/faces/a4j.res/css/table.xcss/DATA/eAFbJaehBAADeAET
            debug[12:44:30,748]: Such element exist in document
            debug[12:44:30,748]: <link> in response with src=/gnomos/faces/a4j.res/css/datascroller.xcss/DATA/eAFbJaehBAADeAET
            debug[12:44:30,748]: Such element exist in document
            debug[12:44:30,748]: Update page part from call parameter for ID convocatoriasRiFaScroller
            debug[12:44:30,748]: call getElementById for id= convocatoriasRiFaScroller
            error[12:44:30,764]: New node for ID convocatoriasRiFaScroller is not present in response
            debug[12:44:30,764]: Update page part from call parameter for ID convocatoriasRiFa
            debug[12:44:30,764]: call getElementById for id= convocatoriasRiFa
            error[12:44:30,764]: New node for ID convocatoriasRiFa is not present in response
            debug[12:44:30,764]: call getElementById for id= ajax-update-ids
            (...)
            


            The response doesn't have any response content, so errors are quite obvious.

            actionListener isn't triggered, either.

            Any idea?

            • 3. Re: My java-created HtmlAjaxCommandLink won't render rerende
              Juan Ignacio Sánchez Lara Apprentice

              This post is turning into a "jira" of my problem...

              I've noticed the BIG difference between the working link and the not working one. This is the beginning of the log when you press the first (note the form):

              debug[12:52:59,926]: Have Event [object Object] with properties: target: undefined, srcElement: http://localhost:7575/gnomos/convocatorias/verConvocatorias.jsf#, type: click
              debug[12:52:59,926]: NEW AJAX REQUEST !!! with form :paginadorConvocatoriasForm
              


              And this is the beginning with the other:
              debug[12:55:26,528]: Have Event [object Object] with properties: target: undefined, srcElement: http://localhost:7575/gnomos/convocatorias/verConvocatorias.jsf#, type: click
              debug[12:55:26,528]: NEW AJAX REQUEST !!! with form :null
              


              How can I attach my component to the form?

              • 4. Re: My java-created HtmlAjaxCommandLink won't render rerende
                Juan Ignacio Sánchez Lara Apprentice

                Setting link's parent with enlace.setParent fixes the "with form :null" issue. Now it renders right message ("with form :paginadorConvocatoriasForm"), but it won't trigger actionListener nor rerender anything

                Help! :(

                • 5. Re: My java-created HtmlAjaxCommandLink won't render rerende
                  Juan Ignacio Sánchez Lara Apprentice

                  In fact, right now both links (working and not) displays just the same html (the only difference are the ids)!

                  :(

                  • 6. Re: My java-created HtmlAjaxCommandLink won't render rerende
                    Alexander Smirnov Master

                    actionParam really is combination for a UIParam and ActionListener.
                    In addition to getChildren().add(actionParameter) you need to call a enlace.addActionListener(actionParameter).

                    • 7. Re: My java-created HtmlAjaxCommandLink won't render rerende
                      Juan Ignacio Sánchez Lara Apprentice

                      I'm afraid it makes no difference. Full response content still comes with no page update, and actionListener is not invoked

                      • 8. Re: My java-created HtmlAjaxCommandLink won't render rerende
                        Juan Ignacio Sánchez Lara Apprentice

                        Ok, finally done!!

                        First of all, thank you, alex.

                        My mistake was code location. This is my first JSF component, so I followed the tipical tutorial which renders html tags in encodeBegin, so I placed object aggregation in it. This seems wrong. The right place to put upper code is in setProperties at custom tag class. Moving it there made this work.

                        Can you suggest me documentation which explains all this to me? I'm wrong following a try-and-error approach.