tutorialadffacesjavabeans-part2

Upload: peter-gikonyo

Post on 06-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 tutorialadffacesjavabeans-part2

    1/13

    TUTORIAL: ADF Faces (Part 2)

    Passing parameter values between JSF pagesBy: Dr. Ahmad Taufik Jamil, Pusat Teknologi Maklumat, HUKM

    This tutorial will show you how to pass parameter value originated from a JSF form and view them in another JSF page. The

    tutorial will show various ways to achieve the objectives. The entire tutorials will use JavaBeans and ADF Faces.

    Part 2

    Using backing beans and managed beans

    1. Creating new project folder.a. Using the same workspace in part 1, create new project folder. Right click at workspaceADFJB, clickNew

    b. InNew Gallery dialog box, inside Categories column, expand General > Project, insideItems, clickEmptyProject, and then clickOK.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    2/13

    c. In Create Projectdialog box, enterview2 forProject Name :, and then clickOK.

    2. Creating page navigation using face-config.xml.a. Right click at view2 project, clickProject Properties. InProject Properties dialog box, clickTechnology

    Scope at left column; find and clickJSFand JavaBeans atAvailable Technologies and move to right column

    (Selected Technologies)-Java, JSP and Servlets is moved as well. ClickOK.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    3/13

    b. Right click at view2 project, and clickOpen JSF navigation. Filefaces-config.xmlis opened in Diagram view.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    4/13

    c. Click, drag & drop 2JSF Page to design area offaces-config.xmland createJSF Navigation, just like in part1 tutorial, follow steps 2(c) 2(d) in part 1 tutorial.

    3. Creating Managed Beana. Right click at view2 project, clickNew

  • 8/3/2019 tutorialadffacesjavabeans-part2

    5/13

    b. AtNew Gallery dialog box, expand General, find and clickJavaBeans. InsideItems, clickBean and then clickOK.

    c. At Create Bean dialog box, enterUserBean forName:,view2 forPackage:, and choosejava.lang.Object forExtends:, then clickOK. Source editor forUserBean.java is now opened.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    6/13

    d. Add the following lines inside the UserBean class, immediately below UserBean constructor ( publicUserBean() { }). (****in part 1 tutorial, the following source code I put in backing bean. Now I separate

    it into the managed bean (Userbean.java)).

    private String nama;private String email;private String jantina;private String bangsa;

    //NAMApublic String getNama(){

    return nama;}

    public void setNama(String nama){this.nama=nama;

    }

    //EMAILpublic String getEmail(){

    return email;}

    public void setEmail(String email){this.email=email;

    }

    //JANTINApublic String getJantina(){

    return jantina;}

    public void setJantina(String jantina){this.jantina=jantina;

    }

    //BANGSApublic String getBangsa(){

    return bangsa;}

    public void setBangsa(String bangsa){this.bangsa=bangsa;

    }

    e. Save all and compile.

    4. Creating JSF form and backing beans.a. Go back tofaces-config.xmlDiagram view.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    7/13

    b. Double click icon/untitled1.jsp. Enterborang.jsp forFile name:. ClickNext. ChooseAutomatically ExposeUI Components in a New managed Beans. ClickFinish.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    8/13

  • 8/3/2019 tutorialadffacesjavabeans-part2

    9/13

    b. Add following lines below the last method commandButton1_action() (after the curly bracket ( })).private UserBean userbean = new UserBean();

    public UserBean getUserbean() {return userbean;

    }

    c. Press Alt+Enter to add import view2.UserBean;d. Within method commandButton1_action(), add below line // Add event code here...

    nama = (String)inputText1.getValue();email = (String)inputText2.getValue();jantina = (String)selectOneRadio1.getValue();bangsa = (String)selectOneChoice1.getValue();

    userbean.setNama(nama);userbean.setEmail(email);userbean.setJantina(jantina);userbean.setBangsa(bangsa);

    e. Then change return null;to return submit;f. Save All & compile.

    6. Creating JSF page to view parameter values.a. Follow step 5(a)-5(g), from tutorial part 1.You will get similar outcome.

    b. ClickoutputText1 in design area to mark it. AtProperty Inspector, clickValue. Clickicon Bind to data. Adialog box Value will appear.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    10/13

    b.c. Expand backing_borangin Variables column. Find userbean and expand it. Find and clicknama to mark it.

    Click button > to move it to Expression column. Then click OK.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    11/13

    d. The Value inProperty Inspectorhas changed to #{backing_borang.nama}.

    e. Repeat the same foroutputText2, 3 &4, foremail, jantina and bangsa repectively.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    12/13

    f. Click buttonSemula to mark it. Go toProperty Inspector, for columnAction, choose back.

    g. Save All & compile.h. Run file borang.jsp

    i. Enter value for all columns, and click buttonHantar.

  • 8/3/2019 tutorialadffacesjavabeans-part2

    13/13

    j. Click button Semula, you will be redirected to the first JSF page.