4 Replies Latest reply on Apr 14, 2011 12:00 PM by cmathrusse

    Problem with invokeOnComponent

    cmathrusse

      I'm usig RichFaces 4 and I'm having an issue invalidating a component and assigning a message to it. My code worked previously with RichFaces 4 M5, but now that I am using 4.0.0 final, it appears that it no longer works. It seems to be an issue with the ids of the components.

       

      Here is my Java code:

       

                                              final String resId = resourceId;

                                              final String compId = componentId;

                                              FacesContext context = FacesContext.getCurrentInstance();

                                              context.getViewRoot().invokeOnComponent(context, compId,

                                                                  new ContextCallback() {

       

                                         @Override

                                                                            public void invokeContextCallback(

                                                                                                FacesContext context, UIComponent component) {

                                                                                      ((UIInput) component).setValid(false);

       

                                                                                      FacesMessage message = new FacesMessage(

                                                                                                          MessageUtils.getString(resId));

                                                                                      context.addMessage(

                                                                                                          component.getClientId(context), message);

                                                                            }

                                                                  });

       

      The compId that I am supplying is the value of the form id and the actual component id concatinated together.

      (quote-only-form:cal-checkin-date)

       

      When the method invokeOnComponent is called, my callback is never invoked because the component Id cannot be located. I've setup a valueChangeListener on the component so I can see what the component clientId is and it has a value other than what I expected.

      (quote-only-form:j_idt57:cal-checkout-date)

       

      I don't know why the value is different than what it previously was or why there is now a j_idt57 in the clientId, but this seems to be preventing my callback from being invoked.

       

      Is there any reason why the clientId of the component would change like this or is there something that I am overlooking when calling invokeOnComponent?

       

      Thanks for the help...

        • 1. Problem with invokeOnComponent
          nbelaevski

          Hi Chris,

           

          Maybe you've placed 'cal-checkin-date' into composite component? This could change client id.

          • 2. Problem with invokeOnComponent
            cmathrusse

            Hi Nick,

             

            Yes, it is in a composite component. So if that makes the client id different, then how am I suppose to know what the client id is when I don't have the UIComponent available?

             

            The odd thing is that this worked previously. But since I upgraded to 4.0.0 Final it no longer works. (Although, to be fair, I also upgraded Glassfish to v3.1)

             

             

            Thanks for the assistance.

            • 3. Problem with invokeOnComponent
              nbelaevski

              Hi Chris,

               

              The best way is to use component.getClientId() method. Otherwise assign composite component ID and append it to clientId string.

              • 4. Problem with invokeOnComponent
                cmathrusse

                Hi Nick,

                 

                Yes, I know the best way is to call component.getClientId(), but in those situations when I don't have the component, how am I to know what the client id is? Can you give me an example of assigning a composite component ID and appending it to the clientId string?

                 

                Thanks...