Hi Anyone has any idea about this

wicketnewuser wrote:
> 
> 
> I have a page with date picker that picks the date, DropdownChoice for
> hour and minute. When I click "today" button I change the model in
> onsubmit method. It is suppose to change the form value in datepicker,
> hour and minute to today/now.This changes hour and minute but doesn't
> change the value in the
> datepicker. Is there something that I need to do to make this work. Here
> is the partial code
> 
> 
>       public void onSubmit() {
> 
>             Calendar startDate = Calendar.getInstance();
> 
>             
> 
>             // initialize end date
> 
>             Calendar endDate = Calendar.getInstance();
> 
>         
> 
>             model.getObject().setStartDate(startDate);
> 
>             model.getObject().setEndDate(endDate);
> 
>             getForm().modelChanged();
> 
>             super.onSubmit();
> 
>         }
> 
> Here is the whole code.
> 
> public final class DateTimeSelectionModel implements IClusterable {
>    
>     private Calendar startDate;
>     private Calendar endDate;
>     
>     public DateTimeSelectionModel() {
>         
>         // initialize start date
>         startDate = Calendar.getInstance();
>         startDate.add(Calendar.DATE, -5);
>         startDate.set(Calendar.HOUR_OF_DAY, 0);
>         startDate.set(Calendar.MINUTE, 0);
>         startDate.set(Calendar.SECOND, 0);
>         
>         // initialize end date
>         endDate = Calendar.getInstance();
>         endDate.add(Calendar.DATE, -5);
>         endDate.set(Calendar.HOUR_OF_DAY, 23);
>         endDate.set(Calendar.MINUTE, 59);
>         endDate.set(Calendar.SECOND, 59);
>         
>         System.out.println("hello");
>     }
>     
>     public void setStartDate(Calendar startDate) {
>         this.startDate = startDate;
>     }
> 
>     public void setEndDate(Calendar endDate) {
>         this.endDate = endDate;
>     }
> 
>     // this method is called to get the default for the form.
>     public Date getStartDate() {
>         return startDate.getTime();
>     }    
>     public void setStartDate(Date date) {
>         //we want to set only year month and day here not the whole date
>         Calendar cal = Calendar.getInstance();
>         cal.setTime(date);
>         this.startDate.set(cal.get(Calendar.YEAR),
> cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
>     }
> 
>     public SelectOption getStartHour() {
>         SelectOption option = new SelectOption("Unknown", new String("" +
> startDate.get(Calendar.HOUR_OF_DAY)));
>         return option;
>     }
>     public void setStartHour(SelectOption hour) {
>         startDate.set(Calendar.HOUR_OF_DAY,
> Integer.valueOf(hour.getValue()));
>     }
> 
>     public void setStartMinute(String minute) {
>         startDate.set(Calendar.MINUTE, Integer.valueOf(minute));
>     }
>     public void setStartMinute(int minute) {
>         startDate.set(Calendar.MINUTE, minute);
>     }
>     public int getStartMinute() {
>         return startDate.get(Calendar.MINUTE);
>     }
> 
>     
>     public Date getEndDate() {
>         return endDate.getTime();
>     }
>     public void setEndDate(Date date) {
>         //we want to set only year month and day here not the whole date
>         Calendar cal = Calendar.getInstance();
>         cal.setTime(date);
>         this.endDate.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
> cal.get(Calendar.DAY_OF_MONTH));
>     }
> 
>     public SelectOption getEndHour() {
>         SelectOption option = new SelectOption("Unknown", new String("" +
> endDate.get(Calendar.HOUR_OF_DAY)));
>         return option;
>     }
>     public void setEndHour(SelectOption hour) {
>         endDate.set(Calendar.HOUR_OF_DAY,
> Integer.valueOf(hour.getValue()));
>     }
>     
>     public void setEndMinute(String minute) {
>         endDate.set(Calendar.MINUTE, Integer.valueOf(minute));
>     }
>     public void setEndMinute(int minute) {
>         endDate.set(Calendar.MINUTE, minute);
>     }
>     public int getEndMinute() {
>         return endDate.get(Calendar.MINUTE);
>     }
> 
>     
>     
> }
> 
> 
> public class DateTimeSelectionForm extends Form {
>             
>     public DateTimeSelectionForm(String id, final
> IModel<DateTimeSelectionModel> model) {
>         //super(id);
>         super(id, model);
> 
>         final DateTextField dateStartField = new
> DateTextField("startDate",new PropertyModel<Date>(model, "startDate"), new
> PatternDateConverter("MM-dd-yyyy",true)) ;
>         add(dateStartField);
>         dateStartField.add(new DatePicker());
>         
>         // Start Hour
>         DropDownChoice<SelectOption> startHourChoice = new
> DropDownChoice<SelectOption>("startHour", getHourChoices(), new
> ChoiceRenderer<SelectOption>("label", "value"));
>         startHourChoice.setNullValid(false);
>         add(startHourChoice);
> 
>         DropDownChoice<Integer> startMinuteChoice = new
> DropDownChoice<Integer>("startMinute" , getMinuteChoices());
>         startMinuteChoice.setNullValid(false);
>         add(startMinuteChoice);
>         
>         DateTextField dateEndField = new DateTextField("endDate", new
> PropertyModel<Date>(model, "endDate"), new
> PatternDateConverter("MM-dd-yyyy", true)) ;
>         add(dateEndField);
>         dateEndField.add(new DatePicker());
> 
>         DropDownChoice<SelectOption> endHourChoice = new
> DropDownChoice<SelectOption>("endHour", getHourChoices(), new
> ChoiceRenderer<SelectOption>("label", "value"));
>         endHourChoice.setNullValid(false);
>         add(endHourChoice);
> 
>         DropDownChoice<Integer> endMinuteChoice = new
> DropDownChoice<Integer>("endMinute", getMinuteChoices());
>         endMinuteChoice.setNullValid(false);
>         add(endMinuteChoice);
>         Button todayButton = new Button("today"){
>         @Override
>         public void onSubmit() {
>             Calendar startDate = Calendar.getInstance();
>             
>             // initialize end date
>             Calendar endDate = Calendar.getInstance();
>         
>             model.getObject().setStartDate(startDate);
>             model.getObject().setEndDate(endDate);
>             getForm().modelChanged();
>             super.onSubmit();
>         }
>          
>         };
>         todayButton.setDefaultFormProcessing(false);
>     Send
>         add(todayButton);
>         // submit button
>         Button submitButton = new Button("submitButton");
>         add(submitButton);
>         
>         // NOTE: the reset button is all on the client side, so wicket
> doesn't need to see it.
>         
>     }
> thank you
>                                         
> 

-- 
View this message in context: 
http://old.nabble.com/Datepicker-model-change-problem-tp26312074p26326280.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

Reply via email to