Wednesday, December 1, 2010

notes on struts2

1) passing parameters to an action
--- in struts.xml
<action name="login" class="at.kds.epb5.epbback.action.LoginAction" method="execute">
<result name="success" type="redirectAction">
<param name="actionName">list</param>
<param name="stickerBundleStatus">1</param>
</result>
<result name="input">/login.jsp</result>
<result name="error">/login.jsp</result>
</action>
since the default stack is used, there is no need to specify an interceptor

--- Action bean class has to implement ParameterAware interface and hence to implement its setParameters method
e.g.
@Override
public void setParameters(Map parameters) {
try {
if ( parameters == null ) return;
String[] tmp = (String[])parameters.get("stickerBundleStatus");
if(tmp != null && tmp[0] != null
) {
stickerBundleStatus = Integer.valueOf(tmp[0]);
}
} catch (Exception ex) {
stickerBundleStatus = StickerBundle.STATUS_OPEN;
}

}


2) Parameters saved to the session
the action bean has to implement SessionAware interface and its method setSession()
e.g.
Map session = null;

@Override
public void setSession(Map session) {
this.session = session;
}
and when needed to use session.put() and session.get() methods

3) Preparable interface - with the default stack when the action bean implements Prepare interface, prepare() and prepareXXX() are called before XXX() action method

No comments:

Post a Comment