<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>All Free Tech &#187; JBoss</title>
	<atom:link href="http://www.allfreetech.com/tag/jboss/feed" rel="self" type="application/rss+xml" />
	<link>http://www.allfreetech.com</link>
	<description>For developers</description>
	<lastBuildDate>Tue, 01 Feb 2011 13:45:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Creating a Web Application on JBoss AS 5</title>
		<link>http://www.allfreetech.com/ebook/java/creating-a-web-application-on-jboss-as-5-136.html</link>
		<comments>http://www.allfreetech.com/ebook/java/creating-a-web-application-on-jboss-as-5-136.html#comments</comments>
		<pubDate>Sun, 24 Jan 2010 08:14:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.allfreetech.com/?p=136</guid>
		<description><![CDATA[In this two-part article by Francesco Marchioni, we will be developing and configuring web applications using JBoss web container. Most developers have surely gained some experience with web applications. Therefore, we will not cover the basics of web applications; we will rather disclose how easy it can be to create a consistent web layer for [...]]]></description>
			<content:encoded><![CDATA[<p>In this two-part article by <b>Francesco Marchioni</b>, we will be developing and configuring web applications using JBoss web container. Most developers have surely gained some experience with web applications. Therefore, we will not cover the basics of web applications; we will rather disclose how easy it can be to create a consistent web layer for your applications, using just the right tools and, of course, the right technique.<span id="more-136"></span></p>
<p>We will cover the following topics in more detail:</p>
<ul>
<li>What is JSF and how to install it on JBoss AS</li>
<li>How to create a JSF facade for our pasture application</li>
<li>How to configure JBoss Web Server</li>
</ul>
<p style="margin-left: 40px; margin-right: 40px;">Wonder what was the first message sent through Internet? At 22:30 hours on October 29, 1969, a message was transmitted using ARPANET (the predecessor of the global Internet) on a host-to-host connection. It was meant to transmit &quot;login&quot;. However, it transmitted just &quot;lo&quot; and crashed.</p>
<h1>Developing web layout</h1>
<p>The basic component of any Java web application is the servlet. Born in the middle of the 90s, servlets quickly gained success against their competitors, the CGI scripts. This was because of some innovative features, especially the ability to execute requests concurrently, without the overhead of creating a new process for each request. However, a few things were missing, for example, the <b>servlet API</b> did not address any APIs specifically for creating the client GUI. This resulted in multiple ways of creating the presentation tier, generally with tag libraries that differed from job to job and from individual developers.</p>
<p>The second thing that was missing in the servlet specification was a clear distinction between the presentation tier and the backend. A plethora of web frameworks tried to fill this gap; particularly the <b>Struts</b> framework effectively realized a clean separation of the <b>model</b> (application logic that interacts with a database) from the <b>view</b> (HTML pages presented to the client) and the <b>controller</b> (instance that passes information between view and model).</p>
<p>However, the limitation of these frameworks was that even if they realized a complete modular abstraction, they still failed as they always exposed the<i>HttpServletRequest</i> and <i>HttpServletSession</i>objects to their action(s). Their actions, in turn, needed to accept the interface contracts such as <i>ActionForm</i>,<i> ActionMapping</i>, and so on.</p>
<p>The JavaServer Faces that emerged on the stage a few years later pursued a different approach. Unlike request-driven <b>Model&ndash;View&ndash;Controller (MVC)</b> web frameworks, JSF chose a component-based approach that ties the user interface component to a well-defined request processing lifecycle. This greatly simplifies the development of web applications.</p>
<p>The JSF specification allows you to have presentation components be POJOs. This creates a cleaner separation from the servlet layer and makes it easier to do testing by not requiring the POJOs to be dependent on the servlet classes.</p>
<p>In the following sections, we will describe how to create a web layout for our application store using the JSF technology. For an exhaustive explanation of the JSF framework, we suggest you to surf the JSF homepage at <a href="http://java.sun.com/javaee/javaserverfaces/" target="_blank">http://java.sun.com/javaee/javaserverfaces/</a>.</p>
<h2>Installing JSF on JBoss AS</h2>
<p>JBoss AS already ships with the JSF libraries, so the good news is that you don&#39;t need to download or install them in the application server. There are different implementations of the JSF libraries. Earlier JBoss releases adopted the <b>Apache MyFaces</b> library. JBoss AS 4.2 and 5.x ship with the <b>Common Development and Distribution License</b> (<b>CDDL</b>) implementation (now called &quot;Project Mojarra&quot;) of the JSF 1.2 specification that is available from the java.net open source community.</p>
<p style="margin-left: 40px; margin-right: 40px;"><em>Switching to another JSF implementation is anyway possible. All you have to do is package your JSF libraries with your web application and configure your <i>web.xml</i> to ignore the JBoss built-in implementation:</em></p>
<pre style="margin-left: 40px;">&lt;context-param&gt;
&lt;param-name&gt;org.jboss.jbossfaces.WAR_BUNDLES_JSF_
IMPL&lt;/param-name&gt;
&lt;param-value&gt;true&lt;/param-value&gt;
&lt;/context-param&gt;
</pre>
<p>We will start by creating a new JSF project. From the <b>File</b> menu, select <b>New</b> | <b>Other</b> | <b>JBoss Tools Web</b> | <b>JSF</b> | <b>JSF Web project</b>. The JSF applet wizard will display, requesting the <b>Project Name</b>, the <b>JSF Environment</b>, and the default starting <b>Template</b>.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article1-image01.png" /></p>
<p>Choose <b>AppStoreWeb</b> as the project name, and check that the <b>JSF Environment</b> used is <b>JSF 1.2</b>. You can leave all other options to the defaults and click <b>Finish</b>. Eclipse will now suggest that you switch to the <b>Web Projects</b> view that logically assembles all JSF components. (It seems that the current release of the plugin doesn&#39;t understand your choice, so you have to manually click on the <b>Web Projects</b> tab.)</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article1-image02.png" /></p>
<p>The key configuration file of a JSF application is faces-config.xml contained in the Configuration folder. Here you declare all <b>navigation rules</b> of the application and the <b>JSF managed beans</b>. Managed beans are simple POJOs that provide the logic for initializing and controlling JSF components, and for managing data across page requests, user sessions, or the application as a whole.</p>
<p>Adding JSF functionalities also requires adding some information to your <i>web.xml</i> file so that all requests ending with a certain suffix are intercepted by the <i>Faces Servlet</i>. Let&#39;s have a look at the <i>web.xml</i> configuration file:</p>
<pre style="margin-left: 40px;">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;web-app version=&quot;2.5&quot; xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;&gt;

&lt;display-name&gt;AppStoreWeb&lt;/display-name&gt;
&lt;context-param&gt;
&lt;param-name&gt;javax.faces.STATE_SAVING_METHOD&lt;/param-name&gt;
&lt;param-value&gt;server&lt;/param-value&gt;
&lt;/context-param&gt;
&lt;context-param&gt; [1]
&lt;param-name&gt;com.sun.faces.
enableRestoreView11Compatibility&lt;/param-name&gt;
&lt;param-value&gt;true&lt;/param-value&gt;
&lt;/context-param&gt;
&lt;listener&gt;
&lt;listener-class&gt;com.sun.faces.config.
ConfigureListener&lt;/listener-class&gt;
&lt;/listener&gt;
&lt;!-- Faces Servlet --&gt;
&lt;servlet&gt;
&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
&lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
&lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
&lt;/servlet&gt;
&lt;!-- Faces Servlet Mapping --&gt;
&lt;servlet-mapping&gt;
&lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
&lt;url-pattern&gt;*.jsf&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;
&lt;login-config&gt;
&lt;auth-method&gt;BASIC&lt;/auth-method&gt;
&lt;/login-config&gt;
&lt;/web-app&gt;
</pre>
<p style="margin-left: 40px; margin-right: 40px;"><em>The context-param pointed out here <b>[1]</b> is not added by default when you create a JSF application. However, it needs to be added, else you&#39;ll stumble into an annoying ViewExpiredException when your session expires (JSF 1.2).</em></p>
<h2>Setting up navigation rules</h2>
<p>In the first step, we will define the navigation rules for our AppStore. A minimalist approach would require a homepage that displays the orders, along with two additional pages for inserting new customers and new orders respectively.</p>
<p>Let&#39;s add the following navigation rule to the <i>faces-config.xml</i>:</p>
<pre style="margin-left: 40px;">&lt;faces-config&gt;
&lt;navigation-rule&gt;
&lt;from-view-id&gt;/home.jsp&lt;/from-view-id&gt; [1]
&lt;navigation-case&gt;
&lt;from-outcome&gt;newCustomer&lt;/from-outcome&gt; [2]
&lt;to-view-id&gt;/newCustomer.jsp&lt;/to-view-id&gt;
&lt;/navigation-case&gt;
&lt;navigation-case&gt;
&lt;from-outcome&gt;newOrder&lt;/from-outcome&gt; [3]
&lt;to-view-id&gt;/newOrder.jsp&lt;/to-view-id&gt;
&lt;/navigation-case&gt;
&lt;/navigation-rule&gt;
&lt;navigation-rule&gt;
&lt;from-view-id&gt;&lt;/from-view-id&gt; [4]
&lt;navigation-case&gt;
&lt;from-outcome&gt;home&lt;/from-outcome&gt;
&lt;to-view-id&gt;/home.jsp&lt;/to-view-id&gt;
&lt;/navigation-case&gt;
&lt;/navigation-rule&gt;
&lt;/faces-config&gt;
</pre>
<p>In a navigation rule, you can have one <i>from-view-id</i> that is the (optional) starting page, and one or more landing pages that are tagged as <i>to-view-id</i>. The <i>from-outcome</i> determines the navigation flow. Think about this parameter as a Struts forward, that is, instead of embedding the landing page in the JSP/servlet, you&#39;ll simply declare a virtual path in your JSF beans.</p>
<p>Therefore, our starting page will be <i>home.jsp</i> <b>[1]</b> that has two possible links&mdash;the <i>newCustomer.jsp</i> form <b>[2]</b> and the <i>newOrder.jsp</i> form <b>[3]</b>. At the bottom, there is a navigation rule that is valid across all pages <b>[4]</b>. Every page requesting the home outcome will be redirected to the homepage of the application.</p>
<p>The above JSP will be created in a minute, so don&#39;t worry if Eclipse validator complains about the missing pages. This configuration can also be examined from the <b>Diagram</b> tab of your <i>faces-config.xml</i>:</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article1-image03.png" /></p>
<p>The next piece of code that we will add to the confi guration is the JSF managed bean declaration. You need to declare each bean here that will be referenced by JSF pages. Add the following code snippet at the top of your <i>faces-config.xml</i> (just before navigation rules):</p>
<pre style="margin-left: 40px;">&lt;managed-bean&gt;
&lt;managed-bean-name&gt;manager&lt;/managed-bean-name&gt; [1]
&lt;managed-bean-class&gt;
com.packpub.web.StoreManagerJSFBean
&lt;/managed-bean-class&gt; [2]
&lt;managed-bean-scope&gt;request&lt;/managed-bean-scope&gt; [3]
&lt;/managed-bean&gt;
</pre>
<p>The <i>&lt;managed-bean-name&gt;</i> <b>[1]</b> element will be used by your JSF page to reference your beans. The <i>&lt;managed-bean-class&gt;</i> <b>[2]</b> is obviously the corresponding class. The managed beans can then be stored within the request, session, or application scopes, depending on the value of the <i>&lt;managed-bean-scope&gt;</i> element <b>[3]</b>.</p>
<h2>Adding a JSF managed bean</h2>
<p>The <i>StoreManagerJSFBean</i> class follows the JavaBean patterns, providing get and <i>set</i> methods for its properties (to make the code more maintainable, we have skipped the <i>getter</i>/<i>setter</i> methods that simply wrap the fields of the class). We have declared the bean as request bound, so for each user of the application, JSF creates a <i>StoreManagerJSFBean</i> instance, which is stored within the <i>request</i> scope.</p>
<p>Add to your project a new Java class and name it <i>com.packtpub.web.StoreManagerJSFBean</i>:</p>
<pre style="margin-left: 40px;">package com.packpub.web;
// skipping imports
public class StoreManagerJSFBean {
@EJB(mappedName = &quot;AppStoreEJB/local&quot;) [1]
private StoreManager storeManager;
private int customerId;
private int orderQuantity;
private int orderPrice;
private String customerName;
private String customerCountry;
private String orderProduct;
List&lt;Order&gt; listOrders;
List &lt;SelectItem&gt; listCustomers;
public List&lt;SelectItem&gt; getListCustomers() {
if (listCustomers == null) {
listCustomers= new ArrayList();
findAllCustomers();
}
return listCustomers;
}
/*
other getter/setter methods omitted for brevity
*/
public StoreManagerJSFBean() { }
public void findOrders() { [2]
listOrders = storeManager.findAllItems(this.customerId);
}
public void findAllCustomers() {
List&lt;Customer&gt; listCustomersEJB =
storeManager.findAllCustomers();
for(Customer customer:listCustomersEJB) {
listCustomers.add(new
SelectItem(customer.getId(),customer.getName()));
}
}
}
public void saveOrder() {
storeManager.saveOrder(customerId,this.orderPrice,
this.orderQuantity,this.orderProduct);
FacesMessage fm = new FacesMessage(&quot;Saved order for
&quot;+this.orderQuantity+ &quot; of &quot;+this.orderProduct);
FacesContext.getCurrentInstance().addMessage(&quot;Message&quot;, fm);
this.orderPrice=0;
this.orderQuantity=0;
this.orderProduct=null;
}
public void insertCustomer() {
storeManager.createCustomer(this.customerCountry,
this.customerName);
FacesMessage fm = new FacesMessage(&laquo;Created Customer
&laquo;+this.customerName+ &laquo; fromf &laquo;+this.customerCountry);
FacesContext.getCurrentInstance().addMessage(&quot;Message&quot;, fm);
this.customerName=null;
this.customerCountry=null;
// Forces customer reloading
this.listCustomers=null;
}
/* Navigation rules */
public String home() { [4]
return &quot;home&quot;;
}
public String newOrder() {
return &quot;newOrder&quot;;
}
public String newCustomer() {
return &quot;newCustomer&quot;;
}
}
</pre>
<p>As you can see, the <i>StoreManagerJSFBean</i> references the session bean we have created previously (<i>StoreManager</i>). Therefore, we must tell the compiler how to solve this dependency. This can be easily solved by choosing <b>Properties</b> on the current project, and then choosing Projects from the <b>Java Build Path</b> option. Add the project <b>AppStore</b> to your build path, as shown here:</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article1-image04.png" /></p>
<p>Having fixed the compilation issues, we can now concentrate on the JSF bean. The first thing we want to capture your attention to is how the <i>StoreManager</i> EJB is injected <b>[1]</b> in the class, skipping completely the lookup/casting/exception handling part.</p>
<p>The <i>findOrders()</i> method <b>[2]</b> retrieves the list of orders from the <i>StoreManager</i> EJB. They will be displayed later in the <i>dataTable </i>component.</p>
<p>The <i>findAllCustomers()</i> <b>[3]</b> is slightly different. It recalls our entity bean&#39;s corresponding <i>findAllCustomers()</i> method and then populates a <i>SelectItem</i> object with the list of customers. <i>SelectItem</i> is a JSF object used to render a combobox programmatically. In our case, we will populate it with the <i>customerId</i> (as value) and <i>customerName</i> (as label).</p>
<p>The remaining EJB wrapper methods, <i>saveOrder()</i> and <i>insertCustomer()</i>, are quite intuitive; their job is to persist data for <i>Orders</i> and <i>Customers</i>.</p>
<p>The final piece of code is about navigation rules <b>[4]</b> that are coded as simple Java methods returning the outcome view as a string. For example, in order to return to the homepage from any other page, we will add the following button:</p>
<pre style="margin-left: 40px;">&lt;h:commandButton action=&quot;#{manager.home}&quot; value=&quot;Back&quot; /&gt;
</pre>
<h2>Setting up the view</h2>
<p>Setting up the view JSF pages are just behind-the-scenes JSP pages that are engineered by the JSF servlet. Therefore, in order to create your views, add the following pages to your web application: <i>home.jsp</i>, <i>newCustomer.jsp</i> and <i>newOrder.jsp</i>. A new JSP page can be added from the <b>Web Projects</b> menu by right-clicking on the <i>WebContent</i> folder, then choosing <b>New</b> | <b>File</b> | <b>JSP Page</b> and naming it <i>home.jsp</i>.</p>
<pre style="margin-left: 40px;">&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%&gt; [1]
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%&gt;
&lt;html&gt;
&lt;body&gt;
&lt;f:view&gt; [2]
&lt;style type=&quot;text/css&quot;&gt; [3]
@import url(&quot;css/appstore.css&quot;);
&lt;/style&gt;
&lt;h:panelGrid columns=&quot;1&quot; border=&quot;1&quot; styleClass=&quot;spring&quot;&gt; [4]
&lt;f:facet name=&quot;header&quot;&gt;
&lt;h:outputText value=&quot;Order List&quot;/&gt;
&lt;/f:facet&gt;
&lt;h:form id=&quot;listOrdersForm&quot;&gt; [5]
&lt;h:outputText value=&quot;Select Customer:&quot; /&gt; [6]
&lt;h:selectOneMenu id=&quot;selectCustomer&quot;
value=&quot;#{manager.customerId}&quot; styleClass=&quot;buttons&quot;&gt; [7]
&lt;f:selectItems
value=&quot;#{manager.listCustomers}&quot; /&gt;
&lt;/h:selectOneMenu&gt;
&lt;h:commandButton action=&quot;#{manager.findOrders}&quot;
value=&quot;ListOrders&quot; styleClass=&quot;buttons&quot;/&gt; [8]
&lt;h:dataTable value=&quot;#{manager.listOrders}&quot; var=&quot;orders&quot;
border=&quot;1&quot; rowClasses=&quot;row1, row2&quot; headerClass=&quot;header&quot;&gt; [9]
&lt;h:column&gt;
&lt;f:facet name=&quot;header&quot;&gt;
&lt;h:outputText value=&quot;Product&quot; /&gt;
&lt;/f:facet&gt;
&lt;h:outputText value=&quot;#{orders.product}&quot; /&gt;
&lt;/h:column&gt;
&lt;h:column&gt;
&lt;f:facet name=&quot;header&quot;&gt;
&lt;h:outputText value=&quot;Price&quot; /&gt;
&lt;/f:facet&gt;
&lt;h:outputText value=&quot;#{orders.price}&quot; /&gt;
&lt;/h:column&gt;
&lt;h:column&gt;
&lt;f:facet name=&quot;header&quot;&gt;
&lt;h:outputText value=&quot;Quantity&quot; /&gt;
&lt;/f:facet&gt;
&lt;h:outputText value=&quot;#{orders.quantity}&quot; /&gt;
&lt;/h:column&gt;
&lt;/h:dataTable&gt;
&lt;h:commandButton action=&quot;#{manager.newCustomer}&quot;
value=&quot;Insert Customer&quot; styleClass=&quot;buttons&quot; /&gt; [10]
&lt;h:commandButton action=&quot;#{manager.newOrder}&quot;
value=&quot;Insert Order&quot; styleClass=&quot;buttons&quot; /&gt; [11]
&lt;/h:form&gt;
&lt;/h:panelGrid&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>JSF contains two tag libraries <b>[1]</b> called JSF core and HTML Basic. The former provides a few general tags and some other tags that let you register validators and event listeners to UI components. The latter contains JSP tags that render HTML UI components such as buttons, text fields, checkboxes, lists, and so on. The standard prefixes of these two tag libraries are <i>h</i> and <i>f</i>, and they are declared at the beginning of <i>home.jsp</i>.</p>
<p>The <i>view</i> tag <b>[2]</b> is the container for all JavaServer Faces component tags used on a page. <b>Stylesheets [3]</b> are used here to decorate the UI components. The <i>panelGrid</i> <b>[4]</b> component simplifies the task of constructing a layout table, to hold form fields, labels, and buttons. In this case, it will contain the main input form.</p>
<p>The <i>form</i> element <b>[5]</b> manages an HTML form just the same way as standard form HTML. Rendering simple text on the page can be achieved with an <i>outputText </i>tag <b>[6]</b>. Here, you can use value-binding expressions from your JSF beans.</p>
<p>The <i>selectOneMenu</i> element <b>[7]</b> is used to display an HTML combobox that is bound to a bean collection. Review the <i>findAllCustomers()</i> method of your <i>StoreManagerJSFBean</i>, where the combobox is built dynamically.</p>
<p>The <i>commandButton</i> <b>[8]</b> is applied to render an HTML button. In our case, we have bound the button to the <i>findOrders()</i> method of our JSF bean.</p>
<p>A core JSF tag is the <i>dataTable</i> tag <b>[9]</b> that can be used to render an HTML table using a collection from the backing bean. This component is generally used to display tabular data and it offers a vast choice of built-in options for customizing its header and footer, and for paginating the table.</p>
<p>The last two buttons, <b>[10]</b> and <b>[11]</b>, plot the route to the <i>newCustomer</i> and <i>newOrder</i> forms.</p>
<p>The form for inserting a new customer is as follows:</p>
<pre style="margin-left: 40px;">&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%&gt;
&lt;html&gt;
&lt;body&gt;
&lt;f:view&gt;
&lt;style type=&quot;text/css&quot;&gt;
@import url(&quot;css/appstore.css&quot;);
&lt;/style&gt;
&lt;h:form id=&quot;newCustomer&quot;&gt;
&lt;h:panelGrid columns=&quot;2&quot; border=&quot;1&quot; styleClass=&quot;spring&quot;&gt;
&lt;f:facet name=&quot;header&quot;&gt;
&lt;h:outputText value=&quot;Insert new Customer&quot; /&gt;
&lt;/f:facet&gt;
&lt;h:outputText value=&quot;Name&quot; /&gt;
&lt;h:inputText value=&quot;#{manager.customerName}&quot; /&gt; [1]
&lt;h:outputText value=&quot;Country&quot; /&gt;
&lt;h:inputText value=&quot;#{manager.customerCountry}&quot; /&gt;
&lt;h:commandButton action=&quot;#{manager.insertCustomer}&quot; [2]
value=&quot;Insert Customer&quot; /&gt;
&lt;h:commandButton action=&quot;#{manager.home}&quot; value=&quot;Back&quot; /&gt;
&lt;/h:panelGrid&gt;
&lt;h:messages /&gt;
&lt;/h:form&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p>The <i>inputText</i> fields <b>[1]</b> are used to populate the individual managed bean properties. With the <i>commandButton</i> <b>[2]</b>, the <i>insertCustomer()</i> action is recalled, thus inserting a new customer. This is the last JSP needed for our example <i>newOrder.jsp</i>:</p>
<pre style="margin-left: 40px;">&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/html&quot; prefix=&quot;h&quot;%&gt;
&lt;%@ taglib uri=&quot;http://java.sun.com/jsf/core&quot; prefix=&quot;f&quot;%&gt;
&lt;html&gt;
&lt;body&gt;
&lt;f:view&gt;
&lt;style type=&quot;text/css&quot;&gt;
@import url(&quot;css/appstore.css&quot;);
&lt;/style&gt;
&lt;h:form id=&quot;newOrder&quot;&gt;
&lt;h:panelGrid columns=&quot;2&quot; border=&quot;1&quot; styleClass=&quot;spring&quot;&gt;
&lt;f:facet name=&quot;header&quot;&gt;
&lt;h:outputText value=&quot;Insert new Order&quot; /&gt;
&lt;/f:facet&gt;
&lt;h:outputText value=&quot;Product&quot; /&gt;
&lt;h:inputText value=&quot;#{manager.orderProduct}&quot; /&gt;
&lt;h:outputText value=&quot;Quantity&quot; /&gt;
&lt;h:inputText value=&quot;#{manager.orderQuantity}&quot; /&gt;
&lt;h:outputText value=&quot;Price&quot; /&gt;
&lt;h:inputText value=&quot;#{manager.orderPrice}&quot; /&gt;
&lt;h:outputText value=&quot;Customer&quot; /&gt;
&lt;h:selectOneMenu id=&quot;selectCustomerforOrder&quot;
value=&quot;#{manager.customer}&quot;&gt;
&lt;f:selectItems value=&quot;#{manager.listCustomers}&quot; /&gt;
&lt;/h:selectOneMenu&gt;
&lt;h:commandButton action=&quot;#{manager.saveOrder}&quot;
value=&quot;Save Order&quot; /&gt;
&lt;h:commandButton action=&quot;#{manager.home}&quot; value=&quot;Back&quot; /&gt;
&lt;/h:panelGrid&gt;
&lt;h:messages /&gt;
&lt;/h:form&gt;
&lt;/f:view&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h2>Assembling and deploying the application</h2>
<p>So far, you have got two standalone projects, one EJB project and one web project. While you could technically deploy them separately, it is worth combining them in an <b>Enterprise ARchive</b> (<b>EAR</b>). The most obvious reason for deploying the application as an Enterprise ARchive is that the web application will be loaded by a <i>ClassLoader</i> in the same hierarchy as the EJB classloader. In short, you don&#39;t need to provide the EJB interfaces to the web application, as you would for a standalone application.</p>
<p>Packaging the application can be done entirely by Eclipse, without messing with archive files. From the menu, select <b>New</b> | <b>Other</b> | <b>Java EE</b> | <b>Enterprise Application project</b>. The next facet will request the <b>Project name</b> and a few details about the configuration. Your archive name will be, by default, the project name plus the extension <i>.ear</i>. Verify that both <b>Target Runtime</b> and the <b>Configuration</b> point correctly to the JBoss 5.0 environment.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article1-image05.png" /></p>
<p>Click <b>Next</b>. On the window that follows, you can select the components of your archive application, that is, the <b>AppStore</b> application and the <b>AppStoreWeb</b> component. Check the option <b>Generate Deployment Descriptor</b>.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article1-image06.png" /></p>
<p>Verify that <i>META-INF/application.xml</i> deployment descriptors contain both the modules enlisted below:</p>
<pre style="margin-left: 40px;">&lt;application&gt;
&lt;display-name&gt;EnterpriseStore&lt;/display-name&gt;
&lt;module&gt;
&lt;web&gt;
&lt;web-uri&gt;AppStoreWeb.war&lt;/web-uri&gt;
&lt;context-root&gt;AppStoreWeb&lt;/context-root&gt;
&lt;/web&gt;
&lt;/module&gt;
&lt;module&gt;
&lt;ejb&gt;AppStore.jar&lt;/ejb&gt;
&lt;/module&gt;
&lt;/application&gt;
</pre>
<p>Okay, now you need only a few more laps to complete the race. Let&#39;s deploy the process to JBoss by switching on the <b>JBoss Server View</b>. Right-click on the JBoss server and select <b>Add and remove projects</b>. Add the <b>EnterpriseStore</b> to the configured projects.</p>
<p>Now deploy the application in the usual way. Right-click on the <b>EnterpriseStore</b> and select <b>Full Publish</b> (at the time of writing, JBoss 5 doesn&#39;t support partial deployment of this component).</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article1-image07.png" /></p>
<p>Verify from the console that the application has been deployed correctly.</p>
<h3>Running the store</h3>
<p>The application gateway will be <i>home.jsf</i> page. Point the browser to the location <i>http://localhost:8080/AppStoreWeb/home.jsf</i>.</p>
<p>Testing the application is quite simple. First add some customers and then link some orders to the customers. In the <i>home.jsf</i> page, check that the orders are correctly listed from the datagrid.</p>
<p style="text-align: center;"><img src="http://www.packtpub.com/files/images/jboss5-article1-image08.png" /></p>
<p style="margin-left: 40px; margin-right: 40px;"><em><b>A last trick</b><br />
	Usually web applications ship with a <b>welcome file list</b> so that you don&#39;t have to remember anything else besides the web context. If you have already tried to add home.jsf to the welcome file list (in web.xml), you would have noticed that it doesn&#39;t work. Actually, Tomcat is a bit stubborn and requires a trick to set a JSF page as a welcome file. First, add the following to your web.xml:</em></p>
<pre style="margin-left: 40px;">&lt;welcome-file-list&gt;
&lt;welcome-file&gt;home.jsf&lt;/welcome-file&gt;
&lt;/welcome-file-list&gt;
</pre>
<p style="margin-left: 40px; margin-right: 40px;"><em>Then create an empty <i>home.jsf</i> page in your web context root. This will trick Tomcat to detect <i>home.jsf</i> as the welcome file and will load <i>home.jsp</i> instead.</em></p>
<h1>Summary</h1>
<p>This two-part article on creating a web application is about developing and configuring web applications on JBoss AS 5.0 using the JSF cutting-edge technology. In this part of the article we have enhanced the Appstore Enterpirse application by adding a web layer to it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.allfreetech.com/ebook/java/creating-a-web-application-on-jboss-as-5-136.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

