Intent

Web application development with Language:Java and the Technology:Seam framework

Motivation

Technology:Seam provides a great support for the development of web applications in Language:Java with easy access control and an integrated persistence layer. It combines the popular Technology:JSF (please visit Contribution:jsf for more information) approach for UI programming with Technology:Hibernate and Technology:JPA. Both persistence technologies are directly integrated into the web-application framework.

Illustration

Technology:Seam is based on the three-tier architecture. Since the presentation is covered by Technology:JSF, the focus of the Seam framework is the business and data access layer. This section illustrates the major components of the Seam framework and introduces its rights management.

Presentation

The presentation layer is based on the MVC architecture, because it is the main architecture of the Technology:JSF framework. From this it follows, that the view consists of Technology:Facelets. We will start our presentation illustration with the first page of the application: the company view. It contains four parts, at which there are two textfields for the name and the total of the company and two buttons for the department list and the cut of the company. In theory, the view is designed to show more than one company, but this is not demanded by the feature model.

...


<rich:dataTable value="#{allCompanies}" var="c" width="300px">
	<rich:column>
		<f:facet name="header">Name</f:facet>
		
		<h:outputText value="#{c.name}" />
	</rich:column>
	<rich:column>
		<f:facet name="header">Total salaries</f:facet>
		
		<h:outputText value="#{c.total()}" />
	</rich:column>
	<rich:column>
		
		<s:button value="Show details" action="#{companyAction.showDetails()}" />
	</rich:column>
	<rich:column>
		
		<s:button value="Cut salaries" action="#{companyAction.cutSalaries()}" />
	</rich:column>
</rich:datatable>

...

The

<rich:dataTable ...> ... </rich:datatable>
tags create a new Language:HTML table with a predefined
width="300px"
. The value
"#{allCompanies}"
maps the table rows to the
allCompanies
list contained in the class CompanyAction.java. Each entry has a corresponding table row. The attribute
var="c"
helps to access one object of the list and get its informations. As mentioned above, the table has four columns: name, total, detail button and cut button. Each column is created by the use of the tags
<rich:column> ... </rich:column>
. The methods of the class CompanyAction.java are directly accessed via the actions of the buttons, for example in
<s:button value="Cut salaries" action="#{companyAction.cutSalaries()}"/>
. CompanyAction is a Technology:Java Bean, which receives the requests of the facelets.

The following example illustrates the

cutSalaries()
method implemented by the class CompanyAction.java:

...

public String cutSalaries() {
	try {
		// The method cuts the salaries for the selected company.
		companyService.cutSalaries(selectedCompany);
		// If the call is successful, a corresponding message is displayed.
		facesMessages.add(FacesMessage.SEVERITY INFO, "The cut salary operation was successfully applied.");
	}
	catch(Exception e) {
		// If an exception occures, an error message is displayed.
		facesMessages.add(FacesMessage.SEVERITY ERROR, "Error when trying to cut salaries. " + e.getMessage());
		e.printStackTrace();
	}
	// The framework expects a view name for loading the next view. If this name is 'null', the current view will reloads.
	return null;
}

...

The action invokes the

cutSalaries(selectedCompany)
method of the CompanyService and additionaly manages the loading of further pages. If an exception occurs, it returns an error message to the facelet. The
null
return value simply means, that the current view has to be reloaded.

Business and Data access

The business layer manages the access control of the application. In addition, it is connected to the persistence layer, which is implemented with Technology:JPA. On cut, the following method of the service class CompanyService is invoked:

...

// The annotation manages the access control for this method.
@Restrict("#{s:hasRole('admin')}") 
public void cutSalaries(Company company) {
	company.cut();
	entityManager.merge(company);
}

...

A simple annotation

@Restrict
provides access controll for the different users. The annotated method is restricted to a user or a group of users, in this case to the "admin" user. The cut is performed within the company object directly. The
entityManager
manages the company entities and provides an easy merge mechanism for all contained entities. In this case all manipulated employees of this company are merged automatically without explicit call.

Architecture

There are some necessary configuration files like the build.xml and the build.properties. Apart from that, everything else is generated or part of the libraries.

Usage

This application requires the Technology:Eclipse and Technology:JBoss Application Server (Version 4.2.x). After downloading and installing both, follow these steps:

  • Import the seam project from your file system to Technology:Eclipse as a java project.
  • Change the this!!build.properties file located in the projects base folder. The jboss.home-property must refer to your Technology:JBoss Application Server location: jboss.home = <your></your>.
  • Run the seam project as ant build in eclipse (Right click on the build.xml file -> Run As -> Ant Script).
  • Start JBoss using either <your>/bin/run.bat for Windows OS or &lt;your&gt;&lt;/your&gt&lt;/bin/run.sh&gt;</your>for Unix OS.
  • Start a Web browser and go to http://localhost:8080/seam
It is possible to access the system with two different users: "admin" (Password: "admin") and "user" (Password: "user"). If you are logged in as "admin", you are allowed to visit all departments and employees contained in the company and cut all salaries. If you are logged in as "user", you are only allowed to visit all elements of the company but not to cut salaries.


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.