Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
<action name="Welcome">
<result>/pages/Welcome.jsp</result>
</action>

How do you emulate the default="true" attribute of a

...

Struts 1.x Action mapping?

Rather than tag the action as being the default, the default action is set by name using default-action-ref element.

...

By using an element, rather than an attribute, packages can inherit the default action name.

How do you extend an action mapping in struts.xml??

Starting in Struts 1.3, you could use the "extends" attribute in your Struts configuration Action mapping to have it inherit properties from a base mapping. In Struts 2, that technique is no longer necessary because you have packages. You can create a package, then set for that package the default Result type, Interceptor chain, and global results. This leaves very little information to actually be included in an action element.

Here is an example of declaring a custom package:

Code Block

<package name="chat" extends="struts-default" namespace="/chat">
  <global-results>
    <result name="login" type="freemarker">/chat/chatLogin.ftl</result>
  </global-results>
  <default-interceptor-ref name="basicStack"/>
  ...
</package>

In fact, packages themselves can extend other packages, as the "chat" package extends "struts-default" in the above example.

Can I use DynaBeans in my Struts actions?

DynaBeans can be treated as a regular Java object, if the particular implementation contains a getMap() method. This method lets OGNL, the Struts 2 expression language, know how to access and set data. DynaBean variants like the LazyDynaBean can create themselves on-the-fly, where other more static types might need to be created in your Action's constructor before being used. However, one of the benefits of Struts 2 over Struts 1.x is that you can use your existing JavaBeans directly without the need of an ActionForm-type wrapper, so you might try bypassing the familiar DynaBean route.

Next: SAF2 ActionContext

...

This material originally adopted from: http://wiki.apache.org/struts/IssuesAndSolutions.