velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Schultz <ch...@christopherschultz.net>
Subject Re: FormTool doesn't work
Date Wed, 25 Jun 2008 14:16:40 GMT
Jake,

Jake Tom wrote:
> Hi good day,
> May I know how to use the velocity FormTool.. 
> publicclassUserForm extendsActionForm {
>  
>     privateUser user;
>     publicUserForm(){
>        this.user=newUser();
>     }
>     publicUser getUser() {
>        returnuser;
>     }
>     publicvoidsetUser(User user) {
>        this.user= user;
>     }
> …
> In jsp:
> <html:form action="/user">
> <html:text property="user.username"/>
> <html:text property="user.password"/>
> <html:submit value="submit"/>
> </html:form>
> In velocity how?
> <INPUT type="text" name="$form.bean.user.username"> doesn’t work!

This really looks like it should work. Can you try this:

form = $form
bean = $form.bean
user = $form.bean.user
username = $form.bean.user.username

and send us the output?

I have never used the FormTool like this, since Struts puts the form 
bean into the request for you already. So, if my form "name" (from 
struts-config.xml) for the action is "userForm", then I would just do 
this in my page:

<input type="text" name="$userForm.username" />

Note that you should always HTML-escape any data coming from the user to 
avoid XSS vulnerabilities as well as keeping your site looking nice. 
Also, it seems odd to use the user's username as a form element name. 
Just a thought.

-chris


Mime
View raw message