Package org.apache.struts.taglib.bean

The "struts-bean" tag library contains JSP custom tags useful in defining new beans (in any desired scope) from a variety of possible sources, as well as a tag to render a particular bean (or bean property) to the output response.

Class Summary

CookieTag Define a scripting variable based on the value(s) of the specified cookie received with this request.
CookieTei Implementation of TagExtraInfo for the cookie tag, identifying the scripting object(s) to be made visible.
DefineTag Define a scripting variable based on the value(s) of the specified bean property.
DefineTei Implementation of TagExtraInfo for the define tag, identifying the scripting object(s) to be made visible.
HeaderTag Define a scripting variable based on the value(s) of the specified header received with this request.
HeaderTei Implementation of TagExtraInfo for the header tag, identifying the scripting object(s) to be made visible.
IncludeTag Define the contents of a specified intra-application request as a page scope attribute of type java.lang.String.
IncludeTei Implementation of TagExtraInfo for the include tag, identifying the scripting object(s) to be made visible.
MessageTag Custom tag that retrieves an internationalized messages string (with optional parametric replacement) from the ActionResources object stored as a context attribute by our associated ActionServlet implementation.
PageTag Define a scripting variable that exposes the requested page context item as a scripting variable and a page scope bean.
PageTei Implementation of TagExtraInfo for the page tag, identifying the scripting object(s) to be made visible.
ParameterTag Define a scripting variable based on the value(s) of the specified parameter received with this request.
ParameterTei Implementation of TagExtraInfo for the parameter tag, identifying the scripting object(s) to be made visible.
ResourceTag Define a scripting variable based on the contents of the specified web application resource.
ResourceTei Implementation of TagExtraInfo for the resource tag, identifying the scripting object(s) to be made visible.
SizeTag Define a scripting variable that will contain the number of elements found in a specified array, Collection, or Map.
SizeTei Implementation of TagExtraInfo for the size tag, identifying the scripting object(s) to be made visible.
StrutsTag Define a scripting variable that exposes the requested Struts internal configuraton object.
StrutsTei Implementation of TagExtraInfo for the struts tag, identifying the scripting object(s) to be made visible.
WriteTag Tag that retrieves the specified property of the specified bean, converts it to a String representation (if necessary), and writes it to the current output stream, optionally filtering characters that are sensitive in HTML.
The "struts-bean" tag library contains JSP custom tags useful in defining new beans (in any desired scope) from a variety of possible sources, as well as a tag to render a particular bean (or bean property) to the output response.

[Introduction] [Bean Properties] [Bean Creation] [Bean Output]

Introduction

Much of the power of JavaServer Pages (JSP) technology comes from the simple and powerful mechanisms by which the servlet that is generated automatically from your JSP source page can interact with JavaBeans that represent the computational state of your application. In standard JSP pages, the <jsp:useBean> tag is used create a bean (if necessary), as well as a "scripting variable" that can be used within scriptlets to refer to these beans.

The "struts-bean" tag library provides substantial enhancements to the basic capability provided by <jsp:useBean>, as discussed in the following sections:

See the Bean Tags Reference for detailed information about the available tags in this tag library, and the valid attributes for each tag.
Bean Tag UML

Bean Properties

Common Tag Attributes

Property References

property

Simple References<jsp:getProperty><jsp:setProperty>getFoo()setFoo(value)BeanInfo http://java.sun.com/products/javabeans/

Nested References<bean:define>

    property="foo.bar.baz"

    getFoo().getBar().getBaz()

last

    getFoo().getBar().setBaz(value)

Indexed References<bean:define>

    property="foo[2]"

    getFoo(2);

    setFoo(2, value)

zero relativefoo[0]

Combined Referencesfoo.bar[0].baz[2]

PropertyUtils


Bean Creation

Introduction

Java Code in Action Classes

Action Action

Request ScopeAction

    Customer customer = ... create or acquire a customer reference ...;
request.setAttribute("cust", customer);

Session ScopeAction

    User user = ... look up valid user in the database ...;
HttpSession session = request.getSession();
session.setAttribute("user", user);

Application Scopeinit()Action

    Foo foo = ... create a Foo ...;
servlet.getServletContext().setAttribute("foo", foo);
Java Code in Scriptlets

Page Scope

<%
Foo foo = ... create a foo ...;
pageContext.setAttribute("foo", foo, PageContext.PAGE_SCOPE);
%>

Request Scope

<%
Customer customer = ... create or acquire a customer reference ...;
pageContext.setAttribute("cust", customer, PageContext.REQUEST_SCOPE);
%>

Session Scope

<%
User user = ... look up valid user in the database ...;
pageContext.setAttribute("user", user, PageContext.SESSION_SCOPE);
%>

Application Scopeinit()

<%
Foo foo = ... create a Foo ...;
pageContext.setAttribute("foo", foo, PageContext.APPLICATION_SCOPE);
%>

NOTEonlyAction

The Standard <jsp:useBean> Tag

<jsp:useBean>

must<jsp:useBean><jsp:getProperty> <jsp:setProperty><jsp:useBean>

<jsp:useBean> http://java.sun.com/products/jsp/download.html

The Struts <bean:define> Tag

<bean:define>above

Introduce A String Constant

    <bean:define id="foo" value="This is a new String"/>
<bean:define id="bar" value='<%= "Hello, " + user.getName() %>'/>
<bean:define id="last" scope="session"
value='<%= request.getRequestURI() %>'/>

Copy An Existing Beanjava.lang.Object

    <bean:define id="foo" name="bar"/>
<bean:define id="baz" name="bop" type="com.mycompany.MyBopClass"/>

Copy An Existing Bean Property

    <bean:define id="foo" name="bar" property="baz" scope="request"
toScope="session"/>
<bean:define id="bop" name="user" property="role[3].name"/>
Other Struts Copying Tags

Bean Tags Reference

Copy A Cookie javax.servlet.http.Cookie<logic:present cookie="xxx">

    <bean:cookie id="foo" name="cookiename"/>
<bean:cookie id="all" name="JSESSIONID" multiple="true"/>

Copy A Request Header<logic:present header="xxx">

    <bean:header id="agent" name="User-Agent"/>
<bean:header id="languages" name="Accept-Language" multiple="true"/>

Copy A Dynamically Created Response

    <bean:include id="text" name="/generateXml?param1=a&param2=b"/>

Copy A JSP Implicitly Defined Object

    <bean:page id="app" property="application"/>
<bean:page id="sess" property="session"/>

Copy A Request Parameter<logic:present parameter="xxx">

    <bean:parameter id="name" name="name"/>
<bean:header id="options" name="option" multiple="true"/>

Copy a Web Application Resourcejava.io.InputStreamServletContext.getResource()ServletContext.getResourceAsStream()

    <bean:resource id="deployment" name="/WEB-INF/web.xml"/>
<bean:resource id="stream" name="/WEB-INF/web.xml"
input="true"/>

Copy A Struts Configuration Object

    <bean:struts id="form" formBean="CustomerForm"/>
<bean:struts id="fwd" forward="success"/>
<bean:struts id="map" mapping="/saveCustomer"/>

Bean Output

Render An Internationalized Message MessageResources Bean Tags Reference

    <bean:message key="label.Cancel"/>
<bean:message key="message.hello" arg0='<%= user.getFullName() %>'/>

Render A Bean or Bean Property above

    <bean:write name="username"/>
<bean:write name="user" property="fullName"/>
<bean:write name="customer" property="orders[2].partNumber"
scope="session"/>

Copyright B) 2000-2007 - The Apache Software Foundation