1 Reply Latest reply on Aug 1, 2011 10:42 AM by F M

    Adding a4j:param in an Handler doesn't work...

    F M Newbie

      Hi,

       

      I'm using Richfaces 4.0.0.Final, JSF 2.1.2 and EL 2.2.

       

      I'm trying to do something simple: create an handler which add a link with a a4j:param as child.

      But the setter method which should be called by the a4j:param is never called...

       

      Here is the code:

       

      public class TrucHandler extends TagHandler {
                public TrucHandler(final TagConfig poConfig) {
                     super(poConfig);
                }
                public void apply(final FaceletContext poCtx, final UIComponent poParent) {
                  try {
                      UICommandButton loLink = new UICommandButton();
                        loLink.setValue("Truc");
                        loLink.setRender("someId");
      
                        UIParameter loA4jParam = new UIParameter();
                        loA4jParam.setValue("aValue");
                        loA4jParam.setValueExpression("assignTo", FacesUtil.getValueExpression("#{myBean.myProperty}", Object.class));
                        loLink.getChildren().add(loA4jParam);
                        poParent.getChildren().add(loLink);
      
                  } catch (FacesException loE) {
                       throw loE;
                  }
                }
      }
      
      

       

      I added a breakpoint to the method AbstractParameter.processAction and it's never called !

       

      What am I missing ?

      Thanks in advance for any idea to go with...

       

      Florian

        • 1. Re: Adding a4j:param in an Handler doesn't work...
          F M Newbie

          Ok, JSF2 changed everything about Facelets TagHandlers, hence my code can't work as previously in JSF 1.2.

           

          Here is a code that's working for the same behavior:

           

           

          public class TrucHandler extends TagHandler {
                    public TrucHandler(final TagConfig poConfig) {
                              super(poConfig);
                    }
          
          
                    public void apply(final FaceletContext poCtx, final UIComponent poParent) {
                              try {
                                        if (!ComponentHandler.isNew(poParent)) {
                                                  return;
                                        }
          
                                        UICommandButton loLink = new UICommandButton();
                                        loLink.setId("truclink");
                                        loLink.setValue("Truc");
                                        loLink.setRender("someId");
          
                                        UIParameter loA4jParam = new UIParameter();
                                        loA4jParam.setId("param");
                                        loA4jParam.setValue("aValue");
                                        loA4jParam.setValueExpression("assignTo", FacesUtil.getValueExpression("#{myBean.myProperty}", Object.class));
                                        loLink.getChildren().add(loA4jParam);
          
                                        loLink.addActionListener(loA4jParam);
          
                                        poParent.getChildren().add(loLink);
                              } catch (FacesException loE) {
                                        throw loE;
                              }
                    }
          }
          
          

           

          The important idea is to define ids and to call the addActionListener which I found in the ParameterHandler class.

          The ComponentHandler.isNew is needed too otherwise the component gets generated twice in the view...

          It seems to work like this, the Event is created and treated by the processAction method.

           

          If someone has a correction to add, please feel free. If somebody has a way of learning this kind of things without debugging JSF and Richfaces sources, I'd be glad to hear from him !

           

          Florian