Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
Course Overview
Unit 1 - Model-View-Controller Design
Pattern
Unit 2 - Model Components
Unit 3 - View Components
Unit 4 - Controller Components
Unit 5 - Tag Libraries
Unit 1
Unit 2
Enterprise JavaBeans
ActionForm Beans
Extends the ActionForm class
Create one for each input form in the application
If defined in the ActionMapping configuration file,
the Controller Servlet will perform the following:
Check session for instance of bean of appropriate class
If no session bean exists, one is created automatically
For every request parameter whose name corresponds
to the name of a property in the bean, the corresponding
setter method will be called
The updated ActionForm bean will be passed to the
Action Class perform() method when it is called, making
these values immediately available
Continued
Define a property (with associated getXxx() and
setXxx() methods) for each field that is present in
the form. The field name and property name must
match according to the usual JavaBeans
conventions
Place a bean instance on your form, and use
nested property references. For example, you
have a "customer" bean on your Action Form, and
then refer to the property "customer.name" in your
JSP view. This would correspond to the methods
customer.getName() and customer.setName(string
Name) on your customer bean
Project Refinery, Inc. 14
STRUTS Model Components
Unit 3
Internationalized Messages
Struts builds upon Java platform to provide
assistance for building internationalized and localized
applications
Locale - fundamental Java class that supports
internationalization
ResourceBundle - supports messages in multiple languages
PropertyResourceBundle - standard implementation of
ResourceBundle that allows you to define resources using the
same "name=value" syntax used to initialize properties files
MessageFormat - allows you to replace portions of a
message string with arguments specified at run time
MessageResources - lets you treat a set of resource bundles
like a database, and allows you to request a particular
message string for a particular Locale
Project Refinery, Inc. 20
STRUTS View Components
ApplicationResources.properties
Contains the messages in the default
language for your server. If your default
language is English, you might have an
entry like this: prompt.hello=Hello
ApplicationResources_xx.properties
Contains
the same messages in the
language whose ISO language code is "xx"
Unit 4
Action Classes:
The Action class defines a perform method
that you override
public ActionForward perform(ActionMapping
mapping, ActionForm form, HttpServletRequest
request, HttpServletResponse response) throws
IOException, ServletException;
<form-beans>
This section contains your form bean
definitions. You use a <form-bean> element for
each form bean, which has the following
important attributes:
z name: The name of the request or session level
attribute that this form bean will be stored as
z type: The fully-qualified Java classname of your form
bean
<action-mappings>
This section contains your action definitions. You
use an <action> element for each of your actions
you would like to define. Each action element has
requires the following attributes to be defined:
path: The application context-relative path to the action
type: The fully qualified java classname of your Action
class
name: The name of your <form-bean> element to use
with this action
The
Web Application Deployment
Descriptor
The final step in setting up the application
is to configure the application deployment
descriptor (stored in file WEB-INF/web.xml)
to include all the Struts components that
are required
Unit 5
HTML Tags
Bean Tags
Logic Tags
Template Tags
Custom Tags
cookie Define a scripting variable based on the value(s) of the specified request cookie.
define Define a scripting variable based on the value(s) of the specified bean property.
header Define a scripting variable based on the value(s) of the specified request header.
include Load the response from a dynamic application request and make it available as a bean.
parameter Define a scripting variable based on the value(s) of the specified request parameter.
write Render the value of the specified bean property to the current JspWriter.
empty Evaluate the nested body content of this tag if the requested variable is either null or an empty string.
equal Evaluate the nested body content of this tag if the requested variable is equal to the specified value.
forward Forward control to the page specified by the specified ActionForward entry.
greaterEqual Evaluate the nested body content of this tag if requested variable is greater than or equal to specified value.
greaterThan Evaluate the nested body content of this tag if the requested variable is greater than the specified value.
iterate Repeat the nested body content of this tag over a specified collection.
lessEqual Evaluate the nested body content of this tag if requested variable is greater than or equal to specified value.
lessThan Evaluate the nested body content of this tag if the requested variable is less than the specified value.
match Evaluate the nested body content of this tag if specified value is an appropriate substring of requested variable.
messagesNotPresent Generate the nested body content of this tag if the specified message is not present in this request.
messagesPresent Generate the nested body content of this tag if the specified message is present in this request.
notEmpty Evaluate the nested body content of this tag if the requested variable is neither null nor an empty string.
notEqual Evaluate the nested body content of this tag if the requested variable is not equal to the specified value.
notMatch Evaluate the nested body content of tag if specified value not an appropriate substring of requested variable.
notPresent Generate the nested body content of this tag if the specified value is not present in this request.
present Generate the nested body content of this tag if the specified value is present in this request.
Unit 6
Unit 7
<taglib>
<taglib-uri>WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>WEB-INF/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
</taglib>
</web-app>
Unit 8
Unit 9