You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Julio C. Rivera" <Ju...@carm.es> on 2004/01/14 17:54:15 UTC

Re: example of PropertySelection with EnumPropertySelectionModel

This is my implementation for a MonthSelectionModel (with 
internationalization). I don't use EnumPropertySelectionModel. I have made 
a class implementing IPropertySelectionModel:

import java.text.DateFormatSymbols;
import java.util.Locale;
import org.apache.tapestry.form.IPropertySelectionModel;

public class MonthSelectionModel implements IPropertySelectionModel{

  String[] months = null;

  public MonthSelectionModel(Locale locale) {
     months = (new DateFormatSymbols(locale)).getMonths();
  }

  public int getOptionCount() {
     return 12;
  }

  public Object getOption(int value) {
     return new Integer(value+1);
  }

  public String getLabel(int value) {
     return months[value];
  }

  public String getValue(int value) {
     return String.valueOf(value);
  }

  public Object translateValue(String value) {
     if ((value == null) || (value.length() == 0))
        return null;
     return getOption(Integer.parseInt(value));
  }
}

Note: I use integers (1..12) for months values. If you want another type 
you can change it easily.

I Hope this helps.
    Julio.


At 17:34 14/01/2004, you wrote:

>On Jan 14, 2004, at 8:16 AM, Jamie Orchard-Hays wrote:
>
>>Looks like you're on the right track. If none of the implementations of
>>IPropertySelectionModel work for you, you can pretty easily write your own.
>>We've done a few here at Darden.
>
>Well I found an example of the EnumPropertySelectionModel in the Tapestry 
>source. But I'm not sure it's what I want. The example I found uses the 
>values of CHILD, TEEN, etc. to mark off these ranges. Then there is a 
>string associated with the values. If I want to do the same thing with 
>Months (which will be stored and converted to an actual date 
>representation I would do:
>MonthEnum JAN = new MonthEnum("1");
>MonthEnum FEB = new MonthEnum("2");
>
>does this make sense? Or is there another way to do this that I'm missing?
>
>Thanks,
>Warner
>
>>
>>PageBeginRender() is the place to set up those values on your page.
>>
>>I'm not sure how you'd deal with the last item.
>>
>>Jamie
>>
>>
>>----- Original Message -----
>>From: "Warner Onstine" <sw...@warneronstine.com>
>>To: "Tapestry users" <ta...@jakarta.apache.org>
>>Sent: Tuesday, January 13, 2004 6:37 PM
>>Subject: example of PropertySelection with EnumPropertySelectionModel
>>
>>
>>>Hi all,
>>>I am converting a form that is currently in PHP over to Tapestry and am
>>>running into a small problem. I think that the
>>>EnumPropertySelectionModel is what I want to use, but I don't know
>>>where there is an example of it (the web site only has the String
>>>model).
>>>
>>>Here is what I need to convert:
>>>I have three drop-downs, one for month, one for day, one for year. Each
>>>of these needs to get turned into a select in Tapestry. Yeah, it would
>>>be nice to have the month locale specific, but not necessary at this
>>>point.
>>>
>>>Also, this needs to be implemented as I currently have it in PHP. When
>>>a user visits this page the month, day and year all default to today's
>>>date. I figure I can set these in the PageBeginRender method, is that
>>>true?
>>>
>>>Ahh, another issue I need to address. The date selected in the
>>>drop-downs cannot be before today's date. This sounds like I would need
>>>to do a custom validator, yes?
>>>
>>>Thanks for the help.
>>>
>>>-warner
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org

*************************************************
Julio C. Rivera Riquelme
Unidad de Informática
Gerencia de Atención Primaria de Murcia
C\ Escultor Sanchez Lozano, 7
*************************************************


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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
> 	public Object getOption(int value) {
> 	   System.out.println("MonthSelectionModel - calling getOption with : 
> " + value);
> 	   return new Integer(value+1);
> 	}



> 	public Object translateValue(String value) {
> 		System.out.println("MonthSelectionModel - calling translateValue 
> with : " + value);
> 	   if ((value == null) || (value.length() == 0))
> 		  return null;
> 	   return getOption(Integer.parseInt(value));
> 	}


So make month an Integer instead of String.  Both of these methods 
return Integer.

	Erik



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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Harish Krishnaswamy <hk...@comcast.net>.
getValue() is the "value" of the option element. translateValue() translates the "value" of the 
option element into a domain object. For example let's say you have enums JANUARY thru' DECEMBER of 
type Month, the getValue() should convert the enums into a String value that can be displayed in the 
option element and translateValue() should convert the selected element String value back to the 
appropriate enum. Hope this is clear enough.

-Harish

Warner Onstine wrote:
> Ok,
> Just looking through the code a bit and I am unclear on exactly what all 
> the different methods are *supposed* to do. I think that this is the 
> main problem. I'm not sure what each one is exactly supposed to do and 
> the two SelectionModels in the tree aren't helping me determine that 
> unfortunately.
> 
> Let me break down what I'm doing and see if this makes sense.
> I have month which has an integer value but is stored as a string going 
> back and forth between the form. Now the option value that is displayed 
> when it renders is 0 - 11, which threw me at first. But now I think I 
> understand that it is only using that as the lookup value for what is 
> the real value. Now is translateValue(int index) supposed to return the 
> real value? If so, then what does getValue(int index) supposed to do 
> specifically?
> 
> Thanks for all the help I really do appreciate it.
> 
> -warner
> 
> On Jan 16, 2004, at 9:17 AM, Erik Hatcher wrote:
> 
>> On Jan 16, 2004, at 10:45 AM, Warner Onstine wrote:
>>
>>>> So make month an Integer instead of String.  Both of these methods 
>>>> return Integer.
>>>
>>>
>>> Maybe I'm misunderstanding. So, I changed these methods to return a 
>>> String instead of an Integer and it still isn't working. Were you 
>>> saying to change the startDateMon to an Integer? But if I changed 
>>> these to both return strings, shouldn't that work the same way?
>>
>>
>> Yes, I think so.  But I'm not at a place where I can try this out 
>> currently.  We've done a lot with custom property selection models 
>> though with no problems.  It can be a little confusing what goes in 
>> and comes out - but a little trial and error has always fixed things 
>> up for us.
>>
>>     Erik
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Warner Onstine <sw...@warneronstine.com>.
Ok,
Just looking through the code a bit and I am unclear on exactly what 
all the different methods are *supposed* to do. I think that this is 
the main problem. I'm not sure what each one is exactly supposed to do 
and the two SelectionModels in the tree aren't helping me determine 
that unfortunately.

Let me break down what I'm doing and see if this makes sense.
I have month which has an integer value but is stored as a string going 
back and forth between the form. Now the option value that is displayed 
when it renders is 0 - 11, which threw me at first. But now I think I 
understand that it is only using that as the lookup value for what is 
the real value. Now is translateValue(int index) supposed to return the 
real value? If so, then what does getValue(int index) supposed to do 
specifically?

Thanks for all the help I really do appreciate it.

-warner

On Jan 16, 2004, at 9:17 AM, Erik Hatcher wrote:

> On Jan 16, 2004, at 10:45 AM, Warner Onstine wrote:
>>> So make month an Integer instead of String.  Both of these methods 
>>> return Integer.
>>
>> Maybe I'm misunderstanding. So, I changed these methods to return a 
>> String instead of an Integer and it still isn't working. Were you 
>> saying to change the startDateMon to an Integer? But if I changed 
>> these to both return strings, shouldn't that work the same way?
>
> Yes, I think so.  But I'm not at a place where I can try this out 
> currently.  We've done a lot with custom property selection models 
> though with no problems.  It can be a little confusing what goes in 
> and comes out - but a little trial and error has always fixed things 
> up for us.
>
> 	Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>



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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Warner Onstine <sw...@warneronstine.com>.
How soon ;-)? I'm already signed up and have got the first 3 chapters.

-warner

On Jan 16, 2004, at 9:27 AM, Howard M. Lewis Ship wrote:

> Chapter 04 of the book should be online shortly; it covers 
> PropertySelection is pretty good detail,
> including diagrams of just how the PS and the model interact.
>
> --
> Howard M. Lewis Ship
> Independent J2EE / Open-Source Java Consultant
> Creator, Tapestry: Java Web Components
> http://jakarta.apache.org/tapestry/
> http://javatapestry.blogspot.com
>
>> -----Original Message-----
>> From: Erik Hatcher [mailto:erik@ehatchersolutions.com]
>> Sent: Friday, January 16, 2004 11:18 AM
>> To: Tapestry users
>> Subject: Re: example of PropertySelection with
>> EnumPropertySelectionModel
>>
>>
>> On Jan 16, 2004, at 10:45 AM, Warner Onstine wrote:
>>>> So make month an Integer instead of String.  Both of these methods
>>>> return Integer.
>>>
>>> Maybe I'm misunderstanding. So, I changed these methods to return a
>>> String instead of an Integer and it still isn't working. Were you
>>> saying to change the startDateMon to an Integer? But if I changed
>>> these to both return strings, shouldn't that work the same way?
>>
>> Yes, I think so.  But I'm not at a place where I can try this out
>> currently.  We've done a lot with custom property selection models
>> though with no problems.  It can be a little confusing what
>> goes in and
>> comes out - but a little trial and error has always fixed
>> things up for
>> us.
>>
>> 	Erik
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>



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


RE: example of PropertySelection with EnumPropertySelectionModel

Posted by "Howard M. Lewis Ship" <hl...@comcast.net>.
Chapter 04 of the book should be online shortly; it covers PropertySelection is pretty good detail,
including diagrams of just how the PS and the model interact.

--
Howard M. Lewis Ship
Independent J2EE / Open-Source Java Consultant
Creator, Tapestry: Java Web Components 
http://jakarta.apache.org/tapestry/
http://javatapestry.blogspot.com

> -----Original Message-----
> From: Erik Hatcher [mailto:erik@ehatchersolutions.com] 
> Sent: Friday, January 16, 2004 11:18 AM
> To: Tapestry users
> Subject: Re: example of PropertySelection with 
> EnumPropertySelectionModel
> 
> 
> On Jan 16, 2004, at 10:45 AM, Warner Onstine wrote:
> >> So make month an Integer instead of String.  Both of these methods 
> >> return Integer.
> >
> > Maybe I'm misunderstanding. So, I changed these methods to return a 
> > String instead of an Integer and it still isn't working. Were you 
> > saying to change the startDateMon to an Integer? But if I changed 
> > these to both return strings, shouldn't that work the same way?
> 
> Yes, I think so.  But I'm not at a place where I can try this out 
> currently.  We've done a lot with custom property selection models 
> though with no problems.  It can be a little confusing what 
> goes in and 
> comes out - but a little trial and error has always fixed 
> things up for 
> us.
> 
> 	Erik
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 


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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 16, 2004, at 10:45 AM, Warner Onstine wrote:
>> So make month an Integer instead of String.  Both of these methods 
>> return Integer.
>
> Maybe I'm misunderstanding. So, I changed these methods to return a 
> String instead of an Integer and it still isn't working. Were you 
> saying to change the startDateMon to an Integer? But if I changed 
> these to both return strings, shouldn't that work the same way?

Yes, I think so.  But I'm not at a place where I can try this out 
currently.  We've done a lot with custom property selection models 
though with no problems.  It can be a little confusing what goes in and 
comes out - but a little trial and error has always fixed things up for 
us.

	Erik


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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Warner Onstine <sw...@warneronstine.com>.
On Jan 16, 2004, at 7:54 AM, Erik Hatcher wrote:

>> 	public Object getOption(int value) {
>> 	   System.out.println("MonthSelectionModel - calling getOption with 
>> : " + value);
>> 	   return new Integer(value+1);
>> 	}
>
>
>
>> 	public Object translateValue(String value) {
>> 		System.out.println("MonthSelectionModel - calling translateValue 
>> with : " + value);
>> 	   if ((value == null) || (value.length() == 0))
>> 		  return null;
>> 	   return getOption(Integer.parseInt(value));
>> 	}
>
>
> So make month an Integer instead of String.  Both of these methods 
> return Integer.

Maybe I'm misunderstanding. So, I changed these methods to return a 
String instead of an Integer and it still isn't working. Were you 
saying to change the startDateMon to an Integer? But if I changed these 
to both return strings, shouldn't that work the same way?

-warner

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



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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
> 	public Object getOption(int value) {
> 	   System.out.println("MonthSelectionModel - calling getOption with : 
> " + value);
> 	   return new Integer(value+1);
> 	}



> 	public Object translateValue(String value) {
> 		System.out.println("MonthSelectionModel - calling translateValue 
> with : " + value);
> 	   if ((value == null) || (value.length() == 0))
> 		  return null;
> 	   return getOption(Integer.parseInt(value));
> 	}


So make month an Integer instead of String.  Both of these methods 
return Integer.

	Erik



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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Warner Onstine <sw...@warneronstine.com>.
Here's the MonthSelectionModel
private String months[];
	
	public MonthSelectionModel(Locale locale) {
	   this.months = (new DateFormatSymbols(locale)).getMonths();
	}

	public int getOptionCount() {
	   return 12;
	}

	public Object getOption(int value) {
	   System.out.println("MonthSelectionModel - calling getOption with :  
" + value);
	   return new Integer(value+1);
	}

	public String getLabel(int value) {
		System.out.println("MonthSelectionModel - calling getLabel with : " +  
value);
	   return months[value];
	}

	public String getValue(int value) {
		System.out.println("MonthSelectionModel - calling getValue with : " +  
value);
	   return String.valueOf(value);
	}

	public Object translateValue(String value) {
		System.out.println("MonthSelectionModel - calling translateValue with  
: " + value);
	   if ((value == null) || (value.length() == 0))
		  return null;
	   return getOption(Integer.parseInt(value));
	}

On Jan 16, 2004, at 6:46 AM, Erik Hatcher wrote:

>
> On Jan 16, 2004, at 8:36 AM, Warner Onstine wrote:
>> .html
>> <span jwcid="month@PropertySelection"  
>> model="ognl: 
>> @com.sandcast.caelum.events.client.pages.PostEvent@MONTH_MODEL"  
>> value="ognl:startDateMon"/>
>> <span jwcid="day@PropertySelection"  
>> model="ognl: 
>> @com.sandcast.caelum.events.client.pages.PostEvent@DAY_MODEL"  
>> value="ognl:startDateDay"/>
>> <span jwcid="year@PropertySelection"  
>> model="ognl: 
>> @com.sandcast.caelum.events.client.pages.PostEvent@YEAR_MODEL"  
>> value="ognl:startDateYear"/>
>>
>> .page
>> <property-specification name="startDateMon" type="java.lang.String"/>
>
> So the day and year work fine?  My guess is that your month model is  
> not using a String - I don't have the previous message with that month  
> model code, but I suspect it is something funky like a type mismatch.
>
> 	Erik
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>



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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 16, 2004, at 8:36 AM, Warner Onstine wrote:
> .html
> <span jwcid="month@PropertySelection"  
> model="ognl: 
> @com.sandcast.caelum.events.client.pages.PostEvent@MONTH_MODEL"  
> value="ognl:startDateMon"/>
> <span jwcid="day@PropertySelection"  
> model="ognl: 
> @com.sandcast.caelum.events.client.pages.PostEvent@DAY_MODEL"  
> value="ognl:startDateDay"/>
> <span jwcid="year@PropertySelection"  
> model="ognl: 
> @com.sandcast.caelum.events.client.pages.PostEvent@YEAR_MODEL"  
> value="ognl:startDateYear"/>
>
> .page
> <property-specification name="startDateMon" type="java.lang.String"/>

So the day and year work fine?  My guess is that your month model is  
not using a String - I don't have the previous message with that month  
model code, but I suspect it is something funky like a type mismatch.

	Erik


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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Warner Onstine <sw...@warneronstine.com>.
.html
<span jwcid="month@PropertySelection"  
model="ognl: 
@com.sandcast.caelum.events.client.pages.PostEvent@MONTH_MODEL"  
value="ognl:startDateMon"/>
<span jwcid="day@PropertySelection"  
model="ognl: 
@com.sandcast.caelum.events.client.pages.PostEvent@DAY_MODEL"  
value="ognl:startDateDay"/>
<span jwcid="year@PropertySelection"  
model="ognl: 
@com.sandcast.caelum.events.client.pages.PostEvent@YEAR_MODEL"  
value="ognl:startDateYear"/>

.page
<property-specification name="startDateMon" type="java.lang.String"/>
<property-specification name="startDateDay" type="java.lang.String"/>
<property-specification name="startDateYear" type="java.lang.String"/>

.java
public static final IPropertySelectionModel MONTH_MODEL =
	new MonthSelectionModel(Locale.US);

public static final IPropertySelectionModel DAY_MODEL =
		new StringPropertySelectionModel(getDays());
		
public static final IPropertySelectionModel YEAR_MODEL =
		new StringPropertySelectionModel(getYears());

public abstract void setStartDateDay(String startDateDay);
public abstract String getStartDateDay();
	
public abstract void setStartDateYear(String startDateYear);
public abstract String getStartDateYear();

public abstract void setStartDateMon(String startDateMon);
public abstract String getStartDateMon();


The MontSelectionModel is identical to what was posted earlier. I've  
tried some changes like change months = (new  
DateFormatSymbols(locale)).getMonths(); to this.months = value (as is  
done in the StringSelectionModel), but it didn't fix the problem.

Let me know if you need the full files.

-warner

On Jan 16, 2004, at 1:05 AM, Erik Hatcher wrote:

> On Jan 15, 2004, at 11:08 PM, Warner Onstine wrote:
>> I'm having a problem with this for some reason. I got the initial  
>> page to load fine, but when I try and set the value of the month  
>> (using the setProperty() method) it ignores it. The same happens  
>> after I submit the form (it doesn't seem to hold the value).
>>
>> Any ideas?
>
> What does your .page and .java file look like?
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>



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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 15, 2004, at 11:08 PM, Warner Onstine wrote:
> I'm having a problem with this for some reason. I got the initial page 
> to load fine, but when I try and set the value of the month (using the 
> setProperty() method) it ignores it. The same happens after I submit 
> the form (it doesn't seem to hold the value).
>
> Any ideas?

What does your .page and .java file look like?


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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Warner Onstine <sw...@warneronstine.com>.
I'm having a problem with this for some reason. I got the initial page  
to load fine, but when I try and set the value of the month (using the  
setProperty() method) it ignores it. The same happens after I submit  
the form (it doesn't seem to hold the value).

Any ideas?

-warner

On Jan 14, 2004, at 9:54 AM, Julio C. Rivera wrote:

> This is my implementation for a MonthSelectionModel (with  
> internationalization). I don't use EnumPropertySelectionModel. I have  
> made a class implementing IPropertySelectionModel:
>
> import java.text.DateFormatSymbols;
> import java.util.Locale;
> import org.apache.tapestry.form.IPropertySelectionModel;
>
> public class MonthSelectionModel implements IPropertySelectionModel{
>
>  String[] months = null;
>
>  public MonthSelectionModel(Locale locale) {
>     months = (new DateFormatSymbols(locale)).getMonths();
>  }
>
>  public int getOptionCount() {
>     return 12;
>  }
>
>  public Object getOption(int value) {
>     return new Integer(value+1);
>  }
>
>  public String getLabel(int value) {
>     return months[value];
>  }
>
>  public String getValue(int value) {
>     return String.valueOf(value);
>  }
>
>  public Object translateValue(String value) {
>     if ((value == null) || (value.length() == 0))
>        return null;
>     return getOption(Integer.parseInt(value));
>  }
> }
>
> Note: I use integers (1..12) for months values. If you want another  
> type you can change it easily.
>
> I Hope this helps.
>    Julio.
>
>
> At 17:34 14/01/2004, you wrote:
>
>> On Jan 14, 2004, at 8:16 AM, Jamie Orchard-Hays wrote:
>>
>>> Looks like you're on the right track. If none of the implementations  
>>> of
>>> IPropertySelectionModel work for you, you can pretty easily write  
>>> your own.
>>> We've done a few here at Darden.
>>
>> Well I found an example of the EnumPropertySelectionModel in the  
>> Tapestry source. But I'm not sure it's what I want. The example I  
>> found uses the values of CHILD, TEEN, etc. to mark off these ranges.  
>> Then there is a string associated with the values. If I want to do  
>> the same thing with Months (which will be stored and converted to an  
>> actual date representation I would do:
>> MonthEnum JAN = new MonthEnum("1");
>> MonthEnum FEB = new MonthEnum("2");
>>
>> does this make sense? Or is there another way to do this that I'm  
>> missing?
>>
>> Thanks,
>> Warner
>>
>>>
>>> PageBeginRender() is the place to set up those values on your page.
>>>
>>> I'm not sure how you'd deal with the last item.
>>>
>>> Jamie
>>>
>>>
>>> ----- Original Message -----
>>> From: "Warner Onstine" <sw...@warneronstine.com>
>>> To: "Tapestry users" <ta...@jakarta.apache.org>
>>> Sent: Tuesday, January 13, 2004 6:37 PM
>>> Subject: example of PropertySelection with EnumPropertySelectionModel
>>>
>>>
>>>> Hi all,
>>>> I am converting a form that is currently in PHP over to Tapestry  
>>>> and am
>>>> running into a small problem. I think that the
>>>> EnumPropertySelectionModel is what I want to use, but I don't know
>>>> where there is an example of it (the web site only has the String
>>>> model).
>>>>
>>>> Here is what I need to convert:
>>>> I have three drop-downs, one for month, one for day, one for year.  
>>>> Each
>>>> of these needs to get turned into a select in Tapestry. Yeah, it  
>>>> would
>>>> be nice to have the month locale specific, but not necessary at this
>>>> point.
>>>>
>>>> Also, this needs to be implemented as I currently have it in PHP.  
>>>> When
>>>> a user visits this page the month, day and year all default to  
>>>> today's
>>>> date. I figure I can set these in the PageBeginRender method, is  
>>>> that
>>>> true?
>>>>
>>>> Ahh, another issue I need to address. The date selected in the
>>>> drop-downs cannot be before today's date. This sounds like I would  
>>>> need
>>>> to do a custom validator, yes?
>>>>
>>>> Thanks for the help.
>>>>
>>>> -warner
>>>>
>>>>
>>>>
>>>> -------------------------------------------------------------------- 
>>>> -
>>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:  
>>>> tapestry-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:  
>>> tapestry-user-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
> *************************************************
> Julio C. Rivera Riquelme
> Unidad de Informática
> Gerencia de Atención Primaria de Murcia
> C\ Escultor Sanchez Lozano, 7
> *************************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>



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


Re: example of PropertySelection with EnumPropertySelectionModel

Posted by Warner Onstine <sw...@warneronstine.com>.
Hmmm. Never have liked Javascript date pickers much, but I'll go ahead  
and give it a shot. Thanks for pointing that out.

-warner

On Jan 14, 2004, at 3:38 PM, Peter Butler wrote:

> You could also use the DatePicker component for selecting a date - much
> more user-friendly than three drop-down boxes.
>
> -----Original Message-----
> From: Julio C. Rivera [mailto:JulioC.Rivera@carm.es]
> Sent: Thursday, 15 January 2004 5:54 a.m.
> To: Tapestry users
> Subject: Re: example of PropertySelection with
> EnumPropertySelectionModel
>
>
> This is my implementation for a MonthSelectionModel (with
> internationalization). I don't use EnumPropertySelectionModel. I have
> made
> a class implementing IPropertySelectionModel:
>
> import java.text.DateFormatSymbols;
> import java.util.Locale;
> import org.apache.tapestry.form.IPropertySelectionModel;
>
> public class MonthSelectionModel implements IPropertySelectionModel{
>
>   String[] months = null;
>
>   public MonthSelectionModel(Locale locale) {
>      months = (new DateFormatSymbols(locale)).getMonths();
>   }
>
>   public int getOptionCount() {
>      return 12;
>   }
>
>   public Object getOption(int value) {
>      return new Integer(value+1);
>   }
>
>   public String getLabel(int value) {
>      return months[value];
>   }
>
>   public String getValue(int value) {
>      return String.valueOf(value);
>   }
>
>   public Object translateValue(String value) {
>      if ((value == null) || (value.length() == 0))
>         return null;
>      return getOption(Integer.parseInt(value));
>   }
> }
>
> Note: I use integers (1..12) for months values. If you want another  
> type
>
> you can change it easily.
>
> I Hope this helps.
>     Julio.
>
>
> At 17:34 14/01/2004, you wrote:
>
>> On Jan 14, 2004, at 8:16 AM, Jamie Orchard-Hays wrote:
>>
>>> Looks like you're on the right track. If none of the implementations
>>> of IPropertySelectionModel work for you, you can pretty easily write
>>> your own. We've done a few here at Darden.
>>
>> Well I found an example of the EnumPropertySelectionModel in the
>> Tapestry
>> source. But I'm not sure it's what I want. The example I found uses  
>> the
>
>> values of CHILD, TEEN, etc. to mark off these ranges. Then there is a
>> string associated with the values. If I want to do the same thing with
>> Months (which will be stored and converted to an actual date
>> representation I would do:
>> MonthEnum JAN = new MonthEnum("1");
>> MonthEnum FEB = new MonthEnum("2");
>>
>> does this make sense? Or is there another way to do this that I'm
>> missing?
>>
>> Thanks,
>> Warner
>>
>>>
>>> PageBeginRender() is the place to set up those values on your page.
>>>
>>> I'm not sure how you'd deal with the last item.
>>>
>>> Jamie
>>>
>>>
>>> ----- Original Message -----
>>> From: "Warner Onstine" <sw...@warneronstine.com>
>>> To: "Tapestry users" <ta...@jakarta.apache.org>
>>> Sent: Tuesday, January 13, 2004 6:37 PM
>>> Subject: example of PropertySelection with EnumPropertySelectionModel
>>>
>>>
>>>> Hi all,
>>>> I am converting a form that is currently in PHP over to Tapestry and
>>>> am running into a small problem. I think that the
>>>> EnumPropertySelectionModel is what I want to use, but I don't know
>>>> where there is an example of it (the web site only has the String
>>>> model).
>>>>
>>>> Here is what I need to convert:
>>>> I have three drop-downs, one for month, one for day, one for year.
>>>> Each of these needs to get turned into a select in Tapestry. Yeah,  
>>>> it
>
>>>> would be nice to have the month locale specific, but not necessary  
>>>> at
>
>>>> this point.
>>>>
>>>> Also, this needs to be implemented as I currently have it in PHP.
>>>> When a user visits this page the month, day and year all default to
>>>> today's date. I figure I can set these in the PageBeginRender  
>>>> method,
>
>>>> is that true?
>>>>
>>>> Ahh, another issue I need to address. The date selected in the
>>>> drop-downs cannot be before today's date. This sounds like I would
>>>> need to do a custom validator, yes?
>>>>
>>>> Thanks for the help.
>>>>
>>>> -warner
>>>>
>>>>
>>>>
>>>> -------------------------------------------------------------------- 
>>>> -
>>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>> For additional commands, e-mail:
>>>> tapestry-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>> For additional commands, e-mail:  
>>> tapestry-user-help@jakarta.apache.org
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
> *************************************************
> Julio C. Rivera Riquelme
> Unidad de Informática
> Gerencia de Atención Primaria de Murcia
> C\ Escultor Sanchez Lozano, 7
> *************************************************
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


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


RE: example of PropertySelection with EnumPropertySelectionModel

Posted by Peter Butler <pe...@141.com>.
You could also use the DatePicker component for selecting a date - much
more user-friendly than three drop-down boxes.

-----Original Message-----
From: Julio C. Rivera [mailto:JulioC.Rivera@carm.es] 
Sent: Thursday, 15 January 2004 5:54 a.m.
To: Tapestry users
Subject: Re: example of PropertySelection with
EnumPropertySelectionModel


This is my implementation for a MonthSelectionModel (with 
internationalization). I don't use EnumPropertySelectionModel. I have
made 
a class implementing IPropertySelectionModel:

import java.text.DateFormatSymbols;
import java.util.Locale;
import org.apache.tapestry.form.IPropertySelectionModel;

public class MonthSelectionModel implements IPropertySelectionModel{

  String[] months = null;

  public MonthSelectionModel(Locale locale) {
     months = (new DateFormatSymbols(locale)).getMonths();
  }

  public int getOptionCount() {
     return 12;
  }

  public Object getOption(int value) {
     return new Integer(value+1);
  }

  public String getLabel(int value) {
     return months[value];
  }

  public String getValue(int value) {
     return String.valueOf(value);
  }

  public Object translateValue(String value) {
     if ((value == null) || (value.length() == 0))
        return null;
     return getOption(Integer.parseInt(value));
  }
}

Note: I use integers (1..12) for months values. If you want another type

you can change it easily.

I Hope this helps.
    Julio.


At 17:34 14/01/2004, you wrote:

>On Jan 14, 2004, at 8:16 AM, Jamie Orchard-Hays wrote:
>
>>Looks like you're on the right track. If none of the implementations 
>>of IPropertySelectionModel work for you, you can pretty easily write 
>>your own. We've done a few here at Darden.
>
>Well I found an example of the EnumPropertySelectionModel in the 
>Tapestry
>source. But I'm not sure it's what I want. The example I found uses the

>values of CHILD, TEEN, etc. to mark off these ranges. Then there is a 
>string associated with the values. If I want to do the same thing with 
>Months (which will be stored and converted to an actual date 
>representation I would do:
>MonthEnum JAN = new MonthEnum("1");
>MonthEnum FEB = new MonthEnum("2");
>
>does this make sense? Or is there another way to do this that I'm 
>missing?
>
>Thanks,
>Warner
>
>>
>>PageBeginRender() is the place to set up those values on your page.
>>
>>I'm not sure how you'd deal with the last item.
>>
>>Jamie
>>
>>
>>----- Original Message -----
>>From: "Warner Onstine" <sw...@warneronstine.com>
>>To: "Tapestry users" <ta...@jakarta.apache.org>
>>Sent: Tuesday, January 13, 2004 6:37 PM
>>Subject: example of PropertySelection with EnumPropertySelectionModel
>>
>>
>>>Hi all,
>>>I am converting a form that is currently in PHP over to Tapestry and 
>>>am running into a small problem. I think that the 
>>>EnumPropertySelectionModel is what I want to use, but I don't know 
>>>where there is an example of it (the web site only has the String 
>>>model).
>>>
>>>Here is what I need to convert:
>>>I have three drop-downs, one for month, one for day, one for year. 
>>>Each of these needs to get turned into a select in Tapestry. Yeah, it

>>>would be nice to have the month locale specific, but not necessary at

>>>this point.
>>>
>>>Also, this needs to be implemented as I currently have it in PHP. 
>>>When a user visits this page the month, day and year all default to 
>>>today's date. I figure I can set these in the PageBeginRender method,

>>>is that true?
>>>
>>>Ahh, another issue I need to address. The date selected in the 
>>>drop-downs cannot be before today's date. This sounds like I would 
>>>need to do a custom validator, yes?
>>>
>>>Thanks for the help.
>>>
>>>-warner
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: 
>>>tapestry-user-help@jakarta.apache.org
>>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org

*************************************************
Julio C. Rivera Riquelme
Unidad de Informática
Gerencia de Atención Primaria de Murcia
C\ Escultor Sanchez Lozano, 7
*************************************************


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



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