8 Replies Latest reply on Jun 18, 2009 12:50 PM by fil78

    a4j:support dynamic creation issue

      Hi folks,
      I am trying to create my own tag using facelets. It consists of jsf input field, listbox and rich button. Besides that I would like to add a4j:support so - here is the code snippets:

      public class MySwitcher extends javax.faces.component.html.HtmlInputText{


      a4j support:

      private HtmlAjaxSupport addAjaxSupport(FacesContext context){
       HtmlAjaxSupport ajaxSupport = new HtmlAjaxSupport();
       ajaxSupport.setEvent("onkeyup");
       ajaxSupport.setReRender(getClientId(context) + "," + LIST_BOX);
       ajaxSupport.setEventsQueue(eventsQueue);
       return ajaxSupport;
       }


      inserting:

      @Override
       public void encodeBegin(FacesContext context) throws IOException {
       ResponseWriter writer = context.getResponseWriter();
       writer.startElement("div", null);
       super.encodeBegin(context);
       this.getFacets().put("ajaxSupport", addAjaxSupport(context));
       }

      Finally html code looks incomplete:

      onkeyup="A4J.AJAX.Submit('_viewRoot','my_main_form',event,{'similarityGroupingId':'my_main_form:j_id115','parameters':{'my_main_form:j_id115':'my_main_form:j_id115'} ,'actionUrl':'/root/camps/location/mySwitcherTest.xhtml'} )"

      but as I understand to reRender components 'affected' should presents.. What could be the problem?
      Thanks.


        • 1. Re: a4j:support dynamic creation issue

          Hey folks, does anybody know the answer? I do need help...

          • 2. Re: a4j:support dynamic creation issue
            nbelaevski

            Hi,

            What is "affected" you are referring to?

            • 3. Re: a4j:support dynamic creation issue

              Hi,
              I mean generated javascript code.. I checked correctly working code and found out that there is something like 'affected':['form_id:field1_id','form_id:fild2_id'] presents.. It is clear that all field id's to rerender listed there. I do not know why in my case it is not generated although I do ajaxSupport.setReRender(getClientId(context) + "," + LIST_BOX). Could you give me a hint? Thanks.

              • 4. Re: a4j:support dynamic creation issue
                nbelaevski

                Well, I'm checking out: http://livedemo.exadel.com/richfaces-demo/richfaces/commandLink.jsf?c=commandLink&tab=usage. Here is "onclick" handler code copied from Firebug:

                A4J.AJAX.Submit('_viewRoot','j_id353',event,{'parameters':{'j_id353:j_id357':'j_id353:j_id357'} ,'actionUrl':'/richfaces\x2Ddemo/richfaces/commandLink.jsf','similarityGroupingId':'j_id353:j_id357'} );return false;
                - no "affected" are present. Definitely, there was a case when "affected" was used, however I can't remember what case produced such code (maybe limitToList usage?). Also note that reRender list can be a dynamic list created on the server; so "affected" is not necessary on the client side at all.

                Try assigning this:
                AjaxRendererUtils.asSet("...ids to reRender")
                as the value of "reRender" attribute.

                • 5. Re: a4j:support dynamic creation issue

                  Thanks Nick, I checked the livedemo - it is true that no ids to rerender are mentioned in the generated AJAX.Submit code..
                  Regarding AjaxRendererUtils.asSet - it would not work..
                  Could it be the problem that I combined 3 components programmatically (HtmlSelectOneListbox and HtmlButton added after super.encodeEnd) and inherited from javax.faces.component.html.HtmlInputText? or
                  Could it be the problem that I am trying to reRender component itself?
                  but everytime when onkeyup fires encodeBegin and encodeEnd properly invokes... and no changes on UI..((

                  • 6. Re: a4j:support dynamic creation issue

                    Hi,
                    I fixed this issue - I just placed my component on the a4j panel.. But now I've got another question. I am implementing something like a search button and I want just to reRender part of a page without any action invoking. So I am trying to do something like:

                     HtmlAjaxCommandButton searchButton = new HtmlAjaxCommandButton();
                     searchButton.setId("ajButton");
                     searchButton.setStyleClass(STYLE_SEARCH_BUTTON);
                     String action = "";
                     ExpressionFactory factory = context.getApplication().getExpressionFactory();
                     MethodExpression methodExpression = factory.createMethodExpression(context.getELContext(), action, null, new Class<?>[0]);
                     searchButton.setActionExpression(methodExpression);
                     searchButton.setImage("/images/searchFieldBtn.gif");
                     searchButton.setReRender(AjaxRendererUtils.asSet(getClientId(context) + "," + LIST_BOX + "," + getReRender()));
                     searchButton.setEventsQueue(eventsQueue);
                     searchButton.setActionExpression(actionExpression);
                     searchButton.encodeAll(context);
                    

                    But it generates an exception.. If I put:
                    String action = "dummyString";

                    It invokes something like an ajax request because a4j status triggers, but it does not reRender the page at all. what is the best practice just to reRender a piece of page without invoking actions? What am I doing wrong?

                    • 7. Re: a4j:support dynamic creation issue

                      Hey folks, do not be shy to answer, please..

                      • 8. Re: a4j:support dynamic creation issue

                        All was fixed by:

                         UIComponent form = getCurrentForm(this);
                         if (form != null) {
                         form.getChildren().add(searchButton);
                         }
                        

                        Thanks..