Primitive types (int vs. java.lang.Integer) are always required because there's no way to indicate that a value is not present, i.e., null.
On Fri, Mar 6, 2009 at 11:57 PM, Borut Bolčina <borut.bolc...@gmail.com> wrote: > Hi, > > I am building a date input component with three select input fields > (day, month, year). Actually I am modifying the code from Alexander's > book. The goal is that the initial value of all three select > components are empty if the date parameter is not provided. Although > none of the t:select(s) has t:validate="required" > > <html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> > <t:select t:value="day" t:model="dayModel" t:encoder="encoder" > t:disabled="disabled" class="drop40" t:blankOption="always"/> > <t:select t:value="month" t:model="monthModel" t:disabled="disabled" > class="drop80" t:blankOption="always"/> > <t:select t:value="year" t:model="yearModel" t:encoder="encoder" > t:disabled="disabled" class="drop55" t:blankOption="always"/> > </html> > > the html generated includes this piece of javascript at the bottom: > > <!-- > Tapestry.DEBUG_ENABLED = true; > Tapestry.onDOMLoaded(function() { > Tapestry.init({"validate":[["select_1",[["required","You must provide > a value for Select 1."]]],["select",[["required","You must provide a > value for Select."]]]]}); > }); > // --> > > ...so when I submit the form I get two error bubbles - one for day, > and one for year. > > Any clues? > > > This is part of the custom component class: > > public class DayMonthYearDateInput implements Field { > > ... > �...@parameter(required = true) > private Date date; > > private Calendar c = Calendar.getInstance(); > > �...@setuprender > void setupCalendar() { > logger.info("setupCalendar() : " + date); > if (date!= null) { > c.setTime(date); > } > } > > public SelectModel getDayModel() { > return new IntegerSelectModel(1, 31); > } > > public SelectModel getYearModel() { > return new IntegerSelectModel(1960, 2010); > } > > public SelectModel getMonthModel() { > return new EnumSelectModel(Month.class, messages); > } > > public ValueEncoder getEncoder() { > return new IntegerValueEncoder(); > } > > public int getDay() { > logger.info("getDay() : " + c.get(Calendar.DATE)); > return (date==null)?0:c.get(Calendar.DATE); > } > > public void setDay(int day) { > c.set(Calendar.DATE, day); > } > > public Month getMonth() { > logger.info("getMonth() : " + Month.values()[c.get(Calendar.MONTH)]); > return (date==null)?null:Month.values()[c.get(Calendar.MONTH)]; > } > > public void setMonth(Month month) { > c.set(Calendar.MONTH, month.getOrder()); > } > > public int getYear() { > logger.info("getYear() : " + c.get(Calendar.YEAR)); > return (date==null)?0:c.get(Calendar.YEAR); > } > > } > > > Thanks, > Borut > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > -- Howard M. Lewis Ship Creator Apache Tapestry and Apache HiveMind --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org