Transcript

Chapter 12 copyright Janson Industries Java Server Faces Explain the JSF framework SDO (service data objects) Facelets Pagecode classes Navigation rules Data connection objects Scripting variables Chapter 12 copyright Janson Industries Java Server Faces Will duplicate the front end of MyWeb PO functions using JSF Demonstrate JSF advantages re: Ease of data access Minimize coding Chapter 12 copyright Janson Industries Create a new Dynamic Web project and new EAR change the configuration to JSF v2.0 Click Modify Chapter 12 copyright Janson Industries 20114 Chapter 12 copyright Janson Industries 20115 Chapter 12 copyright Janson Industries In MyWebJSF, create a Web Page, specify Facelet as the template & SpecifyPOSchool as the name Chapter 12 copyright Janson Industries Palette has new set of visual components And new set of Data Components Chapter 12 copyright Janson Industries Relation Record List An SDO A GUI component built from a DB table definition Need to identify a connection (host, DB and table) to base RRL on Chapter 12 copyright Janson Industries Put in a table, some text, 1 HTML input field (To center had to enter: before the table and after) Need a screen where user can select an existing school or specify a new school Chapter 12 copyright Janson Industries Expand the Data and Services tray Click on SDO Relational Record List, then click on the first row, second column table cell A RRL will be defined to display all existing schools Chapter 12 copyright Janson Industries Give the RRL a name Chapter 12 copyright Janson Industries Must associate the SDO with a JDBC connection Define one by clicking New... Chapter 12 copyright Janson Industries Click New... again Chapter 12 copyright Janson Industries Chapter 12 copyright Janson Industries Our Connection Host: PLEIONE.SEALINC.ORG Userid: Student99 PW: pinrut Test connection, then Next chapter 1016 copyright Janson Industries 2010 This is how you would define the connection Change the connection name and test Chapter 12 copyright Janson Industries Chapter 12 copyright Janson Industries New connection appears Finish defining the RRL (this may take a while) Chapter 12 copyright Janson Industries Scroll down, expand the DB and select the Table Chapter 12 copyright Janson Industries RRL requires a primary key, if none defined in the table must define one in RRL Chapter 12 copyright Janson Industries Select School in left pane, click > button, School moved to right pane Chapter 12 copyright Janson Industries Then deselect all fields except School Chapter 12 copyright Janson Industries Save and test Chapter 12 copyright Janson Industries OK not the best but how was that for fast? How many lines of code did you have write? SDO's are good! Chapter 12 copyright Janson Industries Code the RRL generated, notice "EL" 26 JSF EL JSF technology has its own EL called Unified Expression Language Incorporates standard EL plus new expressions that Follow the #{..} syntax and can Set values Invoke methods Perform dynamic operations Chapter 12 copyright Janson Industries 2008 Chapter 12 copyright Janson Industries You can manipulate the HTML directly The header facet has been commented out Chapter 12 copyright Janson Industries No header displayed 29 AddPO Facelet Need a Facelet to insert a new PO Want SpecifyPOSchool to display first so user specifies the school Schools listed will be defined as links to AddPO Facelet If school not listed, student will type into textfield School name passed to AddPO Chapter 12 copyright Janson Industries 2008 30 Getting to AddPO.jsp For links need to Change listed schools to links Define links to go to AddPO.faces For the text field need to Add a command button Define a navigation rule to go to AddPO.faces Chapter 12 copyright Janson Industries 2008 Chapter 12 copyright Janson Industries CALTAL - First create AddPO Chapter 12 copyright Janson Industries Put some text on page Chapter 12 copyright Janson Industries Click Link, then School. In the Properties view, specify AddPO.faces (not xhtml). Save all changes. Chapter 12 copyright Janson Industries Run and click the Death Valley link... Chapter 12 copyright Janson Industries Do it! Chapter 12 copyright Janson Industries When a Facelet is created in a JSF project: A package called PageCode is created in Java Resources/src PageCodeBase class is imported into the PageCode package When GUI components added to Facelet A java source code file is created in the PageCode package that Has the same name as the Facelet Extends PageCodeBase How does JSF work Chapter 12 copyright Janson Industries Since AddPO only has text, the java file was not created Chapter 12 copyright Janson Industries When a SDO is added to the Facelet, in the pagecode class The default visual components and the methods that define the visuals components are added Methods and variables to perform the data operation(s) are added How does JSF work Chapter 12 copyright Janson Industries Chapter 12 copyright Janson Industries When Facelet invoked, Server instantiates pagecode class as bean with name of pc_FaceletName Facelet invokes the bean data getter methods Facelet formats and displays data How does JSF work Chapter 12 copyright Janson Industries Chapter 12 copyright Janson Industries Need to pass either: Clicked school School name entered in text field Will pass the two pieces of data differently For link, will define a parameter For text field, will define a scripting variable Continuing the App Chapter 12 copyright Janson Industries Click link & in Properties view click on Parameter tab Chapter 12 copyright Janson Industries In Select Page Data Object, expand schoolRRL (SDO), schoolRRL(TXTABLE), select SCHOOL Click Add Parameter, specify schoolName. Click in Value area to display Value button, then click it Click OK 45 RRL School value added to the parameter Chapter 1246 copyright Janson Industries 2011 Expression Language Can retrieve request parameters ${param.parameter_name} or #{param.parameter_name} Or scripting variables ${page.variable_name} or # ${request.variable_name} ${session.variable_name} If scope not specified, search is done in the following order: page, request, session, app Chapter 12 copyright Janson Industries To prove that data passed, add EL to retrieve and display parameter schoolName Save all changes, run SpecifyPOSchool Chapter 12 copyright Janson Industries Click the Death Valley link Chapter 12 copyright Janson Industries Chapter 12 copyright Janson Industries If you look at the end of the URL you will see the parameter schoolName and its value Chapter 12 copyright Janson Industries To define a scripting variable, go back to SpecifyPOSchool edit session, in Page Data view.. expand Scripting Variables,double click sessionScope Chapter 12 copyright Janson Industries Click Add button, specify name and type, click OK Chapter 12 copyright Janson Industries Chapter 12 copyright Janson Industries Been using the text and textfield as placeholders Delete both Chapter 12 copyright Janson Industries Select cells in row and join them by clicking Table, Join Selected Cells Chapter 12 copyright Janson Industries Bind the sessionScope variable to a new input text field by dragging variable to the joined cells Chapter 12 copyright Janson Industries Change the field to allow inputting Chapter 12 copyright Janson Industries Adds descriptive text, input field, Submit button and a message area Drag text and input field into the original table Chapter 12 copyright Janson Industries Add another row to the table and drag the button and message area into it Chapter 12 copyright Janson Industries Click on the Submit button, switch to Properties view, click the Select or code the action button Chapter 12 copyright Janson Industries Select code an action. This allows you to enter code to execute when button is clicked. Must make a change, so click on pane and change the return as below Chapter 12 copyright Janson Industries In Properties view, at far right, click Add Rule... Chapter 12 copyright Janson Industries Select AddPO.xhtml and click OK Chapter 12 copyright Janson Industries A very simple rule "always go to AddPO" added Chapter 12 copyright Janson Industries Bind the sessionScope variable to a new text field by dragging the variable onto the AddPO Facelet Chapter 12 copyright Janson Industries Were adding an output only Text field Chapter 12 copyright Janson Industries Added some descriptive text, an output field and an error message area Chapter 12 copyright Janson Industries Prove it works, run SpecifyPOSchool, enter a school name, click Submit Chapter 12 copyright Janson Industries Try it. Chapter 12 copyright Janson Industries We want AddPO to display text fields to enter the a new POs info and allow insert In addition the school name from SpecifyPOSchool should be used First we have to delete the text and fields JSF Chapter 12 copyright Janson Industries Select the fields and delete Chapter 12 copyright Janson Industries Click on SDO Relational Record and then on AddPO Chapter 12 copyright Janson Industries Give the RR a name & change the function to create Chapter 12 copyright Janson Industries Scroll down, expand SALES, select TXTABLE Chapter 12 copyright Janson Industries Click Modify primary key Chapter 12 copyright Janson Industries Make PONUM the key Chapter 12 copyright Janson Industries Deselect the paid fields and click Finish Chapter 12 copyright Janson Industries Must change the school field to display the parameter schoolName (value set when link clicked) Chapter 12 copyright Janson Industries To test, run SpecifyPOSchool, click the link Chapter 12 copyright Janson Industries New business function to Pay POs We want a Facelet (SpecifyPOtoPay) to display non-paid PO's as links If link clicked, go to PayPO.jsp that Gets PO info and displays Lets user enter pay date and amt Updates the info in DB JSF Chapter 12 copyright Janson Industries Create SpecifyPOtoPay, add a RRL (outstandingPOsRRL) This may take awhile! Chapter 12 copyright Janson Industries Specify the table Chapter 12 copyright Janson Industries This time define PONum as key Chapter 12 copyright Janson Industries Add a filter to get unpaid POs Chapter 12 copyright Janson Industries Specify PAIDAMT and a value of 0 Chapter 12 copyright Janson Industries Chapter 12 copyright Janson Industries Just display enough info to id the PO Chapter 12 copyright Janson Industries Kept the paid amount field from being displayed Added a little descriptive text Chapter 12 copyright Janson Industries Test it Chapter 12 copyright Janson Industries Change SpecifyPOtoPay such that: PO#'s are links to PayPO facelet Pass the PO# as a parameter PayPO will Get PO info for parameter Allow field updates Must create PayPO before you can link to it JSF Chapter 12 copyright Janson Industries Create PayPO Chapter 12 copyright Janson Industries Click Link, {PONUM} Chapter 12 copyright Janson Industries Must specify PayPO.faces in outputLink tag Chapter 12 copyright Janson Industries Define a parameter (PON) and set it's value to the RRL's PONUM with param tag Chapter 12 copyright Janson Industries In PayPO put EL to test that the value is accessible Chapter 12 copyright Janson Industries Test and verify the links are there, click T432... Chapter 12 copyright Janson Industries verify the PO number is displayed Chapter 12 copyright Janson Industries Change text, delete EL, add a Relation Record to the facelet called (payPORR), define it to Update Chapter 12 copyright Janson Industries Select the Table copyright Janson Industries Chapter 12 Select fields Chapter 12 copyright Janson Industries Define the primary key Chapter 12 copyright Janson Industries Define the filter to use the parameter PON Chapter 12 copyright Janson Industries Click Close, then Finish Chapter 12 copyright Janson Industries Time to test Chapter 12 copyright Janson Industries Run SpecifyPOtoPay, click on Bratwurst, should go to PayPO Chapter 12 copyright Janson Industries Enter Date and Amount, then click Submit Gotcha Alert: There are blank spaces in some of the input fields. If you click on the field and type, the data and blanks will be in the field. When you click Submit, it may fail because the field value is too big for the table. Erase all extra spaces. Chapter 12 copyright Janson Industries Nothing will look like it was done Go back to SpecifyPOtoPay and refresh The paid PO will not appear Try it


Top Related