7 Replies Latest reply on Jun 3, 2010 7:16 PM by kapil29

    Problem with Rich:PickList Control

    kapil29

      Hi,

      I am using the rich picklist control for displaying the list of available Questions from the database (Question Table Object) on left hand side of picklist, and selection of question is appearing on right hand side of the list. Now the question are selected will be appear in the panel next to picklist will display the details of that question as per mention in below structure.

       

      Now I have the releation maintain in database table as follows

       

      Question Table (id, Text) values(1, What is your Sex?)

      Answer Table  (id, Text, question_id) values(1, Male,1)

                           (id, Text, question_id) values(2, Female,1)

       

      So the Panel Will display the output as

       

      1 What is your Sex?

      * Male

      * Female

       

      2 Next Selected Question?

      * ans1

      * ans2

       

       

      So when I click the question from left hand side list, the right hand seletion is displayed, but panel next to rich: picklist with above mention output is not being displayed?

       

      Kindly Help me to sort out this issue,

       

       

      Below are my code

       

      JSF code

       

      <rich:panel>
                          <f:facet name="header">
                              Demo Block Question Selection
                          </f:facet>

       

                          <h:panelGrid columns="2" columnClasses="top, top">

                              <rich:pickList value="#{demoBlockBean.demoQuestions}" converter="#{demoBlockConverter}" switchByClick="true" >

                                  <a4j:support event="onlistchanged" reRender="showPanel"/>
                                  <f:selectItems value="#{demoBlockController.allEnabledDemoQuestionsSelectItems}"/>

                              </rich:pickList>

       

                              <rich:panel id="showPanel" bodyClass="pbody">
                                  <f:facet name="header">
                                      <h:outputText value="Options Choosen"></h:outputText>
                                  </f:facet>
                                  <a4j:repeat value="#{demoBlockBean.demoQuestions}" var="demoQuestionSelectedList">
                                      #{demoQuestionSelectedList}
                                  </a4j:repeat>
                              </rich:panel>
                          </h:panelGrid>

      </rich:panel>

       

      Bean Class

       

      @Scope(value = "request")
      @Component(value = "demoBlockBean")

      public class DemoBlockBean {

       

          private List<DemoQuestion> demoQuestions;

       

          public List<DemoQuestion> getDemoQuestions() {
              return demoQuestions;
          }

       

          public void setDemoQuestions(List<DemoQuestion> demoQuestions) {
              System.out.println("demoQuestions===="+demoQuestions);
              this.demoQuestions = demoQuestions;
          }

       

      }

       

      Controller Class for getting list of Question from DB

       

      @Scope(value ="request")
      @Component(value= "demoBlockController")

      public class DemoBlockController {

       

          @Autowired
          DemoQuestionService demoQuestionService;

       

          public List<SelectItem> getAllEnabledDemoQuestionsSelectItems() {
              List<DemoQuestion> demoQuestionList = demoQuestionService.getEnabledDemoQuestions();
              List<SelectItem> demoQuestionSelectItemList = new ArrayList<SelectItem>(demoQuestionList.size());
              for (DemoQuestion demoQuestion : demoQuestionList) {
                  demoQuestionSelectItemList.add(new SelectItem(demoQuestion, demoQuestion.getText()));
              }
              return demoQuestionSelectItemList;
          }
      }

       

       

      Converter Class

       

      @Service(value = "demoBlockConverter")
      @Scope(value = "session")

      public class DemoBlockConverter implements Converter{

       

          @Autowired
          private DemoQuestionService demoQuestionService;

       

          public Object getAsObject(FacesContext context, UIComponent component, String value)
                  throws ConverterException {
              if (context == null || component == null) throw new NullPointerException();
              if (value == null || value.length() == 0) return null;

       

              DemoQuestion demoQuestion = demoQuestionService.getDemoQuestion(new Long(value));
              System.out.println("demoQuestion In Converter========="+demoQuestion.getText() + "value=== " + value);
              return demoQuestion;
          } // end method getAsObject

       

          public String getAsString(FacesContext context, UIComponent component, Object value)
                  throws ConverterException {
              if (context == null || component == null) throw new NullPointerException();
              if (value == null || value.getClass() != DemoQuestion.class) return null;

       

              DemoQuestion demoQuestion = (DemoQuestion) value;
              return demoQuestion.getId().toString();
          } // end method getAsString
      }

       

       

      Please find the attached File also for reference.

        • 1. Re: Problem with Rich:PickList Control
          ilya_shaikovsky

          add rich:messages to the page.

          • 2. Re: Problem with Rich:PickList Control
            kapil29

            Where exactly I need to add the rich:messages?, My poblem is something different, as per mentioned in discussion, actually I am getting stuck with setting the bean peroperty value, I see that when i add the converter into it, the setter property of demoQuestionBean is not getting set. I am checking it with SOP (System.out.printlln) alos I am debugging the application with watches...

             

            But When I take the values for SelectItem as a hard coded String without converter, it calls the setter method property, which will display the list of questions are added into the list.....

             

            Kindly let me know where actually I am getting stuck...

             

             

            Thanks

            Kapil Nimje

            • 3. Re: Problem with Rich:PickList Control
              ilya_shaikovsky

              place messages anywhere at this page.. for example right above or beow the pickList

              • 4. Re: Problem with Rich:PickList Control
                kapil29

                Is it sure to resolve this issue by adding the <rich:messages />?, I think the problem is not having to place the messages above and below the pick list, I need to displayed it into the Panel near by richpick list, so rich:messages is not able to solve the issue,

                 

                Please let me clarify if i am wrong. because i did this as per the live demo site provided by jboss.

                 

                For your Information please try to see the souce code mention in live demo link.

                 

                http://livedemo.exadel.com/richfaces-demo/richfaces/pickList.jsf;jsessionid=660060DCA8FF990D38982A761A843628?c=pickList&tab=usage

                 

                 

                Thanks

                Kapil

                • 5. Re: Problem with Rich:PickList Control
                  ilya_shaikovsky

                  messages  has not connected to solving your problem directly. Them will just show if there are any conversion/validation error messages were added to Context during request.. So please just add them and provide information - if there are something appeared.

                  • 6. Re: Problem with Rich:PickList Control
                    kapil29

                    HIi,

                    after adding rich:messages to the page, it's showing me the error as

                       "j_id234: Validation Error: Value is not  valid"  after selection from the rich pick list.

                    But see my convertor code, it returing the  DemoQuestion object Type, and all my setter and getter methods in DemoQuestion Bean is having the same Type (DemoQuestion),

                    So I am not able to find the root cause of this, so could please let me know where I was wrong...?
                    • 7. Re: Problem with Rich:PickList Control
                      kapil29

                      Hey IIya,

                       

                             I got the problem, and I reslove this error also,

                       

                      The problem was in my Domain Object class i.e. DemoQuestion.java, here I need to override the equals() method of Object Class, by declaring the equals method the problem got solved.

                       

                      here are my code now..

                       

                      @Override
                          public boolean equals(Object obj) {
                              if (!(obj instanceof DemoQuestion)) return false;
                              DemoQuestion demoQuestion = (DemoQuestion) obj;
                              return this.id.equals(demoQuestion.id);
                          } // end method equals

                       

                       

                       

                      Thanks for your support.

                       

                      Kapil Nimje