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