Hi,
On Thu, Aug 1, 2013 at 6:09 PM, Tom Eicher <[email protected]> wrote:
> Hello Martin & List,
>
> Yes, okay, but is it really necessary for me to define an own model class?
> Would it not be much more straightforward to just instantiate one of the
> existing models, like
> new FileUploadField("**UploadFileField", new Model<List<FileUpload>>()));
> or some Model.of() variant ?
>
You mean Wicket automatically to do this for you ?
In current Wicket if a component has no model then its parent is asked.
If the parent's model
implements org.apache.wicket.model.IComponentInheritedModel then Wicket
asks it for a model for the child. This is how CompoundPropertyModel works.
If there is no IComponentInheritedModel up in the hierarchy then the
component just has model == null.
For your use case we can introduce Component#newDefaultModel() that can
return a sane default model per component. And this method should be called
only when org.apache.wicket.Component#initModel returns null.
I don't like much such automatic/automagic behaviors. I prefer to see an
exception message telling me what I forgot to do. But some people may like
this solution.
> However, new Model() does not work, as FileUpload is not Serializable...
>
> (and sorry for the delayed "bump" post today, sync issues with the mobile
> ;-)
>
> Any ideas what better to use ?
>
> Thanks & Cheers, Tom.
>
>
> On Wed, Jul 24, 2013 at 3:55 PM, Tom Eicher <[email protected]> wrote:
>
> Hello,
>>
>> I have an outer form, with a CPM for a business entity.
>>
>> An inner form
>> Form<Void> uploadImageForm = new Form<>("UploadImageForm");
>>
>> has a
>> FileUploadField uploadImageField =
>> new FileUploadField("****UploadImageField");
>>
>>
>> and when I submit the inner form, wicket tries to find
>> getters/setters for UploadImageField in my business entity,
>> which obviously are not there:
>>
>> WicketRuntimeException: No get method defined for class: class
>> XXXBusinessEntity expression: UploadImageField
>>
>> I tried many things to work around this problem, including
>> Form<Void> uploadImageForm = new Form<>("UploadImageForm", null);
>> and
>> uploadImageField = new FileUploadField("****UploadImageField", null);
>>
>> and
>> setModel(null)
>> and some more, however the only way to really get rid of this
>> I found is:
>>
>> FileUploadField uploadImageField = new
>>
> FileUploadField("****UploadImageField",
>
> new UploadFieldModel());
>>
>> static class UploadFieldModel implements
>>
> IModel<List<FileUpload>> {
>
>> List<FileUpload> f;
>> @Override
>> public List<FileUpload> getObject() {
>> return f;
>> }
>> @Override
>> public void setObject(List<FileUpload> object) {
>> f=object;
>> }
>> @Override
>> public void detach() {
>> }
>> }
>>
>> That doesn't sound too reasonable, does it ?
>> I do not need or want the value to be put to any model, is there any
>> more sensible way to do this ? (wicket 6.8.0 - will update soon)
>>
>>
> Actually this is the correct way.
> Wicket needs to store the data somewhere. Usually 'somewhere' is the form
> component's model.
>
> By using 'null' or by not setting anything the component tries to use its
> parent's model.
>
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail:
> users-unsubscribe@wicket.**apache.org<[email protected]>
> For additional commands, e-mail: [email protected]
>
>