Here is the flow of my tiny app: 

listAction -> list.jsp -> selectAction -> update.jsp -> updateAction
(implements ModelDriven - getModel() returns the object selected in
list.jsp stored in session )

Once it gets to update.jsp, the form should show the values of the bean
selected on list.jsp.  But, since getModel() is not called until the
update.jsp is posts to updateAction, the model is not on the value
stack.
-------------------------------------
struts.xml:

<struts>
    <include file="struts-default.xml"/>
    <constant name="struts.devMode" value="true"/>
    <constant name="struts.ui.theme" value="simple"/>

    <constant name="struts.objectFactory"
value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
    

<package name="default" extends="struts-default">

    <action name="list" class="listAction">
        <result>/list.jsp</result>
        <result name="error">/index.jsp </result>
    </action>

    <action name="select" class="selectAction">
        <result>/update.jsp</result>
    </action>

    <action name="save" class="updateAction">
        <result name="input">/update.jsp</result>
        <result>/update.jsp</result>
        <result name="error">/update.jsp</result>
    </action>

</package>

</struts> 

-----------------------------------
ListAction:
import com.wellsfargo.fmg.appaudit.domain.AuditCode;

import java.util.ArrayList;
import java.util.List;

public class ListAction extends AppAuditAction {
    public String execute()
    {
        List codes = new ArrayList();
        AuditCode code = new AuditCode();
        code.setCode(1);
        code.setDescription("Really cool code");
        codes.add(code);
        this.getSession().put("codes",codes);
        return SUCCESS;
    }

}
-----------------------------

list.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> <%@ taglib
uri="/WEB-INF/c.tld" prefix="c" %> <html> <head>
    <title>App Audit Maint</title>
</head>
<body>
<h2>
   App Audit Code Listing
</h2>
<table>
    <s:iterator value="#attr.codes">
    <tr>
        <td>
            <s:property value="code" /> - <s:property
value="description" />
            <s:url id="selectUrl" value="/select.action" >
                  <s:param name="code" value="code" />
            </s:url>
            <s:a href="%{selectUrl}">Edit</s:a>
        </td>
    </tr>
    </s:iterator>
</table>
</body>
</html>
-------------------------------------
SelectAction:
import com.wellsfargo.fmg.appaudit.domain.AuditCode;

import java.util.Iterator;
import java.util.List;

public class SelectAction extends AppAuditAction {
    public String execute() throws Exception
    {
        String[] codeParam = (String[])this.getParameters().get("code");
        List codes = (List)this.getSession().get("codes");

        for (Iterator it = codes.iterator();it.hasNext();)
        {
            AuditCode c = (AuditCode)it.next();
            if (c.getCode() == Integer.valueOf(codeParam[0]).intValue())
            {
                this.getSession().put("auditCode",c);
                break;
            }
        }
        return SUCCESS;
    }
}
-----------------------------------------
update.jsp

<%@ taglib prefix="s" uri="/struts-tags" %> <html> <head>
    <title>App Audit Maint</title>
</head>
<body>
<h2>
   Update Audit Code
</h2>
<s:actionerror/>
<s:form action="save">
<table>
    <tr>
        <td>
            Code: <s:property value="code"/>
        </td>
    </tr>
    <tr>
        <td>
            Description: <s:textfield name="description"/>
        </td>
    </tr>
</table>
    <s:submit value="submit"/>
</s:form>
</body>
</html>

-------------------------------------------------
import com.opensymphony.xwork2.ModelDriven;
import com.wellsfargo.fmg.appaudit.domain.AuditCode;

public class UpdateAction extends AppAuditAction implements ModelDriven
{
    public UpdateAction()
    {
        System.out.println("UPDATE action constructor");
    }

    public String execute() throws Exception
    {
        this.addActionError("Error On Execute");
        return INPUT;
    }

    public int getCode()
    {
        AuditCode auditCode =
(AuditCode)this.getSession().get("auditCode");
        return auditCode.getCode();
    }

    public String input() throws Exception
    {
        return super.input();    //To change body of overridden methods
use File | Settings | File Templates.
    }

    public Object getModel()
    {
        System.out.println("getModel Called");
        AuditCode auditCode =
(AuditCode)this.getSession().get("auditCode");
        return auditCode;
        //return this.auditCode;
    }
}
--------------------
the super class for all my actions:

import com.opensymphony.xwork2.ActionSupport;
import org.apache.struts2.interceptor.SessionAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.ParameterAware;

import java.util.Map;

public abstract class AppAuditAction extends ActionSupport implements
SessionAware, RequestAware, ParameterAware {
    private Map session;
    private Map request;
    private Map parameters;

    public void setSession(Map map)
    {
        this.session = map;
    }

    public void setRequest(Map map)
    {
        this.request = map;
    }

    public void setParameters(Map map)
    {
        this.parameters = map;
    }

    public Map getSession()
    {
        return session;
    }

    public Map getRequest()
    {
        return request;
    }

    public Map getParameters()
    {
        return parameters;
    }
}


       
________________________________________________________________________
____________
Get the free Yahoo! toolbar and rest assured with the added security of
spyware protection.
http://new.toolbar.yahoo.com/toolbar/features/norton/index.php


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to