Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <h:form>
- <h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
- <p:ajax event="change" process="studlist" update="studdep" ></p:ajax>
- <f:selectItems value="#{studBean.student}" var="s"
- itemValue="#{s.studid}" itemLabel="#{s.name}"/>
- <f:converter converterId="studentconverter"/>
- </h:selectOneMenu>
- </h:form>
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
- Student studConvert= new Student();
- List<Student> students=new ArrayList<Student>();
- students=(ArrayList<Student>)((UISelectItems
- component.getChildren().get(0)).getValue();
- }
- <h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
- <f:selectItems value="#{studBean.student}" var="s"
- itemValue="#{s.studid}" itemLabel="#{s.name}" />
- <f:converter converterId="studentconverter" />
- </h:selectOneMenu>
- <h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
- <f:selectItems value="#{studBean.student}" var="s"
- itemValue="#{s}" itemLabel="#{s.name}" />
- <f:converter converterId="studentconverter" />
- </h:selectOneMenu>
- public String getAsString(FacesContext context, UIComponent component, Object value) {
- // This method is called when item value is to be converted to HTTP request parameter.
- // Normal practice is to return an unique identifier here, such as student ID.
- Student student = (Student) value;
- Long id = student.getStudid();
- return String.valueOf(id);
- }
- public Object getAsObject(FacesContext context, UIComponent component, String value) {
- // This method is called when HTTP request parameter is to be converted to item value.
- // You need to convert the student ID back to Student.
- Long id = Long.valueOf(value);
- Student student = someStudentService.find(id);
- return student;
- }
- <h:form>
- <h:selectOneMenu id="studlist" value="#{studBean.selectedStudent}">
- <p:ajax event="change" process="studlist" update="studdep" ></p:ajax>
- <f:selectItems value="#{studBean.studentSelectItemList}" />
- <f:converter converterId="studentconverter"/>
- </h:selectOneMenu>
- </h:form>
- private List<SelectItem> studentSelectItemList;
- //fill studentSelectItemList at the appropriate place
- studentSelectItemList.add(new SelectItem(studentId,studentName));
- <select ...>
- <option>None</option>
- <option value="1">First</option>
- <option value="2">Second</option>
- </select>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement