RE: Struts and Velocity Forms

2005-03-24 Thread Robin Mannering
Great!  I'll take a look, thanks for the tip. Robin

-Original Message-
From: Shinobu Kawai [mailto:[EMAIL PROTECTED]
Sent: 23 March 2005 18:18
To: Velocity Users List
Subject: Re: Struts and Velocity Forms


Hi Robin,

 Can you break out of a velicity foreach loop? Could get rid of the 'rendered' 
 boolean then.

Unfortunately, no.  But fortunately, we have the IteratorTool.  :)
   
http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/IteratorTool.html

Best regards,
-- Shinobu

--
Shinobu Kawai [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



This e-mail and any attachments may be confidential and/or legally
privileged. If you have received this e-mail and you are not a named
addressee, please inform Landmark Information Group on 01491 413030
and then delete the e-mail from your system. If you are not a named
addressee you must not use, disclose, distribute, copy, print or rely 
on this e-mail. This email and any attachments have been scanned for
viruses and to the best of our knowledge are clean. To ensure 
regulatory compliance and for the protection of our clients and 
business, we may monitor and read e-mails sent to and from our 
servers.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Struts and Velocity Forms

2005-03-23 Thread Robin Mannering
Hi all,

Continued working on this problem and have it resolved in the following 
Velocity macro.

I'm surprised it didn't already exist being a very common requirement (maybe it 
does but I just haven't found it !!)

---
#*
 * HTML velocimacro
 * @author Robin Mannering
*#
## Checkbox control. 'Remembers' checkbox choices made by user on previous form 
submission.
## $name The control name
## $selectedValues A list of currently checked values
## $labels The list of labels for the options
## $values The list of values for the options

#macro (checkboxGroup $name $selectedValues $labels $values)

## Use a zero-based counter.
#set ( $index = 0 )

#foreach( $value in $values )

#set ( $rendered = false )

#foreach( $selectedValue in $selectedValues )
#if ( $value == $selectedValue )
input type=checkbox name=$name 
value=$value checked$!labels.get($index)/inputbr/
#set ( $rendered = true )
#end
#end

#if ( $rendered == false )
## the current checkbox still hasn't been rendered it, 
so it must be rendered (unchecked)
input type=checkbox name=$name 
value=$value$!labels.get($index)/inputbr/
#end

#set ( $index = $index + 1 )
#end
#end
--

It can be used with the following example

#set ( $interestLabels = [snowboarding, 
skiing, mountain biking] )
#set ( $interestValues = [snowboarding, 
skiing, mountain biking] )
#set ( $selected = 
$!newsletterForm.interestsDisplay )

#checkboxGroup ( interestsDisplay $selected 
$interestLabels $interestValues )

NB. $selected is a String[] in associated Struts form.

-Original Message-
From: Robin Mannering [mailto:[EMAIL PROTECTED]
Sent: 23 March 2005 11:34
To: Velocity Users List
Subject: Struts and Velocity Forms


Hi all,

Another newbie question here.  I'm working with a StrutsForm that holds 
checkbox selections in a String[] as I normally do when working with struts.

In the form, I'm having difficulty pre-selecting checkbox options that the user 
set on a previous request, so far I have

#set ( $index = 0 )
#set ( $interestOptions = [snowboarding, 
skiing, mountain biking] )


#foreach( $interest in $interestOptions )

input type=checkbox 
name=interestsDisplay value=$interest #if (fillInTheBlanks) selected 
#end$interest/input  

#set ( $index = $index + 1 )
#end

Can somebody please tell be how I 'fillInTheBlanks'? Or point me to a resource 
on the web that would help me, I can't find a think on the velocity site.

Many thanks

Robin


This e-mail and any attachments may be confidential and/or legally
privileged. If you have received this e-mail and you are not a named
addressee, please inform Landmark Information Group on 01491 413030
and then delete the e-mail from your system. If you are not a named
addressee you must not use, disclose, distribute, copy, print or rely 
on this e-mail. This email and any attachments have been scanned for
viruses and to the best of our knowledge are clean. To ensure 
regulatory compliance and for the protection of our clients and 
business, we may monitor and read e-mails sent to and from our 
servers.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



This e-mail and any attachments may be confidential and/or legally
privileged. If you have received this e-mail and you are not a named
addressee, please inform Landmark Information Group on 01491 413030
and then delete the e-mail from your system. If you are not a named
addressee you must not use, disclose, distribute, copy, print or rely 
on this e-mail. This email and any attachments have been scanned for
viruses and to the best of our knowledge are clean. To ensure 
regulatory compliance and for the protection of our clients and 
business, we may monitor and read e-mails sent to and from our 
servers.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Struts and Velocity Forms

2005-03-23 Thread Charles N. Harvey III
What is being filled into the StrutsForm?
Is it something like:
public class MyForm
{
   private String[] interestOptions;
   public String[] getInterestOptions(){
   return this.interestOptions;
   }
   public void setInterestOptions( String[] sValue ){
   this.interestOptions = sValue;
   }
}
And in your Action class you are making sure that interestOptions
are filled in?  If so, you are actually blowing out the user's previous
selections by setting the array again.  You've got to have a different
variable for the selectedInterests and the interestOptions.  And then
you have to have a double #foreach loop looping through both arrays
(unless there is some way to get specific array values by index, which
I think there is but am not sure how to do it).
---
#set ( $index = 0 )
#set ( $interestOptions = [snowboarding, skiing, mountain biking] )
#foreach( $interest in $interestOptions )
   #foreach( $selection in $selectedInterests )
   input type=checkbox
  name=interestsDisplay
  value=$interest
  #if( $selection == $interest ) selected #end$interest/input
   #end
   #set ( $index = $index + 1 )
#end
---
Or, if there is a way to get array values:
---
#set ( $index = 0 )
#set ( $interestOptions = [snowboarding, skiing, mountain biking] )
#foreach( $interest in $interestOptions )
   input type=checkbox
  name=interestsDisplay
  value=$interest
  #if( $selectedInterest.get($index) == $interest ) selected 
#end$interest/input
   #set ( $index = $index + 1 )
#end
---
Hope some of that helps.
Charlie

Robin Mannering said the following on 3/23/2005 6:33 AM:
Hi all,
Another newbie question here.  I'm working with a StrutsForm that holds 
checkbox selections in a String[] as I normally do when working with struts.
In the form, I'm having difficulty pre-selecting checkbox options that the user 
set on a previous request, so far I have
#set ( $index = 0 )
#set ( $interestOptions = [snowboarding, skiing, 
mountain biking] )

#foreach( $interest in $interestOptions )

input type=checkbox name=interestsDisplay 
value=$interest #if (fillInTheBlanks) selected #end$interest/input


#set ( $index = $index + 1 )
#end
Can somebody please tell be how I 'fillInTheBlanks'? Or point me to a resource 
on the web that would help me, I can't find a think on the velocity site.
Many thanks
Robin

This e-mail and any attachments may be confidential and/or legally
privileged. If you have received this e-mail and you are not a named
addressee, please inform Landmark Information Group on 01491 413030
and then delete the e-mail from your system. If you are not a named
addressee you must not use, disclose, distribute, copy, print or rely 
on this e-mail. This email and any attachments have been scanned for
viruses and to the best of our knowledge are clean. To ensure 
regulatory compliance and for the protection of our clients and 
business, we may monitor and read e-mails sent to and from our 
servers.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

 

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: Struts and Velocity Forms

2005-03-23 Thread Robin Mannering
Hi Charlie,

Many thanks for that response...

I think we're both on the same train of thought here (with the nested loops).  
The main difference I think is determining if the checkbox had been rendered on 
each pass through the outer loop. The velocimacro I just submitted is the first 
I've written so it's possible it could be tighter/shorter.

Can you break out of a velicity foreach loop? Could get rid of the 'rendered' 
boolean then.

Thanks again for your input!

Robin

-Original Message-
From: Charles N. Harvey III [mailto:[EMAIL PROTECTED]
Sent: 23 March 2005 14:48
To: Velocity Users List
Subject: Re: Struts and Velocity Forms


What is being filled into the StrutsForm?

Is it something like:

public class MyForm
{
private String[] interestOptions;
public String[] getInterestOptions(){
return this.interestOptions;
}
public void setInterestOptions( String[] sValue ){
this.interestOptions = sValue;
}
}

And in your Action class you are making sure that interestOptions
are filled in?  If so, you are actually blowing out the user's previous
selections by setting the array again.  You've got to have a different
variable for the selectedInterests and the interestOptions.  And then
you have to have a double #foreach loop looping through both arrays
(unless there is some way to get specific array values by index, which
I think there is but am not sure how to do it).

---
#set ( $index = 0 )
#set ( $interestOptions = [snowboarding, skiing, mountain biking] )
#foreach( $interest in $interestOptions )
#foreach( $selection in $selectedInterests )
input type=checkbox
   name=interestsDisplay
   value=$interest
   #if( $selection == $interest ) selected #end$interest/input
#end
#set ( $index = $index + 1 )
#end
---
Or, if there is a way to get array values:
---
#set ( $index = 0 )
#set ( $interestOptions = [snowboarding, skiing, mountain biking] )
#foreach( $interest in $interestOptions )
input type=checkbox
   name=interestsDisplay
   value=$interest
   #if( $selectedInterest.get($index) == $interest ) selected 
#end$interest/input
#set ( $index = $index + 1 )
#end
---

Hope some of that helps.


Charlie



Robin Mannering said the following on 3/23/2005 6:33 AM:

Hi all,

Another newbie question here.  I'm working with a StrutsForm that holds 
checkbox selections in a String[] as I normally do when working with struts.

In the form, I'm having difficulty pre-selecting checkbox options that the 
user set on a previous request, so far I have

   #set ( $index = 0 )
   #set ( $interestOptions = [snowboarding, 
 skiing, mountain biking] )
   

   #foreach( $interest in $interestOptions )
   
   input type=checkbox 
 name=interestsDisplay value=$interest #if (fillInTheBlanks) selected 
 #end$interest/input  
   
   #set ( $index = $index + 1 )
   #end

Can somebody please tell be how I 'fillInTheBlanks'? Or point me to a resource 
on the web that would help me, I can't find a think on the velocity site.

Many thanks

Robin


This e-mail and any attachments may be confidential and/or legally
privileged. If you have received this e-mail and you are not a named
addressee, please inform Landmark Information Group on 01491 413030
and then delete the e-mail from your system. If you are not a named
addressee you must not use, disclose, distribute, copy, print or rely 
on this e-mail. This email and any attachments have been scanned for
viruses and to the best of our knowledge are clean. To ensure 
regulatory compliance and for the protection of our clients and 
business, we may monitor and read e-mails sent to and from our 
servers.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



  


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



This e-mail and any attachments may be confidential and/or legally
privileged. If you have received this e-mail and you are not a named
addressee, please inform Landmark Information Group

Re: Struts and Velocity Forms

2005-03-23 Thread Shinobu Kawai
Hi Robin,

 Can you break out of a velicity foreach loop? Could get rid of the 'rendered' 
 boolean then.

Unfortunately, no.  But fortunately, we have the IteratorTool.  :)
   
http://jakarta.apache.org/velocity/tools/javadoc/org/apache/velocity/tools/generic/IteratorTool.html

Best regards,
-- Shinobu

--
Shinobu Kawai [EMAIL PROTECTED]

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]