Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Looking over the markup, it's easy to see why Java web development without the aid from a modern framework is hard! So far, we've only coded two controls, and there are six more to go! Let's rewrite and finish the form using Struts Tags.

Code Block
XML
XMLtitleAfter Struts Tags (a complete form)
<s:actionerror/>
<s:form action="Profile_update" validate="true">
    <s:textfield label="Username" name="username"/>
    <s:password label="Password" name="password"/>
    <s:password label="(Repeat) Password" name="password2"/>
    <s:textfield label="Full Name" name="fullName"/>
    <s:textfield label="From Address" name="fromAddress"/>
    <s:textfield label="Reply To Address" name="replyToAddress"/>
    <s:submit value="Save" name="Save"/>
    <s:submit action="Register_cancel" value="Cancel" name="Cancel"
            onclick="form.onsubmit=null"/>
</s:form>
Tip

The Struts Tags also support validation and localization as first-class features. So not only is there less code, but there is more utility.

In about the same amount of code as two conventional controls, the Struts Tags can create an entire data-input form with eight controls. Not only is there less code, but the code is easier to read and maintain.

...

Here's a typical configuration (struts.xml) for a login workflow:

Code Block
xml
xml
<struts>
    <package name="default" extends="struts-default">

        <action name="Logon" class="mailreader2.Logon">
            <result name="input">/pages/Logon.jsp</result>
            <result name="cancel" type="redirectAction">Welcome</result>
            <result type="redirectAction">MainMenu</result>
            <result name="expired" type="chain">ChangePassword</result>
        </action>

        <action name="Logoff" class="mailreader2.Logoff">
            <result type="redirectAction">Welcome</result>
        </action>

    </package>
</struts>

(lightbulb) The framework provides general-purpose defaults, so we can start using Struts right away, "out of the box". Any factory defaults can be overridden in an application's configuration, as needed.

...

(tick) An alternate set of JARs for Java 4 are also available. See the "J4" distribution.

Excerpt

Next: AJAX