CourseOutline Example - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

CourseOutline Example

Description:

CourseOutline Example & JavaBeans Lec - 36 Start with Example Displaying Course Outlines User will select either course web design & development or java . – PowerPoint PPT presentation

Number of Views:31
Avg rating:3.0/5.0
Slides: 12
Provided by: DougP163
Category:

less

Transcript and Presenter's Notes

Title: CourseOutline Example


1
CourseOutline Example JavaBeans
  • Lec - 36

2
Start with Example Displaying Course Outlines
  • User will select either course web design
    development or java.
  • On submitting request, course outline would be
    displayed of the selected course from database

3
Program Flow
web.jsp
If page web
index.jsp
controller .jsp
If page java
java.jsp
4
Issues with Last Example
  • Too much cluttered code in JSP
  • Difficult to understand
  • A single page is doing everything bad approach
  • Displaying contents (Presentation logic)
  • Connecting with database (DB connectivity logic)
  • Results Processing (Business Logic)
  • Solution
  • Use JavaBeans

5
JavaBeans
6
What are JavaBeans?
  • Java class that can be easily reused and composed
    together in an application
  • Any java class that follows certain design
    conventions can be a JavaBeans component

7
JavaBeans Design Conventions
  • A bean class must have a zero argument
    constructor
  • A bean class should not have any public instance
    variables (fields)
  • Private values should be accessed through
    setters/getters
  • For boolean data types, use boolean isXXX( )
    setXXX(boolean)
  • A bean class must be serializable

8
A Sample JavaBean
  • public class MyBean implements Serializable
  • private String name
  • // zero argument constructor
  • public MyBean( )
  • name
  • // standard setter
  • public void setName(String n)
  • name n

9
A Sample JavaBean cont.
  • // standard getter
  • public String getName( )
  • return name
  • // any other method
  • public void print( )
  • System.out.println(Name is name)
  • // end Bean class

10
Incorporating Bean in Last Example
  • Create a CourseOutlineBean
  • Has following attributes
  • sessionNo
  • topic
  • assignment
  • Create a CourseDAO (bean)
  • Encapsualte database connectivity logic
  • web.jsp java.jsp will use these beans

11
Example Code
  • Incorporating JavaBeans in
  • CourseOutline Example
Write a Comment
User Comments (0)
About PowerShow.com