You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Katarzyna Chmurzyńska <kc...@gazeta.pl> on 2004/12/14 00:25:52 UTC

Velocity, Struts, DynaValidatorForm and HashMap

Hi,
I have problem in using all the thing above together:
what I want to do:

I have a template where are several text inputs, all of the same name (I 
don't know their number, but I want to validate them all in the same way)
They are for example numbers from 0 to 5 for some kind of products, but 
I also want to remember (in some way) in page the ID numbers for the 
products.
So HashMap (where ID is key and number is value) would be the best.
There is no problem in prosessing values to the template, but is there 
any way to get all the keys and values for them, from the page sending a 
POST? can I get all the pairs from one HashMap object ?

eg. code:
_____ struts-config ______
<form-bean name="productsForm" type="DynaValidatorForm">
            <form-property name="products" type="java.util.HashMap"/>
</form-bean>

______ template ______
#foreach ($key in $products.keySet())
   <input type="text" name="products" 
value="$productsForm.products.get($key)"/>
#end

______ action ______
public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws IOException, 
ServletException
    {
          DynaActionForm f = (DynaActionForm) form;
          HashMap hm = f.get("products");
     }

When I try so I always get :

ConversionException: Cannot assign value of type 'java.lang.String' to property 'products' of type 'java.util.HashMap'



can anyone help me ???

kate



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


Re: Velocity, Struts, DynaValidatorForm and HashMap

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Katarzyna,

> >I don't know about DynaActionForms, but you can achieve something
> >similar using Map-backed ActionForms.
> >  http://struts.apache.org/userGuide/building_controller.html#map_action_form_classes
> >
> >
> >
> >
> thanks for response :)
> unfortunatelly I looked at it and it works (only?) with JSP
> I tried to used it with Velocity but without any results :(

That's strange, I've done it before.  It's not a JSP thing, but a
Struts thing.  All you have to know, is how to map JSP(taglibs) to
Velocity.

Using the FooForm in the example, you should be able to do something like this:
<input type=text name="value(foo)" value="$fooForm.getValue('foo')" />
## forgot the details, but the important part is the name attribute.

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>

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


Re: Velocity, Struts, DynaValidatorForm and HashMap

Posted by Katarzyna Chmurzyńska <kc...@gazeta.pl>.
Shinobu Kawai wrote:

>
>I don't know about DynaActionForms, but you can achieve something
>similar using Map-backed ActionForms.
>  http://struts.apache.org/userGuide/building_controller.html#map_action_form_classes
>
>
>  
>
thanks for response :)
unfortunatelly I looked at it and it works (only?) with JSP
I tried to used it with Velocity but without any results :(

kate



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


Re: Velocity, Struts, DynaValidatorForm and HashMap

Posted by Shinobu Kawai <sh...@gmail.com>.
Hi Katarzyna,

> I have a template where are several text inputs, all of the same name (I
> don't know their number, but I want to validate them all in the same way)
> They are for example numbers from 0 to 5 for some kind of products, but
> I also want to remember (in some way) in page the ID numbers for the
> products.
> So HashMap (where ID is key and number is value) would be the best.
> There is no problem in prosessing values to the template, but is there
> any way to get all the keys and values for them, from the page sending a
> POST? can I get all the pairs from one HashMap object ?

I don't know about DynaActionForms, but you can achieve something
similar using Map-backed ActionForms.
  http://struts.apache.org/userGuide/building_controller.html#map_action_form_classes

Best regards,
-- Shinobu Kawai

--
Shinobu Kawai <sh...@gmail.com>

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