XView4Struts -- An Extension to the Struts Framework |
Attribute | Description |
---|---|
id | The name of your form bean's property. |
value | Optional. The parser will create this attribute if it doesn't exist. If it does exist, the parser will replace it. |
Struts bean property |
The bean property's type must be String. or applicable TagBean. |
Attribute | Description |
---|---|
id | The name of your form bean's property. |
Struts bean property |
The bean property's type must be String or TextAreaTagBean |
Attribute | Description |
---|---|
id | The name of your form bean's property. |
value | Optional. The parser will create this attribute if it doesn't exist. If it does exist, the parser will replace it. |
Struts bean property |
The bean property's type must be String or SelectTagBean |
Attribute | Description |
---|---|
id | The name of your form bean's property. |
Struts bean property |
The bean property's type must be Array. If the array's element is of type String. then only the option's label will be applied. If the array's element is of type LabelValueBean then the option's value attribute and label will both be applied. LabelValueBean.java is a standard bean distributed with Struts. If the array's element is of type OptionTagBean then all attributes populated in the tagBean will be applied. |
Only one option tag is required. If the html page was originally used as a mock-up, then only the first option tag should use the "id" attribute. All other existing option tags will be replaced.
Attribute | Description |
---|---|
id | The name of your form bean's property. |
Struts bean property |
The bean property's type must be ImageTagBean or ImageTagBean. |
The ImageTagBean is a custom bean with properties for every possible IMG attribute. The developer only needs to populate the properties needed.
Attribute | Description |
---|---|
id | The name of your form bean's property. |
Struts bean property |
The bean property's type must be LinkTagBean. |
The LinkTagBean is a custom bean with properties for every possible Link attribute. The developer only needs to populate the properties needed.
Attribute | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
type |
|
||||||||||
id | The name of your form bean's property. | ||||||||||
Struts bean property |
|
The div tag as implemented in this extension is by far the most powerful and dynamic tag implemented. You may still use div tags as intended by the HTML standard. This extension just adds functionality.
The div tag is used to identify an insertion point for HTML document fragments. The document fragment may be simple text, HTML text, the contents of a specified file or the results of an xsl transformation. The document fragment will also be parsed. If the fragment contains HTML elements recognized by the parser then they will be treated as if they are part of the original document. Therefore it is possible to nest any number of document fragments providing the ability to create highly dynamic content. The div tag can also serve as a replacement for the Struts tags <html:errors> and <bean:message> tags.
One possible use of this concept is to create templates for your application. The most popular layout for webpages is to supply a header that may or may not include a menu, a menu on the left hand side, a details section that displays all of the information that gives this page purpose and a footer. Two to three of these sections are relatively constant throughout the application. No one likes having to create the same code over and over again. Maintenance is also a hassel in a project like that because one small change has to be copied to many pages. Then came templates. Templates allow the developer to create a section just once and include it on as many pages as they want. There are several ways to implement the template concept in Struts and XView also provides a mechanism through the use of the div tag. See the section below on using templates.
In practice, any dynamic page content will need a div tag. So if you need to produce a variable length table, a dynamic list of items, display different text for different users or periodically publish different text then you will need to use a div tag. How you implement the div tag is completely up to you. The implementation of this tag is flexible enough that there is normally more that one way to acomplish the same goal.
Inserting Content From Another Page The div tag provides an option to merge multiple html pages into a single page. It is the "type=url" option that performs this function. This option simply extracts all of the content found between the "body" tags of the specified document. After the contents are inserted into the parent document, control is returned to the parser and the new contents are parsed just as if they were part of the original document. In this way, any number of pages may be nested to produce the desired effect. One application of this technique is in creating a templating system.
Using Templates -- An ExampleImplementing this concept means you now have only one page that your application references; the template page and the details are dynamically added as the user navigates your site. The first annoyance that you will run accross is that each navigation point has its own form bean which means that the same four variables have to be included in every form bean and these variables have to be initialized.
There is a work around to this situation.This is just a basic illustration. You will need to adjust it to your own situation. Since
Version 1.4.1, it is possible to reduce the requirements placed upon the formbean by using the
option that specifies the target html as a context relative path in the id attribute.
XSL Transformations
Many times the nature of the dynamic content comes in the form of data that needs to be
prestented in tabular form or as a list. The developer has two options available. One
way is to write a method that formats the data as html text, store it in the form bean
and use <div type="text"> to display the data.
Another option that could be more usefull is to use the <div type="xsl"> tag. Using this option requires two steps. Populate a custom bean with your data and then write the xsl file.
XView4Struts provides helper classes to facilitate this type of presentation. The class org.xview.parse.helpers.XmlTableBean will probably work for many cases when using this option. It's function is the hold the data. The data may be a simple list of Strings or a two dimensional table stored as a list of org.xview.parse.helpers.XmlRowBean objects. XmlTableBean has a properties that also must be set. The "list" and "table" booleans indicate the type of data structure. These two properties interact inversely with each other so only one, your choice, needs to be set. The xslFileName property needs to be populated with the context relative path to the xsl file that will be used to perform the transformation. The developer is also free to write their own bean. The only requirement is that it implements the XmlBean interface. It is therefore possible to to create beans with any type of data structure, properties and behavior need to achieve the desired behavior.
Refering to the example application, you'll see how easy it is to populate the XmlTableBean. The example also has xsl files you may be able to use as is, with slight modification or at the very least use them as a basis for writing your own xsl files. Many times these xsl files may be used for several pages within a single application. When you think about it, this is a very powerfull concept.
Displaying errors
XView4Struts provides a replacement for the Struts <html:errors>
tag. To display a list of errors use <div type="errors">. This
tag will display all action errors identified with the key = "ActionErrors.GLOBAL_ERROR".
This is a slight deviation from the way Struts does it. In Struts all action errors,
reguardless of it's key, is displayed when the <html:errors> is used.
If the "id" attribute is present, then only the specified error message will be displayed
without the header, suffix, prefix or footer messages.
Displaying messages and internationalization
XView4Struts provides a replacement for the Struts <bean:message>
tag. To display a list of messages retrieved from the applicationResources.properties file
use <div type="message">. This implementation will display all
messages identified with the key = "ActionMessages.GLOBAL_ERROR". This tag will replace
any existing text between the <div> and the </div>
tags in the html file. To display a specific message use <div type="message" id="xxx">.
Just like in the errors implementation, this tag deviates slightly from the Struts implementation.
Cache Manager
XView4Struts provides a cache manager that greatly improves your application's response time.
In general, there are two bottlenecks with any web application. They are file I/O and data
I/O. Since XView4Struts only deals with the view layer, it can't do much to improve data I/O.
Since the html and xsl documents used by XView4Struts are static in nature it makes since that
if a master copy is maintained in memory then the file I/O bottleneck would be greatly reduced.
There are always tradeoffs. On one hand performance goes up and and processor activity remains
more constant. On the other hand, memory useage also increases.
The cache manager is very flexable. It uses the CacheManager.properties file for its configuration. It may be completely disabled. The developer may choose to exclude certain files, define a default keep-alive time or specify keep-alive times on a file by file basis. There is a timer thread that runs in the background that periodically removes all items from the cache that have expired. The thread's frequency is specified in the CacheManager.properties file. You decide what is best for your situation. Another note of importance is that whenever the application access a cached item, it's date value is updated. In this way, active pages are kept im memory longer and less active pages expire sooner.
The cache manager may also be used by developers for virtually any Java object. Just build a CachedItem object and use the CacheManager's static methods to add and remove them to the cache as needed. The developer needs to keep in mind that these objects are globally available. One implication of this fact is that its concievable to cache some data layer objects. So if used in this way XView4Struts can help reduce some data I/O activity.
TagBean Helper Classes
Since Version 1.4, TagBean helper classes were introduced to add more dynamic control over the static
presentation tags. TagBeans offer the developer the opportunity to dynamically set any or all attributes
associated with a specific tag. TagBeans also act as a place holder for the value property associated
with form tags. The value property will be populated by struts when a form is submitted. The value
property is also used by XView4Struts to prepopulate a tag when a page is being rendered.
During the rendering process, the TagBean will be inspected for any attributes that have been assigned some value. If such an attribute exists in the TagBean then that attribute will be applied to the tag overwriting any existing attribute. The overall end-effect is that any html tag attributes in the original document will remain unchanged unless over written by an attribute in the TagBean.
The introduction of the TagBean facilitated the addition of another attribute that controls the visibility of a tag. The visibility attribute if set true will prevent the html tag from being rendered.
This table specifies the helper class name that is associated with each html tag.HTML Tag | TagBean Class Name |
---|---|
Input type=text | org.xview.parse.helpers.TextInputTagBean |
Input type=password | org.xview.parse.helpers.PasswordInputTagBean |
Input type=checkbox | org.xview.parse.helpers.CheckedInputTagBean |
Input type=radio | org.xview.parse.helpers.CheckedInputTagBean |
Input type=image | org.xview.parse.helpers.ImageInputTagBean |
Input type=submit | org.xview.parse.helpers.ButtonTagBean |
Input type=file | org.xview.parse.helpers.FileTagBean |
TextArea | org.xview.parse.helpers.TextAreaTagBean |
Select | org.xview.parse.helpers.SelectTagBean |
Option | org.xview.parse.helpers.OptionTagBean |
Anchor/Link | org.xview.parse.helpers.LinkTagBean |
Img | org.xview.parse.helpers.ImageTagBean |
Additional Notes about TagBeans
SelectTagBean:The valueSelected property is of type String[]. This is necessary
to make this bean compatible with 'select' tags that have the "multiple" attribute set.
For single select 'select' tags you only need a String property as a place holder for the
value selected by the user. Multiselect 'select' tags require a String[] to hold all of the
values selected by the user. If you use a String[] for a single select 'select' tag, Struts
will populate the first element with the selected value. Since a String[] works for both
instances then String[] is a perfect fit for the SelectTagBean.
Option Tags:The combinations of 'select' tag formBean property types and 'option'
tag formBean property types provides the developer with nine seperate possibilities they may
choose from. There are three types for the 'select' tag; String, String[] and SelectTagBean.
Internally, the SelectTagBean uses a String[]. The 'option' tag also offers three options;
String[], LabelValueBean[] and OptionTagBean[]. When XView4Struts builds a page to be presented
to the user it needs to be able to indicate which options of a 'select' tag are preselected.
The method for doing this is to populate the 'select' tag's formBean property with the value
of the option or options to be displayed as preselected. When using the OptionTagBean, the
developer has another method available for displaying preselected options. The developer may
choose to set the "selected" attribute of each OptionTagBean individually.
Getting Help
Your best resource for learning how each of these tags are implemented is to review the
examples application. If you need additional help then you should use the
forums on the
XView4Struts website.