Java Reference
In-Depth Information
The Configure sessionScope will be redisplayed with the empNum variable listed.
13.
Click the Close button.
In the Page Data pane, expand the sessionScope item to display the new empNum scripting variable. This means
that the session variable was created (which we will really prove in the next tutorial). Notice that no Java had to be
entered (i.e., no PageContext object created, no getSession method or setAttribute method invoked, etc) to create this
session-wide variable. The JSF framework and RAD handle it all. However, we do need to get the employee number
from the input field into the scripting variable. This will be done through binding .
Binding a Data Object to a Visual Component
When a data object is bound to a visual component, they share the same value. Changing one's value will change the
other's value. However, binding works differently with different visual components. For example, when AllEmps was
created, each RRL field (i.e., a data object) was automatically bound to an outputText component (a visual component
generated when the JSF Output component was added to the page). In that case, because an outputText field can't be
changed by a user, the RRL field can't be modified from the page. However, when the bound outputText component
is displayed, the value in the RRL field will be displayed. InsertEmp also employed binding but in that case, inputText
components were bound to RR fields. Because inputText fields can be modified, this means the RR fields can be
modified from the page.
In both these earlier examples, binding was done automatically because a SDO was used (i.e., a RRL or RR was
used). In GetEmp, the session variable (another type of data object) needs to be bound to the generated inputText
field so that when the employee number is entered, the session variable is changed. Because a JSF Input component is
not an SDO, the programmer must bind the visual component and data object. Fortunately, binding in RAD is easy.
Tutorial: Binding
Let's try binding:
1.
From the Page Data view, drag and drop the empNum variable onto the inputText
component.
Yes, that is all it takes to bind. Notice that in the Properties view RAD put an EL statement into the value property
and in Page Designer the variable name appears in the inputText component (within braces).
To finish GetEmp, we will define a navigation rule to run UpdateEmp when the Submit button is clicked.
However, before the navigation rule is created, UpdateEmp should be created. We will create a very basic UpdateEmp
(for testing purposes) and then come back to GetEmp to define the navigation rule. We will then test that the
navigation rule works and complete UpdateEmp.
2.
Save GetEmp.
3.
In TutorialsJSF/WebContent/c12, create a new Facelet called UpdateEmp.
4.
Insert the text “Information for employee number:”.
5.
Insert a space after the colon and then insert an Output component to the right of the
space. (In the source code you may have to insert the non-breaking space numeric entity,
& #160;, after the colon and move the static text's end paragraph tag, </p>, after the
outputText tag.)
6.
Drag and drop the empNum scripting variable from the Page Data view onto the Output
component.
 
Search WWH ::




Custom Search