Problem with Rich:PickList Control
kapil29 May 25, 2010 3:49 AMHi,
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.
-
PickList Form.JPG 23.2 KB