Advertisement
Guest User

Untitled

a guest
Oct 30th, 2014
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. <h:form>
  2. <h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
  3. <p:ajax event="change" process="studlist" update="studdep" ></p:ajax>
  4. <f:selectItems value="#{studBean.student}" var="s"
  5. itemValue="#{s.studid}" itemLabel="#{s.name}"/>
  6. <f:converter converterId="studentconverter"/>
  7. </h:selectOneMenu>
  8. </h:form>
  9.  
  10. public Object getAsObject(FacesContext context, UIComponent component, String value) {
  11.  
  12. Student studConvert= new Student();
  13. List<Student> students=new ArrayList<Student>();
  14. students=(ArrayList<Student>)((UISelectItems
  15. component.getChildren().get(0)).getValue();
  16. }
  17.  
  18. <h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
  19. <f:selectItems value="#{studBean.student}" var="s"
  20. itemValue="#{s.studid}" itemLabel="#{s.name}" />
  21. <f:converter converterId="studentconverter" />
  22. </h:selectOneMenu>
  23.  
  24. <h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
  25. <f:selectItems value="#{studBean.student}" var="s"
  26. itemValue="#{s}" itemLabel="#{s.name}" />
  27. <f:converter converterId="studentconverter" />
  28. </h:selectOneMenu>
  29.  
  30. public String getAsString(FacesContext context, UIComponent component, Object value) {
  31. // This method is called when item value is to be converted to HTTP request parameter.
  32. // Normal practice is to return an unique identifier here, such as student ID.
  33. Student student = (Student) value;
  34. Long id = student.getStudid();
  35. return String.valueOf(id);
  36. }
  37.  
  38. public Object getAsObject(FacesContext context, UIComponent component, String value) {
  39. // This method is called when HTTP request parameter is to be converted to item value.
  40. // You need to convert the student ID back to Student.
  41. Long id = Long.valueOf(value);
  42. Student student = someStudentService.find(id);
  43. return student;
  44. }
  45.  
  46. <h:form>
  47. <h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
  48. <p:ajax event="change" process="studlist" update="studdep" ></p:ajax>
  49. <f:selectItems value="#{studBean.studentSelectItemList}" />
  50. <f:converter converterId="studentconverter"/>
  51. </h:selectOneMenu>
  52. </h:form>
  53.  
  54. private List<SelectItem> studentSelectItemList;
  55.  
  56. //fill studentSelectItemList at the appropriate place
  57. studentSelectItemList.add(new SelectItem(studentId,studentName));
  58.  
  59. <select ...>
  60. <option>None</option>
  61. <option value="1">First</option>
  62. <option value="2">Second</option>
  63. </select>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement