You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jake Tom <ag...@yahoo.com> on 2008/06/25 07:36:00 UTC
FormTool doesn't work
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!
Thanks…
Re: FormTool doesn't work
Posted by jack-tom <ag...@yahoo.com>.
chris ,
>>> <html:text property="user.username"/>
in jsp,it works. but in velocity ,it doesn't work.
in User class,it has properties:username and password,and getter,setter
methord.
Christopher Schultz-2 wrote:
>
> Jack/Jake,
>
> jack-tom wrote:
>>>> <html:text property="user.username"/>
>
> On second look, shouldn't this be "<html:text property="user.user" />" ?
> You have no 'username' property on your bean. Now do you have
> 'getPassword'. This could be a problem.
>
>> i have tried:
>> #set ($username = $form.bean.user.username )
>> #set ($password = $form.bean.user.password )
>> <FORM method="POST" action="$link.setAction('/user')">
>> name : <INPUT type="text" name="$username">
>> password:<INPUT type="password" name="$password">
>>
>> but i can't get value in my action or actionform
>
> How about trying what I recommended in my original message:
>
>>>> form = $form
>>>> bean = $form.bean
>>>> user = $form.bean.user
>>>> username = $form.bean.user.username
>
> This will help uncover the problem. Also, please post the code for your
> entire bean class. Also, tell us what "$form.name" returns.
>
>> there are two reason why i do so:
>> 1. in action i needn't do:User user=new User();
>> user.setUsername(form.getUsername()) .....
>
> Why don't you need to do this? Are you using Struts 1 or Struts 2? I'm
> guessing Struts 1 since S2 shouldn't have ActionForms any longer...
>
>> 2. in actionform there are properties:username,password... and some
>> getter,setter method,while in User
>> class,it has the same.
>
> Please provide the code for those two classes.
>
>> nothing is perfect,may be you are right.
>
> I'm confident that FormTool works. Let me help you figure out what the
> problem is.
>
> -chris
>
>
>
>
--
View this message in context: http://www.nabble.com/FormTool-doesn%27t-work-tp18106592p18146934.html
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: FormTool doesn't work
Posted by Christopher Schultz <ch...@christopherschultz.net>.
Jack/Jake,
jack-tom wrote:
>>> <html:text property="user.username"/>
On second look, shouldn't this be "<html:text property="user.user" />" ?
You have no 'username' property on your bean. Now do you have
'getPassword'. This could be a problem.
> i have tried:
> #set ($username = $form.bean.user.username )
> #set ($password = $form.bean.user.password )
> <FORM method="POST" action="$link.setAction('/user')">
> name : <INPUT type="text" name="$username">
> password:<INPUT type="password" name="$password">
>
> but i can't get value in my action or actionform
How about trying what I recommended in my original message:
>>> form = $form
>>> bean = $form.bean
>>> user = $form.bean.user
>>> username = $form.bean.user.username
This will help uncover the problem. Also, please post the code for your
entire bean class. Also, tell us what "$form.name" returns.
> there are two reason why i do so:
> 1. in action i needn't do:User user=new User();
> user.setUsername(form.getUsername()) .....
Why don't you need to do this? Are you using Struts 1 or Struts 2? I'm
guessing Struts 1 since S2 shouldn't have ActionForms any longer...
> 2. in actionform there are properties:username,password... and some
> getter,setter method,while in User
> class,it has the same.
Please provide the code for those two classes.
> nothing is perfect,may be you are right.
I'm confident that FormTool works. Let me help you figure out what the
problem is.
-chris
Re: FormTool doesn't work
Posted by jack-tom <ag...@yahoo.com>.
Christopher Schultz-2 wrote:
>
> 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
>
i have tried:
#set ($username = $form.bean.user.username )
#set ($password = $form.bean.user.password )
<FORM method="POST" action="$link.setAction('/user')">
name : <INPUT type="text" name="$username">
password:<INPUT type="password" name="$password">
but i can't get value in my action or actionform
there are two reason why i do so:
1. in action i needn't do:User user=new User();
user.setUsername(form.getUsername()) .....
2. in actionform there are properties:username,password... and some
getter,setter methord,while in User
class,it has the same.
nothing is perfect,may be you are right.
Regards,
jake
--
View this message in context: http://www.nabble.com/FormTool-doesn%27t-work-tp18106592p18126379.html
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org
Re: FormTool doesn't work
Posted by Christopher Schultz <ch...@christopherschultz.net>.
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
Re: FormTool doesn't work
Posted by jack-tom <ag...@yahoo.com>.
hah,resolved!
<INPUT class='text' type='text' name='user.username'>
jack-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!
> Thanks…
>
>
>
>
--
View this message in context: http://www.nabble.com/FormTool-doesn%27t-work-tp18106592p18188504.html
Sent from the Velocity - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org