Hi,
the problem is that you are doing this:
new PropertyModel(getModelObject(),"latestVersion.title")));
This is not really model chaining, you bind PropertyModel with your
Document diretly (not with the DocumentModel).
You can try new PropertyModel(getModel(),"latestVersion.title")));
or just new PropertyModel(model, "latestVersion.title");
Also you can use LoadableDetachableModel to save yourself from having
to implement the whole detaching logic
e.g.
class MyModel extends LoadableDetachableModel
{
private final Long id;
public MyModel(MyEntity entity)
{
super(entity);
this.id = entity.getId();
}
public Object load()
{
return DaoFactory.getDao().load(id);
}
}
-Matej
On Sat, Sep 6, 2008 at 6:27 PM, Wayne Pope
<[EMAIL PROTECTED]> wrote:
> Ok,
>
> this has take me ages to figure out what is happening.
> I have a model that represents a hibernate entity (called Document). I have
> a form with a couple of fields which uses PropertyModel on the model and I
> set the model on this forms contructor.ie.:
>
> setModel(model);
> add(new TextField("title", new
> PropertyModel(getModelObject(),"latestVersion.title")));
> add(new TextArea("quicksummary", new
> PropertyModel(getModelObject(),"latestVersion.summary")));
>
> this model is :
> public class DocumentModel extends Model {
>
> Document doc;
> Long id;
>
> public DocumentModel() {
> }
>
> public DocumentModel(Long docId) {
> id = docId;
> }
>
> @Override
> public Object getObject() {
> if (doc != null)
> return doc;
> if (id == null) {
> doc = new Document();
> } else {
> doc =
> DAOFactory.getFactory().getDocumentDAO().findByPrimaryKey(id);
> }
> return doc;
> }
>
> @Override
> public void setObject(Object obj) {
> doc = (Document)obj;
> id = (doc == null) ? null : doc.getId();
> }
>
> @Override
> public void detach() {
> doc = null;
> }
>
> }
>
> When the constructor for the form is called I see that the PropertyModel
> gets the Document entity from my model and populates the fields. My
> DocumentModel is detached and page displayed. So far far so good.
>
> However when the form is submitted, I see that during the Form validation
> the method TextArea,setModelObject is calling model.setObject(object). (The
> model here is the PropertyModel class instance that was contructed in my
> forms constructor) - I see that this has a reference to my detached Document
> entity.
> THe problems is that in my onSubmit method which is called after the above
> validation etc, is when I call getModelObject() it in turns calls
> getObject() which (as its detached) loads the entity again from the database
> - however this is a different object to the one PropertyModels updated!!!!
>
> So the PropertyModel's are updating an object that was detached!
>
> So plainly I don;t understand what I'm ment to do with Wicket and detached
> models - how to you have a form that represents an entity and make it
> detached?
> Thanks
> Wayne
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]