ArticlesTutorialsInterview Questions & AnswersCertificationsFree Books & Sample ChaptersTechnical Discussions  Your Account | Advertise with us | Feedback |
Few pages of this site are under construction and we are constantly trying to improve it. If you have any suggestions or ideas about how to improve the site, please Let us know.
A first look at Shale Framework - Get started with Shale

A first look at Shale Framework
Get started with Shale    -by Anand K Reddy ,DevelopersBook.com, 06/02/2007

page 5 of 5
Build and Deploy

With all this in place, you should now be able to compile, build, deploy and run your web application. I'm going to assume that you're comfortable enough on this process to bang out a quick script (Ant or Maven) to do the job for you.

You can access your sample app by browsing to your context-root /welcome.faces. That will trigger the JSF servlet to find and load a view named "welcome", which corresponds to your "welcome.jsp"

ViewController

If you notice your logs carefully while running your little Shale app, and you'd have noticed several warnings telling you there's new view controller for view id found under name . This is where we get to start using Shale's features. Shale provides a 1:1 relationship between views and backing beans. It's not an error for there to be no backing bean, but the relationship is one-to-one, not one-to-atmost-one. So we'll create a couple quick empty controller classes and tie them in. For briefness, I'll only show you one.

First, create a new class that extends AbstractViewController:

package com.developersBook.shaleApp.viewcontrollers;

import org.apache.shale.view.AbstractViewController;

public class WelcomeViewController extends AbstractViewController {

            public WelcomeViewController() {

                        super();

            }

            public void init() {

            // Obtain generic resources here - that is, resource that you need regardless of the context of the request    you're going to process.

            }         

            public void preprocess() {

                        if ( ! isPostBack() )

                                    return;

            // Obtain resources you'll need to process the postback - for instance,        database  connections.

            }

           

            public void prerender() {

                        // Use this method to acquire resources ,such as database connections,or performing queries, that you will need if this view is the one to be rendered.

            }

            public void destroy() {

                        // Clean up any resources you obtained in previous event handlers.

            }

}

Then add a managed-bean to your faces config:

<managed-bean>

      <managed-bean-name>welcome</managed-bean-name>

      <managed-bean-class>

                    com.developersBook.shaleApp.viewcontrollers.HelloWorldViewController

      </managed-bean-class>

      <managed-bean-scope>request</managed-bean-scope>

 </managed-bean>

And that's it! The magic is in the naming convention. We have a view called "welcome.jsp". Shale will try to find a backing-bean for your view named "welcome". Note that there's no actual requirement for your backing bean to implement the ViewController interface (AbstractViewController is a convenience base class) - but Shale guarantees that if it does, you'll get extra "freebies" from the framework. For more information on using ViewController, See Here


Resources

The Shale homepage: Find javadocs and additional framework information about Shale


1  | 2  |  3  |  4  |  | 5  |  Articles Home
Test
About Us | Our Mission | Terms of use | Author Terms |    Search        | Contact Us | Advertise With Us | Link to Us | Sitemap
Copyright © 2016 developersBOOK.COM. All rights reserved.