You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "José Fortunato H. Tomás" <jo...@link.pt> on 2003/07/24 17:50:15 UTC
Pre-Setting DynaValidatorForm attributes
Hi!
I have the follow situation:
- I get an Circuit Data Object from a manager
Then I want to edit the Circuit in HTML form, using an DynaValidatorForm I
don't know to how to do correct set for the propertyes priorly!
How should I set the properties priorly?
I'm tring to do the usual set(key, object), but I get an NullPointerException on
getter:
----
java.lang.NullPointerException
at
org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:596)
at org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:241)
at
com.esegur.sims.util.struts.form.BasicDynaValidatorForm.getInteger(BasicDynaValidatorForm.java:32)
at
org.apache.jsp.circuitEditForm_jsp._jspService(circuitEditForm_jsp.java:145)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
...
----
BasicDynaValidatorForm is just an helper for getString, getInteger and so on.
The code I'm using for setting is:
---
if (actionForm instanceof BasicDynaValidatorForm ) {
BasicDynaValidatorForm circuitEditForm =
(BasicDynaValidatorForm)actionForm;
circuitEditForm.initialize(actionMapping);
CircuitDO cDO = Planning.getCircuitSessionAttr(httpServletRequest);
circuitEditForm.set( "circuitId", cDO.getCircuitId() );
/*...*/
circuitEditForm.set( "designation", cDO.getDesignation() );
}
---
Thanks
--
José Tomás
LINK Consulting SA - http://www.link.pt
Av. Duque de Avila 23 5º Dto. - 1000-138 Lisboa
Telf: (+351) 213 100 095 Fax: (+351) 213 100 079
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Pre-Setting DynaValidatorForm attributes (solution/conclusion)
Posted by "José Fortunato H. Tomás" <jo...@link.pt>.
Hi!
Just for close this post I want to say this:
- I had a bug for something stupid I made and I didn't realise what was referred
by the exception.
The code that I presented here is the correct one. Since we are in a Action or
JSP nested to an Action Form, a bean exists in the correct scope with the
respective attribute name.
Thanks anyway.
José Fortunato H. Tomás wrote:
> Hi!
>
> I have the follow situation:
> - I get an Circuit Data Object from a manager
> Then I want to edit the Circuit in HTML form, using an
> DynaValidatorForm I don't know to how to do correct set for the
> propertyes priorly!
>
> How should I set the properties priorly?
>
> I'm tring to do the usual set(key, object), but I get an
> NullPointerException on getter:
> ----
> java.lang.NullPointerException
> at
> org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:596)
>
> at
> org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:241)
> at
> com.esegur.sims.util.struts.form.BasicDynaValidatorForm.getInteger(BasicDynaValidatorForm.java:32)
>
> at
> org.apache.jsp.circuitEditForm_jsp._jspService(circuitEditForm_jsp.java:145)
>
> at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
>
> ...
> ----
> BasicDynaValidatorForm is just an helper for getString, getInteger and
> so on.
>
> The code I'm using for setting is:
> ---
> if (actionForm instanceof BasicDynaValidatorForm ) {
> BasicDynaValidatorForm circuitEditForm =
> (BasicDynaValidatorForm)actionForm;
>
> circuitEditForm.initialize(actionMapping);
>
> CircuitDO cDO =
> Planning.getCircuitSessionAttr(httpServletRequest);
> circuitEditForm.set( "circuitId", cDO.getCircuitId() );
> /*...*/
> circuitEditForm.set( "designation", cDO.getDesignation() );
> }
> ---
>
> Thanks
--
José Tomás
LINK Consulting SA - http://www.link.pt
Av. Duque de Avila 23 5º Dto. - 1000-138 Lisboa
Telf: (+351) 213 100 095 Fax: (+351) 213 100 079
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Pre-Setting DynaValidatorForm attributes
Posted by "José Fortunato H. Tomás" <jo...@link.pt>.
Alex Shneyderman wrote:
> I am not sure if I understand you correctly, but I will try.
>
> What you basically need is to create a form bean without actually
> invoking the action that claims that it uses it. Did I understand you
> correctly?
I use "/planning/circuitEditForm" as a mid tier view action to set some Request
Attributes with ArrayList. Those ArrayList have data from the DB tier to help
build some combo.
If I didn't have any combo dynamic data to build the form I could simple
substitute "/planning/circuitEditForm.do" for "/planning/circuitEditForm.jsp".
But my problem is that beownd the data for those combos I need to set in
advantage de value for the bean, so with <html:text property="designation"
maxlength="50" /> in the JSP I get the value existing in the database, to do
some editing of existing data.
That's why I'm trying to do the code that I gived here.
>
>
> Anway to create your form bean manually you would do something like
> this:
>
> ModuleConfig mc = RequestUtils.getRequestModuleConfig (request);
> ActionMapping am = (ActionMapping) mc.findActionConfig (actionName);
> return RequestUtils.createActionForm (request, am, mc, getServlet ());
I'm trying to do this, I'll be back.
>
> where action name is the action name that uses the form you create, in
> your case /planning/circuit/edit
>
> HTH,
> Alex.
>
>
>
>
>
>>-----Original Message-----
>>From: José Fortunato H. Tomás [mailto:jose.tomas@link.pt]
>>Sent: Thursday, July 24, 2003 2:14 PM
>>To: Struts Users Mailing List
>>Subject: Re: Pre-Setting DynaValidatorForm attributes
>>
>>I was reading my post and reallise that I omitted an importante
>>information.
>>The action where I want to set DynaValidatorForm properties is the one
>
> to
>
>>forward into the JSP that builds the all form, and not the action
>>associated
>>with the bean.
>>
>>Just for more complete information:
>>The actio that contains the initial form bean:
>> <action path="/planning/circuit/edit"
>> type="com.esegur.sims.web.CircuitEditAction"
>> scope="request"
>> name="CircuitEditForm"
>> input="/planning/circuitEditForm.do"
>> validate="true">
>> <forward name="ok"
>
> path="site.planning.circuit.edit.result"/>
>
>> <forward name="ko"
>
> path="site.planning.circuit.edit.form"/>
>
>> </action>
>>
>>
>>The action where I want to set some properties:
>> <action
>> path="/planning/circuitEditForm"
>>
>
> type="com.bla.bla.web.formaction.CircuitEditFormJSPAction"
>
>> parameter="/planning/circuitEditForm.jsp"/>
>>
>>
>>José Fortunato H. Tomás wrote:
>>
>>
>>>Hi!
>>>
>>>I have the follow situation:
>>> - I get an Circuit Data Object from a manager
>>> Then I want to edit the Circuit in HTML form, using an
>>>DynaValidatorForm I don't know to how to do correct set for the
>>>propertyes priorly!
>>>
>>>How should I set the properties priorly?
>>>
>>>I'm tring to do the usual set(key, object), but I get an
>>>NullPointerException on getter:
>>>----
>>>java.lang.NullPointerException
>>> at
>>>
>>
> org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.j
> av
>
>>a:596)
>>
>>> at
>>>org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:241)
>>> at
>>>
>>
> com.esegur.sims.util.struts.form.BasicDynaValidatorForm.getInteger(Basic
> Dy
>
>>naValidatorForm.java:32)
>>
>>> at
>>>
>>
> org.apache.jsp.circuitEditForm_jsp._jspService(circuitEditForm_jsp.java:
> 14
>
>>5)
>>
>>> at
>>>org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
>>> at
>
> javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>
>>> at
>>>
>>
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
> va
>
>>:210)
>>
>>>...
>>>----
>>>BasicDynaValidatorForm is just an helper for getString, getInteger
>
> and
>
>>>so on.
>>>
>>>The code I'm using for setting is:
>>>---
>>> if (actionForm instanceof BasicDynaValidatorForm ) {
>>> BasicDynaValidatorForm circuitEditForm =
>>>(BasicDynaValidatorForm)actionForm;
>>>
>>> circuitEditForm.initialize(actionMapping);
>>>
>>> CircuitDO cDO =
>>>Planning.getCircuitSessionAttr(httpServletRequest);
>>> circuitEditForm.set( "circuitId", cDO.getCircuitId() );
>>>/*...*/
>>> circuitEditForm.set( "designation", cDO.getDesignation()
>
> );
>
>>> }
>>>---
>>>
>>>Thanks
>>
>>--
>>José Tomás
>> LINK Consulting SA - http://www.link.pt
>> Av. Duque de Avila 23 5º Dto. - 1000-138 Lisboa
>> Telf: (+351) 213 100 095 Fax: (+351) 213 100 079
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>
--
José Tomás
LINK Consulting SA - http://www.link.pt
Av. Duque de Avila 23 5º Dto. - 1000-138 Lisboa
Telf: (+351) 213 100 095 Fax: (+351) 213 100 079
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
RE: Pre-Setting DynaValidatorForm attributes
Posted by Alex Shneyderman <al...@law.columbia.edu>.
I am not sure if I understand you correctly, but I will try.
What you basically need is to create a form bean without actually
invoking the action that claims that it uses it. Did I understand you
correctly?
Anway to create your form bean manually you would do something like
this:
ModuleConfig mc = RequestUtils.getRequestModuleConfig (request);
ActionMapping am = (ActionMapping) mc.findActionConfig (actionName);
return RequestUtils.createActionForm (request, am, mc, getServlet ());
where action name is the action name that uses the form you create, in
your case /planning/circuit/edit
HTH,
Alex.
> -----Original Message-----
> From: José Fortunato H. Tomás [mailto:jose.tomas@link.pt]
> Sent: Thursday, July 24, 2003 2:14 PM
> To: Struts Users Mailing List
> Subject: Re: Pre-Setting DynaValidatorForm attributes
>
> I was reading my post and reallise that I omitted an importante
> information.
> The action where I want to set DynaValidatorForm properties is the one
to
> forward into the JSP that builds the all form, and not the action
> associated
> with the bean.
>
> Just for more complete information:
> The actio that contains the initial form bean:
> <action path="/planning/circuit/edit"
> type="com.esegur.sims.web.CircuitEditAction"
> scope="request"
> name="CircuitEditForm"
> input="/planning/circuitEditForm.do"
> validate="true">
> <forward name="ok"
path="site.planning.circuit.edit.result"/>
> <forward name="ko"
path="site.planning.circuit.edit.form"/>
> </action>
>
>
> The action where I want to set some properties:
> <action
> path="/planning/circuitEditForm"
>
type="com.bla.bla.web.formaction.CircuitEditFormJSPAction"
> parameter="/planning/circuitEditForm.jsp"/>
>
>
> José Fortunato H. Tomás wrote:
>
> > Hi!
> >
> > I have the follow situation:
> > - I get an Circuit Data Object from a manager
> > Then I want to edit the Circuit in HTML form, using an
> > DynaValidatorForm I don't know to how to do correct set for the
> > propertyes priorly!
> >
> > How should I set the properties priorly?
> >
> > I'm tring to do the usual set(key, object), but I get an
> > NullPointerException on getter:
> > ----
> > java.lang.NullPointerException
> > at
> >
>
org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.j
av
> a:596)
> >
> > at
> > org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:241)
> > at
> >
>
com.esegur.sims.util.struts.form.BasicDynaValidatorForm.getInteger(Basic
Dy
> naValidatorForm.java:32)
> >
> > at
> >
>
org.apache.jsp.circuitEditForm_jsp._jspService(circuitEditForm_jsp.java:
14
> 5)
> >
> > at
> > org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
> > at
javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> > at
> >
>
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.ja
va
> :210)
> >
> > ...
> > ----
> > BasicDynaValidatorForm is just an helper for getString, getInteger
and
> > so on.
> >
> > The code I'm using for setting is:
> > ---
> > if (actionForm instanceof BasicDynaValidatorForm ) {
> > BasicDynaValidatorForm circuitEditForm =
> > (BasicDynaValidatorForm)actionForm;
> >
> > circuitEditForm.initialize(actionMapping);
> >
> > CircuitDO cDO =
> > Planning.getCircuitSessionAttr(httpServletRequest);
> > circuitEditForm.set( "circuitId", cDO.getCircuitId() );
> > /*...*/
> > circuitEditForm.set( "designation", cDO.getDesignation()
);
> > }
> > ---
> >
> > Thanks
>
> --
> José Tomás
> LINK Consulting SA - http://www.link.pt
> Av. Duque de Avila 23 5º Dto. - 1000-138 Lisboa
> Telf: (+351) 213 100 095 Fax: (+351) 213 100 079
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org
Re: Pre-Setting DynaValidatorForm attributes
Posted by "José Fortunato H. Tomás" <jo...@link.pt>.
I was reading my post and reallise that I omitted an importante information.
The action where I want to set DynaValidatorForm properties is the one to
forward into the JSP that builds the all form, and not the action associated
with the bean.
Just for more complete information:
The actio that contains the initial form bean:
<action path="/planning/circuit/edit"
type="com.esegur.sims.web.CircuitEditAction"
scope="request"
name="CircuitEditForm"
input="/planning/circuitEditForm.do"
validate="true">
<forward name="ok" path="site.planning.circuit.edit.result"/>
<forward name="ko" path="site.planning.circuit.edit.form"/>
</action>
The action where I want to set some properties:
<action
path="/planning/circuitEditForm"
type="com.bla.bla.web.formaction.CircuitEditFormJSPAction"
parameter="/planning/circuitEditForm.jsp"/>
José Fortunato H. Tomás wrote:
> Hi!
>
> I have the follow situation:
> - I get an Circuit Data Object from a manager
> Then I want to edit the Circuit in HTML form, using an
> DynaValidatorForm I don't know to how to do correct set for the
> propertyes priorly!
>
> How should I set the properties priorly?
>
> I'm tring to do the usual set(key, object), but I get an
> NullPointerException on getter:
> ----
> java.lang.NullPointerException
> at
> org.apache.struts.action.DynaActionForm.getDynaProperty(DynaActionForm.java:596)
>
> at
> org.apache.struts.action.DynaActionForm.get(DynaActionForm.java:241)
> at
> com.esegur.sims.util.struts.form.BasicDynaValidatorForm.getInteger(BasicDynaValidatorForm.java:32)
>
> at
> org.apache.jsp.circuitEditForm_jsp._jspService(circuitEditForm_jsp.java:145)
>
> at
> org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
> at
> org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
>
> ...
> ----
> BasicDynaValidatorForm is just an helper for getString, getInteger and
> so on.
>
> The code I'm using for setting is:
> ---
> if (actionForm instanceof BasicDynaValidatorForm ) {
> BasicDynaValidatorForm circuitEditForm =
> (BasicDynaValidatorForm)actionForm;
>
> circuitEditForm.initialize(actionMapping);
>
> CircuitDO cDO =
> Planning.getCircuitSessionAttr(httpServletRequest);
> circuitEditForm.set( "circuitId", cDO.getCircuitId() );
> /*...*/
> circuitEditForm.set( "designation", cDO.getDesignation() );
> }
> ---
>
> Thanks
--
José Tomás
LINK Consulting SA - http://www.link.pt
Av. Duque de Avila 23 5º Dto. - 1000-138 Lisboa
Telf: (+351) 213 100 095 Fax: (+351) 213 100 079
---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org