私は Tapestry5 のユーザーで、膨大な数のフィールドを含むフォームを持っており、すべて数値でインクリメントされます。
例
timesheet.tsHours01 timesheet.tsHours02 など
これを動的にループしたいのですが、完全に機能させることができませんでした。これまでに試したこと。
@Property
private List<TimeSheetEntity> timeSheetEntity;
@Property
private List<TsWhour> tsWhours;
@Property
private TsWhour tsWhour;
public void onPrepareFromForm() {
this.timeSheetEntity = timeSheetService.getCreateOrUpdate(timeSheetEntity);
tsWhours = new ArrayList<TsWhour>();
tsWhours.add(new TsWhour(timeSheetEntity, "TsWhours01"));
tsWhours.add(new TsWhour(timeSheetEntity, "TsWhours02"));
tsWhours.add(new TsWhour(timeSheetEntity, "TsWhours03"));
}
public class TsWhour {
private TimeSheetEntity timeSheetEntity;
private String id;
private BigDecimal property;
public TsWhour() {
}
public TsWhour(TimeSheetEntity timeSheetEntity, String id) {
this.timeSheetEntity = timeSheetEntity;
this.id = id;
}
public BigDecimal getProperty() {
try {
Method method = TimeSheetEntity.class.getMethod("get" + id);
return (BigDecimal) method.invoke(timeSheetEntity);
} catch (NoSuchMethodException ex) {
Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
} catch (SecurityException ex) {
Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalArgumentException ex) {
Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
} catch (InvocationTargetException ex) {
Logger.getLogger(TimeSheet.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public void setProperty(BigDecimal value) {
System.out.println(value);
}
public TimeSheetEntity getTimeSheetEntity() {
return timeSheetEntity;
}
public void setTimeSheetEntity(TimeSheetEntity timeSheetEntity) {
this.timeSheetEntity = timeSheetEntity;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
ページをロードすることはできますが、保存すると失敗します。可能であれば、完全に動的に保つために、データ型を bigdecimal として指定したくありません。