velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Colson" <tcol...@cisco.com>
Subject RE: velocity and radio button. Is there a better way?
Date Wed, 02 Jul 2003 22:01:32 GMT
Hey folks -
  Albert posted this to the DEV list, and I replied, but realized it
should be over here on Velocity-User.

Timo


> with velocity, I need to write a macro to display which radio value is
> selected, 
Yep, that's correct, but pretty easy, and one advantage over the bean
tag is that you see exactly what the HTML looks like and can change it
without recompiling the taglib. :-)

I use a macro like this one for a Yes/No/Unknown radio buttons:

#macro ( YesNoInput $fieldname $value)
    #if (! $value ) #set ($value = "") #end
    #set ($s=0)
    <input type="radio" value="Y"   name="$fieldname" #if ($value == "Y"
|| $value == "YES") #set ($s=1) checked #end >Yes
    <input type="radio" value="N"   name="$fieldname" #if ($value == "N"
|| $value == "NO" ) #set ($s=1) checked #end >No
    <input type="radio" value="UNK" name="$fieldname" #if ($s == 0)
checked #end>Unknown
#end

#YesNoInput ("happyCamper" $myForm.HappyCamper)


> and worse when the form is submitted, I need to go 
> through the request parameters to set the correct value.
Hmm... Velocity just creates the HTML, so just like the taglib, after
submission the Struts form is taking over and doing it's thing. There
might just be a field naming typo or something simple like that. I
wouldn't suspect Velocity has anything to do with it at this point.

> Man, I'd regret of not using velocity because of this!
> Any idea, suggestion is appreciated!
Heh heh... I don't think that will be necessary. :-)

Timo



> -----Original Message-----
> From: Albert Lu [mailto:alu@nmdp.org] 
> Sent: Wednesday, July 02, 2003 2:27 PM
> To: velocity-dev@jakarta.apache.org
> Subject: velocity and radio button. Is there a better way?
> 
> 
> Hi,
> 
> I encounter a problem with velocity and radio input box.
> 
> I want to migrate to velocity from JSP with Struts. But I see there is
> no way to persist value of a radio values to an attribute in my form
> bean "easily" like struts tag <bean:input ...>.
> 
> with velocity, I need to write a macro to display which radio value is
> selected, and worse when the form is submitted, I need to go 
> through the
> request parameters to set the correct value.
> 
> The real problem is in my form, there are roughly 50 questions using
> radio buttons and average 4 options in each question
> 
> html syntax of radio button:
>     <input type="radio" name="option1" value="1" 
> checked>option1</input>
> 
> 
> 
> Man, I'd regret of not using velocity because of this!
> 
> Any idea, suggestion is appreciated!
> 
> Albert Lu
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-dev-help@jakarta.apache.org
> 
> 



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


Mime
View raw message