4 Replies Latest reply on Jul 14, 2008 12:54 PM by Stephen More

    How to set HtmlActionParameter value dynamically?

    Marcelo Leiras Newbie

      I know how to set it in static way.


      <a4j:actionparam name="xxx" value="#{item.id}" assignTo="#{auditoria.idAuditoriaSelecionada}" />
      


      But it is not working dynamically

      HtmlActionParameter actionparam = new HtmlActionParameter();
      actionparam.setValueBinding("apName", application.createValueBinding("#{item.id}"));
      


      What is wrong in my code? Thanks.

        • 1. Re: How to set HtmlActionParameter value dynamically?
          Marcelo Leiras Newbie

          I change the static way to work with "bindind" instead "value", like this:

          <a4j:actionparam name="xxx" binding="#{item.id}" assignTo="#{auditoria.idAuditoriaSelecionada}" />
          


          and it keeps working with no problem. But the dynamic way is not working.

          HtmlActionParameter actionparam = new HtmlActionParameter();
          actionparam.setValueBinding("vb", application.createValueBinding("#{item.id}"));
          actionparam.setAssignToBinding(application.createValueBinding("#{origem.selectedId}"));
          


          The value assigned to "origem.selectedId" is always null.

          Could someone help please? Thanks a lot.

          • 2. Re: How to set HtmlActionParameter value dynamically?
            Marcelo Leiras Newbie

            I think the correct way is use the method "setValue" instead "setValueBinding", like the following code:

            actionparam.setValue("#{item.cnpj}");
            actionparam.setAssignToBinding(application.createValueBinding("#{origem.strTeste}"));
            


            but the value assigned to "origem.strTeste" is always the string "item.cnpj" when actually should be the content of the property called "cnpj". How can I do that?

            • 3. Re: How to set HtmlActionParameter value dynamically?
              Stephen More Newbie

              Have you gotten this to work yet ?

              I too am struggling with this problem.

              • 4. Re: How to set HtmlActionParameter value dynamically?
                Stephen More Newbie

                This seems to work for me:

                org.ajax4jsf.component.html.HtmlAjaxCommandLink link = new org.ajax4jsf.component.html.HtmlAjaxCommandLink();
                link.setId( "link" );
                javax.faces.component.html.HtmlOutputText title = new javax.faces.component.html.HtmlOutputText();
                title.setId( "title" );
                title.setValue( "My Link" );
                link.getChildren().add( title );
                
                org.ajax4jsf.component.html.HtmlActionParameter ap = new org.ajax4jsf.component.html.HtmlActionParameter();
                ap.setId( "param" );
                ap.setName( "username" );
                ap.setValue( "Alex" );
                javax.faces.application.Application application = context.getApplication();
                javax.el.ExpressionFactory ef = application.getExpressionFactory();
                javax.el.ValueExpression ve = ef.createValueExpression( context.getELContext(), "#{userBean.name}", UserBean.class );
                ap.setAssignToBinding( ve );
                
                link.getChildren().add( ap );
                
                link.addActionListener( ap );