1 / 22

CSCI 6962: Server-side Design and Programming

CSCI 6962: Server-side Design and Programming. Java Server Faces Components and Tags. 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 )

giolla
Download Presentation

CSCI 6962: Server-side Design and Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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:____htmltags (most correspond to standard html) • <f:____facelettags (specific to JSF capabilites) • <c:____JSTLtags (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.xhtml order.xhtml ComputerBean

  5. Checkbox • Tag: <h:selectBooleanCheckbox value=“#{beanname.variable}”/> • 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(booleanvalue) • public booleanisVariable()

  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 • <c:if test=“boolean value”> html</c:if> • 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 ‘<‘ and ‘>’) • 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:<f:selectItemitemLabel=“label” itemValue=“value”/> <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 Stringvariable 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. • Note that array does not evaluate to null if nothing chosen • Can check whether length property = 0 to check whether user selected anything

  15. Iteration JSTL Tag • Can use like simple for loop<c:forEachvar=“loopiterator” begin=“inital” end=“final” step=“step”/>html</c:forEach> • Similiar tofor (intloopiterator = initial;loopiterator<= final;loopiterator+= step) {…

  16. Iteration JSTL Tag • More useful for looping through collection • Arrays, database tables, etc. • <c:forEachitems=“array or collection”var=“ith value” />html that uses var</c:forEach> • Example: Array stooges = [“Larry”, “Curley”, “Moe”]<c forEach items=“stooges” var=“stooge”/> • 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 ith element of software array Display that value in outputLabel

  18. 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

  19. 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 <f:selectItems value=“bean.arrayName”/>to insert allSelectItem objects in array into list

  20. 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

  21. Bean Generated Lists

  22. Bean Generated Lists

More Related