1 2 Previous Next 20 Replies Latest reply on Dec 26, 2010 1:43 PM by krbaburaj

    JSF Custom Component and ajax4jsf problem

    krbaburaj

      Hi,

      1) I have a custom component with 3 combobox(TimeField --> hour, minute, second)

      2) It is working fine

      3)  it is supposed to be worked in such a way that , ther is another  combobox as status --> when we select status combo.. the visibility  of the custome compoenent need to be changed

      4) i have given it inside the a4j support event= onchange

      5) But while rerendering its not calling the bean setter methods

      6) The file is attached along with this mail...

      7) This is a war file --> this can be directly deployed inside tomcat.. source is also packed

      8) URL  -->  http://localhost:5050/ajax/faces/index.jsp

       

      Please quote me whether anything is wrong with me

        • 1. Re: JSF Custom Component and ajax4jsf problem
          ilya_shaikovsky

          at first do not update conditionally rendered component itself. use it's parent update instead.

          • 2. Re: JSF Custom Component and ajax4jsf problem
            krbaburaj

            thanks Ilya for your reply....


            update conditionally rendered component itself

             

            The above line if u can make it a bit clear.. it will be more helpful

            • 3. Re: JSF Custom Component and ajax4jsf problem
              krbaburaj

              Ilya Shaikovsky wrote:

               

              at first do not update conditionally rendered component itself. use it's parent update instead.

              I didnt understand .... please explain a bit more

              • 4. Re: JSF Custom Component and ajax4jsf problem
                ilya40umov

                it means if your component(which you want to reRender) has an EL in rendered attribute. And you want it to apper/dissapper. You should use ID of its parent in reRender of your a4j:support. Like this

                <h:someTag>

                    <a4j:support reRender="wrapID">

                </h:someTag>

                <h:panelGroup id="wrapID">

                     <h:someComponentYouWishToDisapper rendered="#{el}"/>

                </h:panelGroup>

                • 5. Re: JSF Custom Component and ajax4jsf problem
                  krbaburaj

                  Hi Ilya.

                   

                  I have done exactly what you told. The war file i had attached contains all these details... its a small working test applpication

                  I was using panel grid as parent. I had tried it using panel group also, as shown below

                   

                  <h:panelGrid border="0" columns="1">
                              <h:selectOneMenu id="organizationNameId" value="#{dateTest.value}">
                                  <f:selectItems value="#{dateTest.nameItems}" />
                                  <a4j:support ajaxSingle="true" event="onchange"
                                      action="#{dateTest.handle }" reRender="x" />
                              </h:selectOneMenu>
                          </h:panelGrid>

                   


                          <h:panelGroup id="x">
                              <a:inputTime id="startTimeId" rendered="#{dateTest.three}"
                                  value="#{dateTest.time }"></a:inputTime>
                                  <h:inputText rendered="#{dateTest.three }"></h:inputText>
                          </h:panelGroup>

                   

                  here you can see the rendered value of both my component and inputText is same. inputText is switching fine.. but my component failed..

                   

                  Please help me, if i had to write anything more to my custom component for making it dynamically rendered

                  • 6. Re: JSF Custom Component and ajax4jsf problem
                    ilya40umov

                    1) look at this topic http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_support.html and try to use  valueChangeListener instead of using action="#{dateTest.handle }"
                    2) Show also code of DateTest bean

                    1) look at this topic http://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/a4j_support.html and try to use  valueChangeListener instead of using action="#{dateTest.handle }"

                    2) Show also code of DateTest bean

                    • 7. Re: JSF Custom Component and ajax4jsf problem
                      krbaburaj

                      Hi Ilya,

                       

                      I had debugged a bit more on this issue and the following are the result. this will help to diagnose the issue

                       

                      1) I had given log on the setter method of the tag and component and the handle method of the bean

                      2) What i saw is ,On change

                                         1) framework is first calling the setter method of the COMPONENT

                                         2) Calling the handle method of BEAN

                                         3) Calling the setter method of the TAG

                      3)  So all time component is having the old value

                      4) Reloding is happing but with old values

                      5) That is why component is not repainting

                       

                      Is this the problem with me(I know it is because of me only, but i couldn't identify where exactly is the problem)

                       

                      The following is my bean calss

                       

                      package org.test;

                       

                      import java.util.ArrayList;
                      import java.util.List;

                       

                      import javax.faces.model.SelectItem;

                       

                      public class DateTest {
                         
                          private String time = "18:16:45";
                         
                          private boolean one;
                         
                          private boolean two;
                         
                          private boolean three;
                         
                          private int value;
                         
                          public void setTime(String time) {
                              this.time = time;
                          }
                         
                          public String getTime() {
                              return time;
                          }
                         
                          public String add() {
                              System.out.println("-----------> 1234   " + getTime().toString());
                              return "OK";
                          }
                         
                          public void handle() {
                              if (value == 0) {
                                  one = true;
                                  two = false;
                                  three = false;
                              }
                              else if (value == 1) {
                                  one = false;
                                  two = true;
                                  three = false;
                              }
                              else if (value == 2) {
                                  one = false;
                                  two = false;
                                  three = true;
                              }
                             
                              System.out.println(one + "          " + two + "          " + three);
                             
                          }
                         
                          public List<SelectItem> getNameItems() {
                              List<SelectItem> items = new ArrayList<SelectItem>(1);
                              items.add(new SelectItem("0", "One"));
                              items.add(new SelectItem("1", "Two"));
                              items.add(new SelectItem("2", "Three"));
                             
                              return items;
                          }
                         
                          /**
                           * @return the one
                           */
                          public boolean isOne() {
                              return one;
                          }
                         
                          /**
                           * @param one
                           *            the one to set
                           */
                          public void setOne(boolean one) {
                              System.out.println("Set Bean One");
                              this.one = one;
                          }
                         
                          /**
                           * @return the two
                           */
                          public boolean isTwo() {
                              return two;
                          }
                         
                          /**
                           * @param two
                           *            the two to set
                           */
                          public void setTwo(boolean two) {
                              System.out.println("Set Bean Two");
                              this.two = two;
                          }
                         
                          /**
                           * @return the three
                           */
                          public boolean isThree() {
                              return three;
                          }
                         
                          /**
                           * @param three
                           *            the three to set
                           */
                          public void setThree(boolean three) {
                              System.out.println("Set Bean Three");
                              this.three = three;
                          }
                         
                          /**
                           * @return the value
                           */
                          public int getValue() {
                              return value;
                          }
                         
                          /**
                           * @param value
                           *            the value to set
                           */
                          public void setValue(int value) {
                              this.value = value;
                          }
                      }

                      • 8. Re: JSF Custom Component and ajax4jsf problem
                        ilya40umov

                        1) if you haven't tried the same without custom component you could try it with standart components only. It can help to determine where bug is(in custom components or the idea in general is wrong)

                        2) debug also get methods (I guess that JSF may not call isThree when it rerenders page)

                        3) try valueChangeListener for handling value change event

                        • 9. Re: JSF Custom Component and ajax4jsf problem
                          ilya40umov
                          • 10. Re: JSF Custom Component and ajax4jsf problem
                            krbaburaj

                            protected void setProperties(UIComponent component) {
                                    super.setProperties(component);
                                    UIInputTime uiTime = (UIInputTime) component;
                                    System.out.println("SET Properties   -->  "+rendered);
                                    if (rendered != null) {
                                        System.out.println("Rendered ========= " + rendered);
                                        if (TagLibUtil.isValueReference(rendered.toString())) {
                                            TagLibUtil.setValueExpression(getFacesContext(), "rendered", rendered.toString(), uiTime, Boolean.class);
                                        }
                                        else {
                                            uiTime.setRendered(rendered);
                                        }
                                    }

                            }


                            Bean methods are calling on the change events.

                             

                            But the above method of TAG class is calling only once(at the very first time of rendering).

                             

                            At the Onchange event setProperties method is not calling. Is that right flow. If i am ryte, once the setProperty method has called then only COMPONENT object gets the data from beans.

                            • 11. Re: JSF Custom Component and ajax4jsf problem
                              krbaburaj

                              What could be wrong, why the above setProperty method is not calling by the reRendering process

                              • 12. Re: JSF Custom Component and ajax4jsf problem
                                krbaburaj

                                Bean property is true ... but those value is not reaching the TAG and COMPONENTS. Why it is so. the value of the bean is reaching correctly. What is wrong with other properties.. For the past 2 weeks im fed with this 1.2 components. Development almost stopped becoz of this. Please help...

                                • 13. Re: JSF Custom Component and ajax4jsf problem
                                  ilya40umov

                                  Unfortunatly I've never tried to create complete JSF components. Facelets' ability to create custom components has been always enough for me. But I guess that there are guys here who can help you. You also can read this(it's about how to write JSF components with facelets) http://www.ibm.com/developerworks/java/library/j-facelets/

                                   

                                  P.S. I think you can also try Richfaces CDK if you are not using it now.

                                  • 14. Re: JSF Custom Component and ajax4jsf problem
                                    ilya40umov

                                    Sorry if I've disappointed you.

                                    1 2 Previous Next