How to get DateField value
Hi i'm new to wicket, I wonder if any of yous can help me. I'm trying to get the date selected from DateField component when the date is changed. I've tried getConvertedInput() and getInput()but they just return null. Below is my code, I've striped it down to just display the date in the console to make things a bit easier. Thanks, Ryan public class TestFormPanel extends Panel{ protected DateField dateField; private static final long serialVersionUID = 1L; public TestFormPanel (String id){ super(id); dateField = new DateField(date, new Model(new Date())); add(dateField); dateField.add(new AjaxFormComponentUpdatingBehavior(onchange) { @Override protected void onUpdate(AjaxRequestTarget arg0) { System.out.println(new datee + dateField.getInput()); System.out.println(new datee + dateField.getConvertedInput()); } }); } }
Re: How to get DateField value
You can get the model Date d = dateField.getModelObject(); Format it by using the SimpleDateFormat -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24568750.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
Hi, Thanks for the reply. I've tried this too, but this also returns null. There is date in the textfield box of the datefield but for some reason it doen't get it Ryan On Mon, Jul 20, 2009 at 2:19 PM, Mathias Nilsson wicket.program...@gmail.com wrote: You can get the model Date d = dateField.getModelObject(); Format it by using the SimpleDateFormat -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24568750.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
The above code works for me. You know that the onchange method is only triggered when you click the textfield for focus and the click the webpage to lose focus have you put the field in a form? -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24570614.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
Ok, i tried this. But i get the date the DateField was initialised with ie today 20/07/09. If i change text field to 10/07/09 i still get the 20/07/09. I can get it working with a normal submit button but when i try anything with ajax i get the problem stated. Can paste the code that you got this working with? Thanks Ryan On Mon, Jul 20, 2009 at 4:11 PM, Mathias Nilsson wicket.program...@gmail.com wrote: The above code works for me. You know that the onchange method is only triggered when you click the textfield for focus and the click the webpage to lose focus have you put the field in a form? -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24570614.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
import java.util.Date; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.extensions.markup.html.form.DateTextField; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.model.Model; /** * Homepage */ public class HomePage extends WebPage{ private static final long serialVersionUID = 1L; protected DateTextField dateField; public HomePage() { FormVoid form = new FormVoid( form ); dateField = new DateTextField(date, new ModelDate(new Date())); dateField.add(new AjaxFormComponentUpdatingBehavior(onchange) { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget arg0) { Date d = dateField.getModelObject(); System.out.println( d ); } }); form.add( dateField ); add( form ); } } -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24574979.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
Yes, that does work for DateTextField. But i am using the DateField component which is a combination of DateTextField and DatePicker Ryan On Mon, Jul 20, 2009 at 8:25 PM, Mathias Nilsson wicket.program...@gmail.com wrote: import java.util.Date; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.extensions.markup.html.form.DateTextField; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.model.Model; /** * Homepage */ public class HomePage extends WebPage{ private static final long serialVersionUID = 1L; protected DateTextField dateField; public HomePage() { FormVoid form = new FormVoid( form ); dateField = new DateTextField(date, new ModelDate(new Date())); dateField.add(new AjaxFormComponentUpdatingBehavior(onchange) { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget arg0) { Date d = dateField.getModelObject(); System.out.println( d ); } }); form.add( dateField ); add( form ); } } -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24574979.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
from wicket-extension or from another project? -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24575317.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
wicket-extension. This one, org.apache.wicket.extensions.yui.calendar.DateField; On Mon, Jul 20, 2009 at 8:45 PM, Mathias Nilsson wicket.program...@gmail.com wrote: from wicket-extension or from another project? -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24575317.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
Ok this is wicket-datetime if I'm not misstaken. You must override the newDateTextField then import java.util.Date; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.datetime.markup.html.form.DateTextField; import org.apache.wicket.extensions.yui.calendar.DateField; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.model.Model; /** * Homepage */ public class HomePage extends WebPage{ private static final long serialVersionUID = 1L; protected DateField dateField; public HomePage() { FormVoid form = new FormVoid( form ); dateField = new DateField(date, new ModelDate(new Date())){ @Override protected DateTextField newDateTextField(java.lang.String id, org.apache.wicket.model.PropertyModel dateFieldModel){ DateTextField f = DateTextField.forShortStyle(id, dateFieldModel); f.add(new AjaxFormComponentUpdatingBehavior(onchange) { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget arg0) { Date d = dateField.getModelObject(); System.out.println( d ); } }); return f; } }; form.add( dateField ); add( form ); } } -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24575872.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
Ok this is wicket-datetime if I'm not misstaken. You must override the newDateTextField then import java.util.Date; import org.apache.wicket.ajax.AjaxRequestTarget; import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior; import org.apache.wicket.datetime.markup.html.form.DateTextField; import org.apache.wicket.extensions.yui.calendar.DateField; import org.apache.wicket.markup.html.WebPage; import org.apache.wicket.markup.html.form.Form; import org.apache.wicket.model.Model; /** * Homepage */ public class HomePage extends WebPage{ private static final long serialVersionUID = 1L; protected DateField dateField; public HomePage() { FormVoid form = new FormVoid( form ); dateField = new DateField(date, new ModelDate(new Date())){ @Override protected DateTextField newDateTextField(java.lang.String id, org.apache.wicket.model.PropertyModel dateFieldModel){ DateTextField f = DateTextField.forShortStyle(id, dateFieldModel); f.add(new AjaxFormComponentUpdatingBehavior(onchange) { private static final long serialVersionUID = 1L; @Override protected void onUpdate(AjaxRequestTarget arg0) { Date d = dateField.getModelObject(); System.out.println( d ); } }); return f; } }; form.add( dateField ); add( form ); } } -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24575929.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
You can also override the datepicker if you would like -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24576032.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
Also, how does your markup look? You should use the DateField with a span or div. -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24576073.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: How to get DateField value
It's working now. Overriding the newDateTextField worked. Thanks for your help On Mon, Jul 20, 2009 at 9:31 PM, Mathias Nilsson wicket.program...@gmail.com wrote: Also, how does your markup look? You should use the DateField with a span or div. -- View this message in context: http://www.nabble.com/How-to-get-DateField-value-tp24567634p24576073.html Sent from the Wicket - User mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org