13 Replies Latest reply on Mar 28, 2011 8:08 PM by Nick Belaevski

    Problem with a4j x custom components

    Jean Zimermann Newbie

      I've building a custom pager component extends UIComponentBase. It's works fine, but when add a4j:suport tag, to render a another component, it doesn't work.

       

      I atach component code files to this discussion, please i need to resolve this.

       

      The code bellow, calls the implementation:

       

      <f:view>   

       

              <h:form>         

                  <h:inputText value="#{dummy.atual}" id="xxx" />

                  <w:paginador count="#{dummy.count}" max="5" actual="#{dummy.atual}" executeSubmit="false">

                      <a4j:support event="onselect" reRender="xxx"></a4j:support>

                  </w:paginador>

              </h:form>   

       

          </f:view>

       

       

       

      Regards,

       

      Jean

        • 2. Problem with a4j x custom components
          Jay Balunas Master

          Hi Jean,

           

          Can you give some more information on your env, such as RichFaces version, JSF Impl, etc..?

           

          Thanks,

          Jay

          • 3. Problem with a4j x custom components
            Jean Zimermann Newbie

            Sure...

             

            JSF: 1.2

            RichFaces: 3.3.3

            JBoss: 4.3.3

            • 4. Problem with a4j x custom components
              Ilya Shaikovsky Master

              does just simple

               

                    <w:paginador count="#{dummy.count}" max="5" actual="#{dummy.atual}" executeSubmit="false" onselect="alert('working')">

               

              works for you? Probably just event handler not encoded/bound properly.

              • 5. Problem with a4j x custom components
                Jean Zimermann Newbie

                Really i'm not notifying events to jsf framework. How i do it?

                • 6. Problem with a4j x custom components
                  Jean Zimermann Newbie

                  I searched in the web and found some articles abount events, then i try to call method queueEvent in decode method od my render, but don't works. What is missing?

                   

                   

                   

                      @Override

                      public void decode(FacesContext context, UIComponent component) {

                          super.decode(context, component);

                          HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest();

                   

                          String clientId = component.getClientId(context);

                          String actual = request.getParameter(clientId + "_actual");

                   

                          if (component.getValueExpression("actual") != null) {

                              component.getValueExpression("actual").setValue(context.getELContext(), Integer.parseInt(actual));

                          }

                   

                          if (request.getParameter(clientId + "_onselect") != null) {

                              MethodExpression selectListener = ((Paginador)component).getSelectListener();

                              if (selectListener != null) {

                                  selectListener.invoke(context.getELContext(), new Object[] { component, "SelectEvent" });

                              }

                              component.queueEvent(new ActionEvent(component));

                          }

                      }

                  • 7. Problem with a4j x custom components
                    Nick Belaevski Master

                    Jean,

                     

                    You should render client-side event handlers such as onclick, onselect etc.

                    • 8. Problem with a4j x custom components
                      Jean Zimermann Newbie

                      Could you explain?

                      • 9. Problem with a4j x custom components
                        Nick Belaevski Master

                        Does this work as expected:

                         

                        onselect="alert('select')"?

                        • 10. Re: Problem with a4j x custom components
                          Jean Zimermann Newbie

                          Onselect works fine without a4j. I implemented support to onselect on my component. See the code attached in this thread.

                           

                          When I click on my pager component, it call a4j event, the event comes on the server, executes the decode method of my renderer, but do not call his endode methods. In other words, is like if it don't know which component to rerender. I could see other person with the same problem, but I can't any response.

                           

                          I tried to extend  UIInput component and HtmlBasicInputRenderer but I don't got success yet.

                          • 11. Problem with a4j x custom components
                            Nick Belaevski Master

                            Jean,

                             

                            Looked over the code - nothing suspicious. Can you please attach the whole project so that I check it at my side?

                            • 12. Problem with a4j x custom components
                              Jean Zimermann Newbie

                              Hi Nick

                               

                              I've attached all sources in this thread.

                              In last weekend I resolved my problem. I did this in validade method:

                               

                              if (oldValue != newValue) {

                                                            addComponentsToRender(context);

                                                            queueEvent(new ValueChangeEvent(this, oldValue, newValue));

                              }

                               

                              private void addComponentsToRender(FacesContext ctx) {

                                                  if (!executeSubmit && rerender != null) {

                                                            if (rerender.contains(",")) {

                                                                      String[] ids = rerender.split(",");

                                                                      for (int i = 0; i < ids.length; i++) {

                                                                                UIComponent cp = ctx.getViewRoot().findComponent(getCompleteName(ctx, ids[i]));

                                                                                if (cp != null) {

                                                                                          AjaxContext.getCurrentInstance().addComponentToAjaxRender(cp);

                                                                                }

                                                                      }

                                                            } else {

                                                                      UIComponent cp = ctx.getViewRoot().findComponent(getCompleteName(ctx, rerender));

                                                                      if (cp != null) {

                              AjaxContext.getCurrentInstance().addComponentToAjaxRender(cp);

                                                                      }

                                                            }

                               

                                                  }

                                        }

                               

                              I know which not is the wonderful soluction, but resolved my problem now. I hope this help other peoples with same problem.

                              • 13. Problem with a4j x custom components
                                Nick Belaevski Master

                                Jean,

                                 

                                This is the incorrect method that should be removed:

                                 

                                @Override

                                          public void setValueExpression(String arg0, ValueExpression arg1) {

                                                    super.setValueExpression(arg0, arg1);

                                                    if (arg1 != null) {

                                                              if (!arg1.isLiteralText()) {

                                                                        getAttributes().put(

                                                                                            arg0,

                                                                                            arg1.getValue(FacesContext.getCurrentInstance()

                                                                                                                .getELContext()));

                                                              }

                                                    }

                                          }