Java Reference
In-Depth Information
40 </h:panelGrid>
41
42 <!-- Use combo box and list -->
43 <h:panelGrid columns="4">
44 <h:outputLabel value="Major "/>
45 <h:selectOneMenu id="majorSelectOneMenu"
46 value="#{registration.major}">
47 <f:selectItem itemValue="Computer Science"/>
48 <f:selectItem itemValue="Mathematics"/>
49 </h:selectOneMenu>
50 <h:outputLabel value="Minor "/>
51 <h:selectManyListbox id="minorSelectManyListbox"
52 value="#{registration.minor}">
53 <f:selectItem itemValue="Computer Science"/>
54 <f:selectItem itemValue="Mathematics"/>
55 <f:selectItem itemValue="English"/>
56 </h:selectManyListbox>
57 </h:panelGrid>
58
59 <!-- Use check boxes -->
60 <h:panelGrid columns="4">
61 <h:outputLabel value="Hobby: "/>
62 <h:selectManyCheckbox id="hobbySelectManyCheckbox"
63 value="#{registration.hobby}">
64 <f:selectItem itemValue="Tennis"/>
65 <f:selectItem itemValue="Golf"/>
66 <f:selectItem itemValue="Ping Pong"/>
67 </h:selectManyCheckbox>
68 </h:panelGrid>
69
70 <!-- Use text area -->
71 <h:panelGrid columns="1">
72 <h:outputLabel>Remarks:</h:outputLabel>
73 <h:inputTextarea id="remarksInputTextarea"
74 style="width:400px; height:50px;"
75
bind major
bind minor
bind hobby
value="#{registration.remarks}"/>
bind remarks
76 </h:panelGrid>
77
78 <!-- Use command button -->
79 <h:commandButton value="Register" />
80 <br />
81 <h:outputText escape="false" style="color:red"
82
value="#{registration.response}" />
bind response
83 </h:form>
84 </h:body>
85 </html>
The new JSF form in this listing binds the h:inputText element for last name, first name,
and mi with the properties lastName , firstName , and mi in the managed bean (lines 21,
24, 27). When the Register button is clicked, the page is sent to the server, which invokes the
setter methods to set the properties in the managed bean.
The h:selectOneRadio element is bound to the gender property (line 34). Each radio
button has an itemValue . The selected radio button's itemValue is set to the gender prop-
erty in the bean when the page is sent to the server.
The h:selectOneMenu element is bound to the major property (line 46). When the page
is sent to the server, the selected item is returned as a string and is set to the major property.
The h:selectManyListbox element is bound to the minor property (line 52). When the
page is sent to the server, the selected items are returned as an array of strings and set to the
minor property.
binding input texts
binding radio buttons
binding combo box
binding list box
 
Search WWH ::




Custom Search