At least part of your problem is the way you're trying to setup the
action form. Struts will create an instance of the form bean for you,
which is what is passed into execute() via the 'form' parameter. You're
referencing that in the first line of your execute() method.
However, you then go on to build your own form bean instance, and
replace the one Struts put in the request with the one you've built. You
don't need to do this; just use the bean Struts supplies in the 'form'
parameter.
You mentioned that someone has suggested you needed to do this to get
initial values populated; that's not the case. The first time Struts
builds an instance of DynaActionForm, it will populate properties for
which you've supplied an initial value. What it won't do is reset
properties to their initial values when the reset() method is called on
the form, which you might care about if you have the form stored in
session scope. You can worry about that later though.
So, essentially, your execute() method can be simplified to just this:
> public ActionForward execute(ActionMapping mapping,
> ActionForm form,
> HttpServletRequest request,
> HttpServletResponse response)
> throws ServletException, IOException{
> DynaActionForm setupForm = (DynaActionForm) form;
> //getSetupInfo(setupForm);
> return mapping.findForward("success");
> }
L.
fea jabi wrote:
Thanks for hepling me. here is the code
<form-bean
name="SetupForm"
type="org.apache.struts.action.DynaActionForm" dynamic="true">
<form-property name="custName" type="java.lang.String"/>
<form-property name="typeName" type="java.lang.String"/>
<form-property name="typeNameDesc" type="java.lang.String"/>
<form-property name="confirm" type="java.lang.boolean"
initial="true"/>
</form-bean>
<action
path="/PrepareSetupAction"
type="com.actions.PrepareSetupAction"
name="SetupForm"
scope="session"
validate="false"
input="/pages/Setup.jsp">
<forward name="success" path="/pages/Setup.jsp" redirect="false"/>
</action>
public class PrepareSetupAction extends Action {
/** Creates a new instance of PrepareSetupAction */
public PrepareSetupAction() {
}
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
DynaActionForm setupForm = (DynaActionForm) form;
System.out.println("In PrepareSetupAction : setupform is : " +
setupForm);
//getSetupInfo(setupForm);
ModuleConfig moduleConfig = RequestUtils.getModuleConfig(request,
getServlet().getServletContext());
FormBeanConfig formConfig =
moduleConfig.findFormBeanConfig("SetupForm");
DynaActionFormClass dynaClass =
DynaActionFormClass.createDynaActionFormClass(formConfig);
try {
setupForm = (DynaActionForm)dynaClass.newInstance();
System.out.println("In PrepareSetupAction in try : setupform
is : " + setupForm);
}
catch (Exception e) {
//logger.error(e);
}
//request.setAttribute("SetupForm", setupForm);
return mapping.findForward("success");
}
}
<html:form action="PrepareScreen1Action.do" method="post">
<table >
............................
......................................
<!-- 1. Customer Name-->
<tr>
<td>
<bean:message key="lbl.customername"/>
<bean:message key="colon"/>
</td>
<td>
<html:text property="custName" size="40"
styleClass="invisibleInput" readonly="true" tabindex="-1"/>
</td>
<td></td>
</tr>
<tr></tr><tr></tr><tr></tr>
<tr>
<td>
<bean:message key="lbl.typename"/> <bean:message
key="colon"/>
</td>
<td>
<html:text property="typeName" size="40" />
</td>
<td></td>
</tr>
<tr></tr><tr></tr><tr></tr>
<!-- 3. Type Name Description -->
<tr>
<td>
<bean:message key="lbl.typenamedescption"/>
<bean:message key="colon"/>
</td>
<td>
<html:textarea property="typeNameDesc" />
</td>
<td></td>
</tr>
<tr></tr><tr></tr><tr></tr>
<!-- 4. confirm -->
<tr>
<td>
<bean:message key="lbl.confirm"/> <bean:message
key="colon"/>
</td>
<td>
<html:checkbox property="confirm" />
</td>
<td></td>
</tr>
......................
....................
</table>
</html-form>
thanks.
From: Dave Newton <[EMAIL PROTECTED]>
Reply-To: "Struts Users Mailing List" <user@struts.apache.org>
To: Struts Users Mailing List <user@struts.apache.org>
Subject: Re: No getter method servlet Exception. using DynaActionForm
Date: Wed, 16 Nov 2005 11:06:56 -0500
fea jabi wrote:
When I debug after
DynaActionForm setupForm = (DynaActionForm) form;
my setupForm is null
Is your struts config as you posted earlier? i.e., the "name"
attribute refers to a Dyna form that doesn't exist in the "form-beans"
section? That won't work.
ModuleConfig moduleConfig =
RequestUtils.getModuleConfig(request,
getServlet().getServletContext());
FormBeanConfig formConfig =
moduleConfig.findFormBeanConfig("CustForm");
DynaActionFormClass dynaClass =
DynaActionFormClass.createDynaActionFormClass(formConfig);
try {
setupForm = (DynaActionForm)dynaClass.newInstance();
one of the user suggested that when I initialize a form-property in
struts-config using initial="true"
I have to use the above to prepopulate the form.
is this right?? Am I using at the right place.
If Struts is configured the form will have already been created on
entry to the Action.
I think you need to back up a step and check your configuration. If
you post the relevent sections again as they exist now we might be
able to help you better.
Right now things are wrong, and I find it highly unlikely you would
_ever_ need or want to instantiate a form inside an Action.
Dave
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
_________________________________________________________________
Don’t just search. Find. Check out the new MSN Search!
http://search.msn.click-url.com/go/onm00200636ave/direct/01/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]