You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Mike Kienenberger <mk...@alaska.net> on 2003/10/29 18:28:31 UTC

Re: Retrieve form elements from a velocity page

tkchris@netcourrier.com wrote:
> I have recently started learning velocity. I am now trying to use it as 
the view in my Struts application. But I am facing the following problem: 
"retrieve data displayed in my form elements."
>
> In my velocity page I write:
> ============================
> <input name="siret" type="text" id="siret" 
value="$!creationAdminOfForm.siret" size="17" maxlength="17" 
onFocus="MM_changeProp('siret','','style.backgroundColor','yellow','INPUT/TEXT')" 
onKeyUp="remplissage(this.value)" 
onBlur="MM_changeProp('siret','','style.backgroundColor','#FFFFFF','INPUT/TEXT');EstSiretValide(this.value)">
</td>
> ============================
> 
> The form is well displayed but when I fill and submit, I have a surprising 
result; nothing displayed!!! I try with other forms elements (checkBox, 
select); the result is still the same.
> 
> Please tell me WHAT I AM MISSING HERE? Please tell me where I can find web 
page examples formatted with velocity, containing form elements such as 
checkBoxes, select, textField, etc... 


To my casual glance, what you have seems workable.   It may be that your 
actual problem is generating the next page rather than collecting the data.  


In struts-config:
============
		<form-bean
            name="loginForm"
            type="org.apache.struts.validator.DynaValidatorForm">
            <form-property
                name="username"
                type="java.lang.String"/>
            <form-property
                name="password"
                type="java.lang.String"/>
		</form-bean
============

In my velocity page:
============
				<FORM method="POST" action="$link.setAction('LoginResult')">
					<strong>$msg.get("label.username"):</strong><BR /="">
					<INPUT type="text" name="username" value="$!{loginForm.username}" 
size="10" maxlength="32" class="login" id="userID" /><BR /="">
					<strong>$msg.get("label.password"):</strong><BR /="">
					<INPUT type="password" name="password" value="$!{loginForm.password}" 
size="10" maxlength="32" class="login" /><BR /="">
				</FORM>
============

In my Action, to read the data afterward:
============
		String userName = (String)((DynaValidatorForm)form).get("username");
		String password = (String)((DynaValidatorForm)form).get("password");
============


You can throw the following on your velocity page to see what's in the 
request context and verify that creationAdminOfForm exists:

<!-- request dump:
#foreach( $attribute in $request.attributeNames)
    $attribute
#end
-->

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