1 / 21

CSCI 6962: Server-side Design and Programming

CSCI 6962: Server-side Design and Programming. Introduction to Java Server Faces. Outline. Model-based architectures and value binding Creating JSF page and managed beans in NetBeans Adding member variables to managed beans Basic JSF tags Binding variables to JSF form elements.

amanda
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 Introduction to Java Server Faces

  2. Outline • Model-based architectures and value binding • Creating JSF page and managed beans in NetBeans • Adding member variables to managed beans • Basic JSF tags • Binding variables to JSF form elements

  3. Java Server Faces • Model-based architecture • Data storage and manipulation • Validation • Navigation and redirection • Long term data storage (sessions, databases, etc.) Managed Bean JJava Server Faces page Support class User interface components JBean JJSF JBean JJSF

  4. Java Server Faces Value Binding • Form elements can be directly linkedto variables inside bean • Changing values on form changes value of those variables when form submitted

  5. Creating a JSF • New Project  Java Web  Web Application Enter name and press NEXT twice(not finish) • Check Java Server Facesunder Frameworks

  6. Creating a JSF Page • New File  Web  JSF Page • Make sure Facelets selected

  7. Creating a Managed Bean • New File  Java Server Faces  JSF Managed Bean • Give it a name and a package • Set its scope to request(for now)

  8. Managed Beans • Generated bean file contains • Name that any JSF can useto refer to it • Scope for which bean exists • Request (single page) • Session (multiple pages in same user session) • Application (accessible byall user sessions)

  9. Defining Member Variables • Data stored or computed by bean • Any form elements bean binds to • Must be type Stringfor text elements

  10. Getter/Setter Methods • Each member variable variable should have methods • public String getVariable() • public void setVariable(String) • Required if variable bound to form element • Get called when page loaded to insert value • Set called when form submitted to change bean value • Done “behind the scenes” with request.getParametercalls

  11. Getter/Setter Methods • Can use ALT-INSERT to do automatically

  12. Java Server Faces Tags • JSF tags instead of html

  13. Java Server Faces Tags • JSF tags instead of html • Tags of form <h:tagname…>or <f:tagname…>(XML syntax) • Many similar in form to html tags • Tag libraries set in enclosing html tag • Reference:http://docs.oracle.com/javaee/6/javaserverfaces/2.0/docs/pdldocs/facelets/

  14. Java Server Faces Tags • Translated to html in response sent to client

  15. JSF Text Input • Goal: Bind input field to member variable in bean • Form submitted  variable value updated automatically • Page sent back as response  variable value automatically inserted • Syntax:<h: inputText value=‘#{beanname.variablename}’/>

  16. JSF Text Output • Like input field, but “read only” • Variable value automatically inserted into response • Translated into simple text • Syntax:<h: outputLabelvalue=‘#{beanname.variablename}’/>

  17. JSF Submit Buttons • Syntax:<h:commandButton value=‘label on button' action=“page to redirect to"/> • Note that address defined in button rather than form • Crucial for bean-directed redirection

  18. Computed Values • Can bind to computed values instead of bean variables • Example: • Bean computes cost of widget order • Receipt gets and displays that value

  19. Computed Values • Must define get and set method for input field • Must define setmethod for input field Cost not a member variable getCost computed from member variables

  20. Initial Values • Can load values into form elements when page loaded • Assign corresponding bean variables initial values

  21. JSF/Bean Lifecycle JJSF JBean Request for JSF page (initial form request) bean constructed (if it does not already exist) Jhtml Sent as html form bean values loaded into bound elements using get methods Parameter values parsed Form submitted parameter values from bound elements stored in bean using set methods

More Related