You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by "Young, Wayne" <WY...@metasolv.com> on 2001/05/02 16:43:02 UTC

possible contributions to struts? code attached!

I've been developing some custom tags for our framework that runs with
Struts. Eventually, we would like to see this OR some similar functionality
incorporated into Struts. THE SOURCE CODE IS IN mslv-shared.jar. Jakarta-ORO
is also required

The tags provide the following functionality:
o Ability to store application/user state in the page and pass from page to
page using NO server state. (metabean)
o Field validation based on regular expressions. Based on Thor
Kristmundsson's excellent article at JavaWorld, but changed to store state
in the page using the metabean instead of in the session.
(http://www.javaworld.com/javaworld/jw-12-2000/jw-1201-struts.html)
o Scrolling tables via javascript. Wrap this around the tables you create
with <bean:iterate> and you can create a table that scrolls entirely within
the page. This only works in IE right now, but can easily be enhanced to
work with NS4 & NS6.

To use the mslv-shared library:
1) Copy mslv-shared.jar to your \WEB-INF\lib folder.
2) Add mslv-shared.jar to your required library list.
3) Extract the .tld from the .jar & place in your WEB-INF folder.
4) Get jakarta-oro from http://jakarta.apache.org/oro/ and place the
jakarta-oro*.jar in your \WEB-INF\lib folder.

I've attached some modified pages & classes from the struts-example that
show how to use the stuff. I made the following changes to these components
of struts-example.
registration.jsp
o added tld reference
o changed <html:form> to <shared:form>
o changed <html:text> to <shared:text> for fullName and added pattern
validation
o Wrapped <shared:scroll rows="2" id="subs"> around subscription table
o Added <scroll_split/> markers to identify header and each row.

EditRegistrationAction.java
o added username to the metabean on regform. 
o Once registration.jsp displays, do a view-source and you'll see the
username value in the metabean along with the validation rules for the page.
(do a search for metabean)

RegistrationForm.java
o changed to extend MetaActionForm
o added call to super.validate()
o removed fullName validation since it is validated by the ancestor using
the pattern stored in the metabean 


Here's a description of each item in the mslv-shared.jar library. The source
code & compiled classes are included.
MetaTextTag <shared:text> 
o descendant of com.mslv.webapp.tag.MetaBaseFieldTag
o replace <html:text> with <shared:text>
o generates <input type=text.../> HTML
o named pattern - <shared:text property="custAcctId" pattern="@custacctid"
errorMessage="meta.error"/>
o dynamic pattern - <shared:text property="custAcctId"
pattern="/^[0-9]{1,5}$/" errorMessage="meta.error"/>

MetaBaseFieldTag 
o ancestor object - never instantiated directly
o descendant of org.apache.struts.taglib.html.BaseFieldTag
o added "pattern" attribute to define the validation based on a perl match
o supports "named patterns" defined by @somepattern  that maps to
named.pattern.somepattern in com.mslv.webapp.res.WebApplicationResources.
o added "errorMessage" attribute to define the error message if a validation
fails - error messages are read from the APPLICATION resource file. (not the
same place the patterns are stored)
o uses MetaBean to store the pattern & errorMessage attributes  (no server
state required)
o perl regular expressions are covered at http://www.perl.com
o the expression "/^[0-9]{1,5}$/" matches 0-99999 (positive integers with
length between 1 & 5)

ScrollingRegionTag <shared:scroll>
o multiple scrolling regions per page are supported 
o turns a table into a scrolling table.
o descendant of javax.servlet.jsp.tagext.BodyTagSupport
o place <shared:scroll> begin & end tags around an iterate tag (or any long
html table)
o use the id attribute to identify the scrolling region - id must be unique
within a page (including included pages)
o use the rows attribute to set how many rows per page
o use the string "<scroll_split/>" to separate the table header from the
table body (between </tr> & <logic:iterate>) 
o use the string "<scroll_split/>" to separate the table footer from the
table body (between </tr> & </logic:iterate>) 
o data is cached on the client browser 

MetaBean
o use to store a hashtable of String name/value pairs as XML in a page.
o passed from page to page by framework.

MetaActionForm 
o moved MetaBean generation to doEndTag() so that other tags within a form
can modify the MetaBean 
o added support for validation based on perl patterns  
o descendant of org.apache.struts.action.ActionForm
o change your form beans to extend this instead of ActionForm.
o allows for easy manipulation of the MetaBean.

MetaFormTag <shared:form>
o descendant of org.apache.struts.taglib.html.FormTag.
o replace <html:form> with <shared:form> in .jsp
o use <shared:form action="/xxx" metabean="false"> to suppress generation of
the hidden metabean field. 
o the "metabean" attribute is optional. Any value other than "false" will
include the metabean.
o if the "metabean" attribute is not defined, the hidden metabean field will
be generated.

mslv-shared.tld 
o The mslv-shared.tld file is in the META-INF\tlds folder. Use "shared" as
the prefix.
o Include syntax is <%@ taglib uri="/WEB-INF/mslv-shared.tld"
prefix="shared" %>

Notes:
o Jakarta-ORO is required. http://jakarta.apache.org/oro/
o There is still much to be done. But I thought if these were released now,
people might have ideas for improvement.
o Add a bunch of mail accounts for a user to see the scrolling table work.
I've got the rows="2", of course you can change it to play with the results.

Let me know what you think and if there is potential for inclusion in
Struts.

Thanks.

Wayne
wyoung@metasolv.com