You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Pat Quinn <pa...@hotmail.com> on 2003/09/29 13:35:26 UTC

DynaValidatorActionForm Setting Properties

I have an Action to prepare a JSP view which uses a DynaValidatorActionForm. 
When i try to set a Form property i get a NullPointerException my source is 
as follows:


-----------------
Struts-Config.xml
-----------------
<form-bean name="MyForm" 
type="org.apache.struts.action.DynaValidatorActionForm">
   <form-property name="myTestTO" type="com.mycompany.to.myTestTO"/>
</form-bean>


<action path="/viewTest"
	type="com.mycompany.actions.myTestAction"
        scope="request"
	input="my-tile-view"
        name="MyForm"
        validate="false">
        <forward name="success" path="success-tile"/>
</action>




--------------
VALIDATION.xml
--------------
<form-validation>
   <formset>
      <form name="MyForm">
         <field property="myTestTO.name"
         	   depends="required,minlength">
                     <var>
                       <var-name>minlength</var-name>
                       <var-value>10</var-value>
                     </var>
         </field>
      </form>
   </formset>

</form-validation>




--------------------------------------------------------------
ACTION SOURCE CODE (i.e. com.mycompany.actions.myTestAction)
--------------------------------------------------------------

DynaValidatorActionForm  myForm = new DynaValidatorActionForm();

myForm.set("myTestTO", new myTestTO()); /* THROWS NullPointerException 
Here!!!!*/

pRequest.setAttribute("MyForm", myForm );


I've also tried casting the inbound ActionForm to DynaValidatorActionForm 
but i still get the same error when i invoke the set method.



Any Ideas?

_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: DynaValidatorActionForm Setting Properties

Posted by Adam Hardy <ah...@cyberspaceroad.com>.
Hi Pat,

if you have to instantiate it yourself, you should call the initialize() 
method on the form first so that struts configures it to the 
struts-config settings.

However that probably won't help in this case since your in-bound form 
doesn't work either. I doubt it would help, but you could try naming 
your class with an initial capitalized letter. Secondly, does the 
exception from the inbound form have a message?

Regards
Adam

On 09/29/2003 01:35 PM Pat Quinn wrote:
> I have an Action to prepare a JSP view which uses a 
> DynaValidatorActionForm. When i try to set a Form property i get a 
> NullPointerException my source is as follows:
> 
> 
> -----------------
> Struts-Config.xml
> -----------------
> <form-bean name="MyForm" 
> type="org.apache.struts.action.DynaValidatorActionForm">
>   <form-property name="myTestTO" type="com.mycompany.to.myTestTO"/>
> </form-bean>
> 
> 
> <action path="/viewTest"
>     type="com.mycompany.actions.myTestAction"
>        scope="request"
>     input="my-tile-view"
>        name="MyForm"
>        validate="false">
>        <forward name="success" path="success-tile"/>
> </action>
> 
> 
> 
> 
> --------------
> VALIDATION.xml
> --------------
> <form-validation>
>   <formset>
>      <form name="MyForm">
>         <field property="myTestTO.name"
>                depends="required,minlength">
>                     <var>
>                       <var-name>minlength</var-name>
>                       <var-value>10</var-value>
>                     </var>
>         </field>
>      </form>
>   </formset>
> 
> </form-validation>
> 
> 
> 
> 
> --------------------------------------------------------------
> ACTION SOURCE CODE (i.e. com.mycompany.actions.myTestAction)
> --------------------------------------------------------------
> 
> DynaValidatorActionForm  myForm = new DynaValidatorActionForm();
> 
> myForm.set("myTestTO", new myTestTO()); /* THROWS NullPointerException 
> Here!!!!*/
> 
> pRequest.setAttribute("MyForm", myForm );
> 
> 
> I've also tried casting the inbound ActionForm to 
> DynaValidatorActionForm but i still get the same error when i invoke the 
> set method.
> 
> 
> 
> Any Ideas?
> 
> _________________________________________________________________
> The new MSN 8: smart spam protection and 2 months FREE*  
> http://join.msn.com/?page=features/junkmail
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 
> 

-- 
struts 1.1 + tomcat 4.1.27 + java 1.4.2
Linux 2.4.20 RH9


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org