Hi,

For this use case you have to replace the model object with a new instance,
i.e. something like:

MyFormComponentPanel.this.setModelObject(getModelObject().withDayOfMonth(DayOfMonth));


P.S. I don't know the API by heart so the method name could be wrong.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Jun 8, 2015 at 5:27 AM, smallufo <[email protected]> wrote:

> Hi :
> I have a question about immutable object in FormComponentPanel .
> If the object doesn't have setters , how to correctly handle it ?
> for example : Java8's LocalDate , it only has getYear() , getMonthValue() ,
> getDayOfMonth()
> no setters.
>
> And in my code :
>
>
> public class DatePanel extends FormComponentPanel<LocalDate> {
>
>   private Logger logger = LoggerFactory.getLogger(getClass());
>
>   // year / month DropDownChoice skipped
>   private DropDownChoice<Integer> dayChoice;
>
>   public DatePanel(String id, LocalDate localDate) {
>     super(id, Model.of(localDate));
>
>     // year / month skipped
>     add(dayChoice = new DropDownChoice<>(
>       "day",
>       new PropertyModel<>(localDate , "dayOfMonth")  ,
>       IntStream.range(1, 32).boxed().collect(Collectors.toList()))
>     );
>   }
>
>   @Override
>   protected void convertInput() {
>     // year / month skipped
>     int day = dayChoice.getConvertedInput();
>
>     logger.info("year = {} , month = {} , day = {}" , year , month , day);
>     setConvertedInput(LocalDate.of(year, month, day));
>   }
> }
>
> It will throw "*WicketRuntimeException: no set method defined*" exception.
>
> Well , I can wrap LocalDate in a mutable wrapper (with setYear / setMonth /
> setDay methods) ,
> and pass this LocalDateWrapper as the Model of FormComponentPanel.
> But is it the only solution ?
> Any other solution without a wrapper ?
>
> Thanks.
>

Reply via email to