Chapter: Internet & World Wide Web HOW TO PROGRAM - Rich Internet Application Server Technologies - JavaServer™ Faces Web Applications

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail

Examining a Page Bean File

Figure 26.3 presents the page bean file. Line 3 indicates that this class belongs to package webtime.

Examining a Page Bean File

 

Figure 26.3 presents the page bean file. Line 3 indicates that this class belongs to package webtime. This line is autogenerated and specifies the project’s name as the package name. Line 18 begins class Time’s declaration and indicates that it inherits from class Abstract-PageBean (from package com.sun.rave.web.ui.appbase). All page bean classes that support JSP files with JSF components must inherit from the abstract class AbstractPageBean, which provides page life-cycle methods. Note that the IDE makes the class name match the page name. Package com.sun.webui.jsf.component includes classes for many of the basic JSF components (see the import statements at lines 6–13).

 

5    // Fig. 26.3: Time.java

 

6    // Page bean file that sets clockText to the time on the Web server.

 

7    package webtime;

4

9    import com.sun.rave.web.ui.appbase.AbstractPageBean;

 

10import com.sun.webui.jsf.component.Body;

 

11import com.sun.webui.jsf.component.Form;

 

12import com.sun.webui.jsf.component.Head;

 

13import com.sun.webui.jsf.component.Html;

 

14   import com.sun.webui.jsf.component.Link;

 

15   import com.sun.webui.jsf.component.Meta;

 

16   import com.sun.webui.jsf.component.Page;

 

17   import com.sun.webui.jsf.component.StaticText;

 

18   import java.text.DateFormat;

 

19   import java.util.Date;

 

20   import javax.faces.FacesException;

17

1      public class Time extends AbstractPageBean

2      {

 

3             private int __placeholder;

21

5             // auto-generated component initialization method.

 

6             private void _init() throws Exception

7             {

 

8             } // end method _init

26

27   private Page page1 = new Page();

 

28

1            public Page getPage1()

2            {

 

3                   return page1;

 

4            } // end method getPage1

5              

5            public void setPage1( Page p )

6            {

 

7                   this.page1 = p;

 

8            } // end method setPage1

8

39    private Html html1 = new Html();

 

40

14         public Html getHtml1()

15         {

 

16               return html1;

 

17         } // end method getHtml1

18          

19         public void setHtml1( Html h )

20         {

 

21               this.html1 = h;

 

22         } // end method setHtml1

50

51    private Head head1 = new Head();

 

52

24         public Head getHead1()

25         {

 

26               return head1;

 

27         } // end method getHead1

28          

30         public void setHead1( Head h )

31         {

 

32               this.head1 = h;

 

33         } // end method setHead1

62

63    private Link link1 = new Link();

 

64

1            public Link getLink1()

2            {

 

3                   return link1;

 

4            } // end method getLink1

5              

15         public void setLink1( Link l )

16         {

 

17               this.link1 = l;

 

18         } // end method setLink1

74

75    private Body body1 = new Body();

 

76

21         public Body getBody1()

22         {

 

23               return body1;

 

24         } // end method getBody1

1            public void setBody1( Body b )

2            {

 

3                   this.body1 = b;

 

4            } // end method setBody1

86

87    private Form form1 = new Form();

 

88

89        public Form getForm1()

90        {

 

91               return form1;

 

92        } // end method getForm1

93          

13        public void setForm1( Form f )

14        {

 

15               this.form1 = f;

 

16        } // end method setForm1

98

99    private StaticText timeHeader = new StaticText();

 

100

22         public StaticText getTimeHeader()

23         {

 

24                return timeHeader;

 

25         } // end method getTimeHeader

105

1             public void setTimeHeader( StaticText st )

2             {

 

3                    this.timeHeader = st;

 

4             } // end method setTimeHeader

110

111  private StaticText clockText = new StaticText();

 

112

1             public StaticText getClockText()

2             {

 

3                    return clockText;

 

4             } // end method getClockText

5              

10         public void setClockText( StaticText st )

11         {

 

12                this.clockText = st;

 

13         } // end method setClockText

122

123  private Meta meta1 = new Meta();

 

124

1             public Meta getMeta1()

2             {

 

3                    return meta1;

 

4             } // end method getMeta1

5              

1             public void setMeta1( Meta m )

2             {

 

3                    this.meta1 = m;

 

4             } // end method setMeta1

134

5             public Time()

6             {

 

7             } // end Time constructor

8              

1             // initializes page content

 

2             public void init()

3             {

 

4                    super.init();

143

10                try

11                {

12                      _init();

13                } // end try

 

14                catch ( Exception e )

15                {

 

16                      log( "Time Initialization Failure", e );

 

17                      throw e instanceof FacesException ? ( FacesException ) e :

 

18                             new FacesException( e );

 

19                } // end catch

 

20          } // end method init

155

17          // method called when postback occurs

 

18          public void preprocess()

19          {

 

20          } // end method preprocess

160

24          // method called before the page is rendered

 

25          public void prerender()

26          {

 

27                clockText.setValue( DateFormat.getTimeInstance(

 

28                      DateFormat.LONG ).format( new Date() ) );

 

29          } // end method prerender

167

31          // method called after rendering completes, if init was called

 

32          public void destroy()

33          {

 

34          } // end method destroy

172

38          // return a reference to the scoped data bean

 

39          protected SessionBean1 getSessionBean1()

40          {

 

41                return ( SessionBean1 ) getBean( "SessionBean1" );

 

42          } // end method getSessionBean1

178

45          // return a reference to the scoped data bean

 

46          protected ApplicationBean1 getApplicationBean1()

47          {

 

48                return ( ApplicationBean1 ) getBean( "ApplicationBean1" );

 

49          } // end method getApplicationBean1

184

52          // return a reference to the scoped data bean

 

53          protected RequestBean1 getRequestBean1()

{

59 return ( RequestBean1 ) getBean( "RequestBean1" );

 

60          } // end method getRequestBean1

 

} // end class Time


Fig. 26.3 | Page bean file that sets clockText to the time on the web server.

This page bean file provides get and set methods for every element of the JSP file of Fig. 26.1. These methods are generated automatically by the IDE. We included the com-plete page bean file in this first example, but in future examples these properties and their get and set methods will be omitted to save space. Lines 99–109 and 111–121 of the page bean file define the two Static Text components that we dropped onto the page and their get and set methods. These components are objects of class StaticText in package com.sun.webui.jsf.component.

 

The only logic required in this page is to set the clockText component’s text to read the current time on the server. We do this in the prerender method (lines 162–166). The meaning of this and other page bean methods will be discussed shortly. Lines 164–165 fetch and format the time on the server and set the value of clockText to that time.


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail


Copyright © 2018-2020 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.