Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags.

Similar presentations


Presentation on theme: "CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags."— Presentation transcript:

1 CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags

2 JSF Tags JSF pages contain mix of HTML and JSF tags – <h:____ html tags (most correspond to standard html) – <f:____ facelet tags (specific to JSF capabilites) – <c:____ JSTL tags (simple control flow actions) XML format Defined in libraries loaded in xhtml tag at beginning

3 JSF Tags JSF pages mapped to servlet – Code in web.xml generated when JSF webapp created Converted to servlet and run on demand (like JSP)

4 Example JSF configure.xhtmlorder.xhtml ComputerBean

5 Checkbox Tag: Maps to a boolean member variable in bean Can access as boolean in bean methods Can set initial state of checkbox (true if checked)

6 Checkbox Mehtods Requires methods – public void setVariable(boolean value) – public boolean isVariable()

7 Conditional Output Goal: Display whether monitor selected Methods: – Place condition in JSF page to only display row if monitor checked – Place condition in bean to create an output string in html (either a table row or nothing) and display it in JSF page

8 JSF Page Condition Requires use of tags in JSTL library – Cannot just put executable code in page as in JSP html Condition can be bean value If true Display this

9 Bean Value Condition Create “get” method for string to display – Multiple possible strings based on bean values Create outputText to display that string – escape=“false” causes html to be rendered (instead of ‘ ’) – Possible security hole (cross site scripting)

10 List-like Form Elements Basic syntax like select/option lists in html Grouped into single select and multiple select types Contains list of selectItem elements: <h:selectOneListbox <h:selectOneMenu <h:selectOneRadio <h:selectManyCheckbox <h:selectManyListbox <h:selectManyMenu label to display value to pass

11 Radio Buttons Example: Radio button for memory choices Linked to String variable in bean

12 Radio Buttons Evaluates to a single String value – Can manipulate in bean – Can access in JSF page

13 Multiple Selection Elements Must be linked to array in bean

14 Multiple Selection Elements Can manipulate like array – Iterate through elements, search, etc. – Can check whether length property = 0 to check whether user selected anything

15 Iteration JSTL Tag Can use like simple for loop html Similiar to for (int loopiterator = initial; loopiterator <= final; loopiterator += step) {…

16 Iteration JSTL Tag More useful for looping through collection – Arrays, database tables, etc. html that uses var Example: Array stooges = [“Larry”, “Curley”, “Moe”] – Loops 3 times – Iteration 1: stooge = “Larry” – Iteration 2: stooge = “Curley” – Iteration 3: stooge = “Moe”

17 Iteration JSTL Tag Example: Displaying all software selected by user – In software array in bean i th element of software array Display that value in outputLabel

18 Multiple Select Elements Can also generate entire list in bean and then display using simple form element

19 Defining List Elements in Bean List contents hardwired in JSF page – Difficult to modify in future – List contents may be defined by business model Better if list elements defined in bean instead of JSF – JSF links to bean to get list elements

20 Bean Generated Lists Construct array of SelectItem objects in bean – Must import javax.faces.model.* in bean Provide get method to return the array Use to insert all SelectItem objects in array into list

21 Array of SelectItems Syntax: private static SelectItem[] arrayName { new SelectItem(“value1”, “label1”), new SelectItem(“value2”, “label2”), new SelectItem(“value3”, “label3”), … }; public getArrayName() { return arrayName; } Construct new SelectItem for each element in list

22 Bean Generated Lists

23


Download ppt "CSCI 6962: Server-side Design and Programming Java Server Faces Components and Tags."

Similar presentations


Ads by Google