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 4 of 5
hello.jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

 <html>
            <head>
                        <title>Hello World!</title>

            </head>
            <body>
                        <f:view>

                        <h3>Hello…… <h:outputText value="#{nameBean.name}"/></h3>

                        </f:view>

            </body>
</html>

bye.jsp

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<html>
            <head>
                        <title>Hello World!</title>

            </head>

            <body>

                   <f:view>

                      <h3>GoodBye, <h:outputText value="#{nameBean.name}"/></h3>

                   </f:view>

            </body>
</html>

If you're not familiar with JSF already, you're probably wondering how all of this is going to tie together... How does nameBean get into my JSP's and how do the input buttons on welcome.jsp get me to hello.jsp or bye.jsp? That's where we come back to the faces-config.xml file.

faces-config.xml

Create a file called  helloworld/WEB-INF/faces-config.xml  and copy the following into it:

<!DOCTYPE faces-config PUBLIC

  "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"

  "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">

 <faces-config>

            <navigation-rule>

                        <from-view-id>/welcome.jsp</from-view-id>

                        <navigation-case>

                                    <from-outcome>hello</from-outcome>

                                    <to-view-i>d>/hello.jsp</to-view-id>

                        </navigation-case>

                        <navigation-case>

                                    <from-outcome>bye</from-outcome>

                                    <to-view-id>/bye.jsp</to-view-id>

                        </navigation-case>

            </navigation-rule>
 
           
<managed-bean>

                        <managed-bean-name>nameBean</managed-bean-name>

                        <managed-bean-class>             

                                    com.developersBook.jsfApp.NameBean

                        </managed-bean-class>

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

            </managed-bean>

</faces-config>

faces-config sets up our navigation rules. In particular, if we're coming from /welcome.jsp and the "outcome" is "sayhello", go to the hello.jsp view; if the "outcome" is "bye", go to the bye.jsp view. The "outcome" is determined by the action property of the commandButton elements your "from-view", welcome.jsp.

Additionally, you can see we've created a managed-bean called nameBean that is an instance of our com.developersbook.jsfsample.NameBean class. nameBean has request scope, and is therefore available throughout processing of the entire request. Its properties can be accessed and set using the #{beanname.propertyname} convention, as shown in all three JSPs.

  Continued.....

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.