2 Replies Latest reply on Nov 24, 2011 1:11 PM by Jorge Campos

    a4j:support with f:setPropertyActionListener

    Jorge Campos Newbie

      Hello,

       

      In my xhtml code I have this code:

       

       

      <rich:suggestion .... >
      
        <a4j:support event="onchange" immediate="true"
                ignoreDupResponses="true" eventsQueue="compQueue"
                requestDelay="500" limitToList="true" reRender="field"
                action="#{componentBean.findByKey}" ajaxSingle="true">
      
      
           <f:setPropertyActionListener target="#{componentBean.valueId}"
                     value="#{someOtherBean.valueId}" />
      
           <!-- -99999 represents null value -->
           <a4j:actionparam noEscape="true"
                     value="jQuery(this).val() == '' ? '-99999' : jQuery(this).val()"
                     assignTo="#{componentBean.valueId}" />
      
        </a4j:support>
      
      </rich:suggestion>
      

       

       

      I need to create the suggestion via java wich would be like this:

       

       

      HtmlSuggestionBox campoSuggestion = new HtmlSuggestionBox();
      campoSuggestion.setId("sugg" + parametro.getNome());
      campoSuggestion.setVar( "_var" + parametro.getNome() );
      campoSuggestion.setWidth("350");
      campoSuggestion.setHeight("300");
      campoSuggestion.setFor( "desc" + parametro.getNome() );
      campoSuggestion.setNothingLabel("Nenhum registro encontrado.");
      campoSuggestion.setFrequency(0.1);
      campoSuggestion.setMinChars("3");
      campoSuggestion.setRequestDelay(600);
      
      ExpressionFactory expressionFactory = context.getApplication().getExpressionFactory();
      ELContext elCtx = context.getELContext();
      
      MethodExpression me = expressionFactory.createMethodExpression(elCtx, 
                "#{someBean.autoComplete}", List.class, 
                          new Class[]{Object.class});
      
      campoSuggestion.setSuggestionAction(me);
      
      HtmlAjaxSupport a4jSuggestion = new HtmlAjaxSupport();
      
      a4jSuggestion.setId( "a4jSugg" + campoSuggestion.getId() );
      a4jSuggestion.setEvent("onchange");
      a4jSuggestion.setLimitToList(true); 
      a4jSuggestion.setAjaxSingle(true);
      a4jSuggestion.setRequestDelay(200);
      
      HtmlActionParameter param = new HtmlActionParameter();
      param.setId("param"+campoSuggestion.getId());
      param.setValue("jQuery(this).val() == '' ? '-99999' : jQuery(this).val()");
      param.setName("suggACT"+parametro.getNome());
      ValueExpression valorExpressparamSugg = expressionFactory
                               .createValueExpression( elCtx, 
                                "#{someBean.paramComponentes['desc" + parametro.getNome() + "']}", String.class);
      param.setAssignToBinding(valorExpressparamSugg);
      
      
      a4jSuggestion.getChildren().add(param);
      
      //how to add f:setPropertyActionListener?????
      
      

       

      Here I'm stuck, how can I add the f:setPropertyActionListener ??? Or something that works right exactly it ?!

       

      Thanks in advance

        • 2. Re: a4j:support with f:setPropertyActionListener
          Jorge Campos Newbie

          Hello Guys I've found out this a little time ago and forgotten to answer here! So...

           

          the way to do this: //how to add f:setPropertyActionListener????

          is:

            ValueExpression vlTarget = context.getApplication().getExpressionFactory()

                                        .createValueExpression( context.getELContext(), "#{genericSuggestionBean.panelId}", String.class);

                              

                              ValueExpression vlProperty = context.getApplication().getExpressionFactory()

                                        .createValueExpression( context.getELContext(), "someidpanel", String.class);

           

          a4jSupportOnchange.addActionListener( SetPropertyActionListenerImpl(vlTarget,vlProperty)  );

           

          works like a charm! in fact I've create a method to do this, wich is

           

          private SetPropertyActionListenerImpl createListener( String target, String property ){

                              ValueExpression vlTarget = context.getApplication().getExpressionFactory()

                                        .createValueExpression( context.getELContext(), target, String.class);

                              

                              ValueExpression vlProperty = context.getApplication().getExpressionFactory()

                                        .createValueExpression( context.getELContext(), property, String.class);

                              

                              return new SetPropertyActionListenerImpl(vlTarget,vlProperty);

                    }