MVC and JSF

download MVC and JSF

of 12

Transcript of MVC and JSF

  • 8/19/2019 MVC and JSF

    1/26

    Programming Applications

    Spring

    201

    5

    -

    201

    6

    Ass

    . Prof. Dr.

    Pelin GÖRGEL

    ([email protected])

    09

    .

    03

    .201

    6

    15:10 1

    15:10

  • 8/19/2019 MVC and JSF

    2/26

    MVC (Model

    -

    View

    -

    Controller)

    MVC

    which

    is

    an

    essential architectural

    pattern in software was firstly defined in

    1979.

    It divides the application into three

    components:

    Model

    View

    Controller

    MVC design defines the interactions

    between them.2

    15:10

  • 8/19/2019 MVC and JSF

    3/26

    MVC (Continued)

    This architecture is a significant

    cornerstone for many applications due to

    its benefits and advantages and accepted

    by most of the coders and software

    engineers.

    Even if you are junior developer you

    probably faced with a problem called

    “Complexity of Project”. MVC helps you to

    decrease

    complexity

    of project.

    In the creation process of a complex web

    application it is convenient to divide it into

    particular functional components to

    preserve the good

    arrangement of sourcecodes. 3

    15:10

  • 8/19/2019 MVC and JSF

    4/26

    MVC (Continued)

    It enables not only to

    separate

    the

    application appearance from data

    and its code, but also to divide

    various types of application

    functional components and their

    classification into a well

    -

    arrangedarchitecture.

    The aim of MVC is to develop the

    layers of the project seperately. This

    helps the project to extent, the

    codes to be updated

    and the test tobe performed

    easily

    . 415:10

  • 8/19/2019 MVC and JSF

    5/26

    MVC

    515:10

  • 8/19/2019 MVC and JSF

    6/26

    MVC

    -

    Model

    In an application, model represents

    data and the rules for accessing it.

    It handles data processing and

    database.

    Model processes events sent by

    Controller. After processing these

    events then it sends processed data

    to Controller or directly to the View

    side.615:10

  • 8/19/2019 MVC and JSF

    7/26

    MVC - Controller

    Controller is like brain of the system. Itprocesses every request , prepares otherparts of the system like Model and View.

    Then the system determines what to doby controller’s commands.It translates the user's interactions withthe View into actions that the Model willperform.In a MVC application, View just displaysthe information, Controller manages user

    inputs and interactions . 7

  • 8/19/2019 MVC and JSF

    8/26

    MVC – View

    View prepares an interface to show to theuser. Controller or Model tells View whatto show to the user.

    Handles requests from user and informscontroller.Specifies exactly how the Model datashould be presented.A View requests the information from theModel that it needs to generate an outputrepresentation.

    815:10

  • 8/19/2019 MVC and JSF

    9/26

    Dependency Hierarchy

    There is usually a kind of hierarchy in theMVC pattern. The Model knows only aboutitself.

    The View however, knows about theModel. But the View knows nothing aboutthe Controller.The Controller knows about both theModel and the View.

    915:10

  • 8/19/2019 MVC and JSF

    10/26

    Dependency Hierarchy(Continued)

    For example If you click on a buttonwhile playing a game, the Controllerknows which function will be called inthe Model.If you press the button for switchingbetween first and second player, theController knows which function willbe called in the View to request thedisplay change.

    1015:10

  • 8/19/2019 MVC and JSF

    11/26

    Dependency Hierarchy(Continued)

    The hierarchy minimizesdependencies. No matter how theView class is modified, the Model willstill work.Even if the system is moved fromWindows to an app in a smart phone,the Model can be moved with nochanges. But the View and Controllerprobably need to be updated.

    1115:10

  • 8/19/2019 MVC and JSF

    12/26

    MVC

    1215:10

  • 8/19/2019 MVC and JSF

    13/26

    13

    Java Server FacesS o m e Di f f er en c es B et w een J S P an d J S F

    JSF is a framework for webapplications.JSF uses the MVC architecture.In JSP, all Java codes are embeddedinto the HTML codes.JSF is faster and for more complexapplications.

    15:10

  • 8/19/2019 MVC and JSF

    14/26

    Process of a JSF Execution

    1. You invoke the application from aserver

    2. Browser requests the app.’s JSFpage

    3. Web server receives this request4.

    GlassFish application server or anyJSF 2.0 compliant container such asApache TomCat behaves like a webserver.

    1415:10

  • 8/19/2019 MVC and JSF

    15/26

    Process of a JSF Execution(Continued)

    5. The framework includes Facesservlet (a software componentrunning on the server) thatprocesses each requested page.

    6. The framework returns a responseto the client.

    1515:10

  • 8/19/2019 MVC and JSF

    16/26

    Setup GlassFish Server

    Go ;https:// glassfish.java.net/download.html

    Choose ;Java EE 7 Full Platform

    Download ;glassfish - 4.1.1.zip

    Extract the zip file ( keeping the name ofthe file) under C: \ driver .

    15:10

    https://glassfish.java.net/download.htmlhttps://glassfish.java.net/download.htmlhttp://download.java.net/glassfish/4.1.1/release/glassfish-4.1.1.ziphttp://download.java.net/glassfish/4.1.1/release/glassfish-4.1.1.ziphttp://download.java.net/glassfish/4.1.1/release/glassfish-4.1.1.ziphttp://download.java.net/glassfish/4.1.1/release/glassfish-4.1.1.ziphttps://glassfish.java.net/download.html

  • 8/19/2019 MVC and JSF

    17/26

    Start GlassFish Server

    Go to the GlassFish folder under Cdriver . Copy the path of the bin file.Click the Start buttonIn the Search box, type cmdPaste this path after cd command

    Write the start command of theGlassFish server:

    15:10 C:\glassfish4\bin\>asadmin start-domain

  • 8/19/2019 MVC and JSF

    18/26

    15:10

  • 8/19/2019 MVC and JSF

    19/26

    15:10

  • 8/19/2019 MVC and JSF

    20/26

    JSF Components

    15:10

  • 8/19/2019 MVC and JSF

    21/26

    JSF App -1 (Buttons)index.xhtml

    15:10

  • 8/19/2019 MVC and JSF

    22/26

    JSF App -1 (Buttons)index.xhtml

    15:10

  • 8/19/2019 MVC and JSF

    23/26

    JSF App -1 (Buttons)login.xhtml

    15:10

  • 8/19/2019 MVC and JSF

    24/26

    JSF App -1 (Buttons)UserBean.java

    15:10

  • 8/19/2019 MVC and JSF

    25/26

    JSF App. 2index.xhtml (JSF file)

    15:10

  • 8/19/2019 MVC and JSF

    26/26

    JSF App. 2WebTimeBean.java (Bean file)

    15:10