You must be a fan of annonymous classes! :)

The problem is that you re-use ListItem's model. As you noticed
yourself, that model doesn't update the underlying model object. I
think this is done because Johan, Chris and Juergen (to name of few)
deemed depending on the index dangerous.

Anyway, the solution is to do something like:

                protected void populateItem(ListItem item)
                {
                        // add a text field that works on each list item model 
(returns objects of
                        // type FormInputModel.Line) using property text.
                        item.add(new TextField("lineEdit", new
PropertyModel(item.getModel(), "text")));
                }

The underlying object will be used for get operations, and by wrapping
a model around that (model), you'll get all the update facilities you
need.

Eelco


On 9/13/05, Jim McBeath <[EMAIL PROTECTED]> wrote:
> Below is the java code I am using.  I think the important points are:
> 
> 1. The only models I am explicitly creating are the PropertyModel objects
>    associated with the two ListView components.
> 2. The CheckBox component gets its model from the ListItem, which in
>    turn comes from the ListView, which in turn uses a PropertyModel
>    object tied to my main model (a ResultSetTableModel object, which is
>    just a simple bean with a few properties).  Thus I have supposedly
>    chained my models all back to the original model.
> 3. I am setting setOptimizeItemRemoval(true) as per the wiki and
>    javadoc instructions.
> 
> In the code below I have added onModelChanging and onModelChanged methods
> to my CheckBox as part of debugging this issue.  The onModelChanged method
> now also updates my List, so my code does what I want; but I think I
> should not have to do that.
> 
> I have not yet fixed the TextField to do the same thing.
> 
>     public ResultSetTable(final String name, ResultSetTableModel model)
>     {
>         super(name,new Model(model));
>         this.rsModel = model;
>         Form form = new Form("form");
>         add(form);
>         ListView headerListView = new ListView("columnHeaders",
>                     new PropertyModel(model,"columnHeaders")) {
>             public void populateItem(final ListItem item) {
>                 final String columnHeader = (String)item.getModelObject();
>                 final int columnIndex = item.getIndex();
>                 item.add(new Label("colLabel",columnHeader));
>             }
>         };
>         form.add(headerListView);
>         ListView dataListView = new ListView("rows",
>                 new PropertyModel(model,"rows")) {
>             public void populateItem(final ListItem rowItem) {
>                 final List row = (List)rowItem.getModelObject();
>                 ListView rowListView = new ListView("row",row) {
>                     public void populateItem(final ListItem colItem) {
>                         Object colVal = colItem.getModelObject();
>                         final List colRow = row;
>                         final int columnIndex = colItem.getIndex();
>                         if (colVal==null)
>                             colVal="";
>                         final IModel colModel = colItem.getModel();
>                         Label lbl = null;
>                         TextField txt = null;
>                         CheckBox cb = null;
>                         if (rsModel.columnIsEditable(columnIndex)) {
>                             if (colVal instanceof Boolean)
>                                 cb = new CheckBox("colCheckBox",colModel) {
>                                     public void onModelChanging() {
>                                         System.out.println("model changing 
> "+getModel());
>                                         System.out.println("old value: 
> "+getModelObject());
>                                     }
>                                     public void onModelChanged() {
>                                         System.out.println("model changed 
> "+getModel());
>                                         System.out.println("new value: 
> "+getModelObject());
>                                         if (colRow!=null) {
>                                             System.out.println("set new value 
> into row");
>                                             Object newVal = getModelObject();
>                                             colRow.set(columnIndex,newVal);
>                                         }
>                                     }
>                                 };
>                             else
>                                 txt = new TextField("colText",colModel);
>                         } else {
>                             lbl = new Label("colLabel",colVal.toString());
>                         }
>                         if (lbl==null) {
>                             lbl = new Label("colLabel");
>                             lbl.setVisible(false);
>                         }
>                         if (txt==null) {
>                             txt = new TextField("colText");
>                             txt.setVisible(false);
>                         }
>                         if (cb==null) {
>                             cb = new CheckBox("colCheckBox");
>                             cb.setVisible(false);
>                         }
>                         colItem.add(lbl);
>                         colItem.add(txt);
>                         colItem.add(cb);
>                     }
>                 };
>                 rowListView.setOptimizeItemRemoval(true);
>                 rowItem.add(rowListView);
>             }
>         };
>         dataListView.setOptimizeItemRemoval(true);
>         form.add(dataListView);
>         Button submitButton = new Button("submitButton",new Model("Submit")) {
>             protected void onBeginRequest() {
>                 setVisible(formIsEditable());
>             }
>             protected void onSubmit() {
>                 ResultSetTable.this.onSubmit();
>             }
>         };
>         form.add(submitButton);
>     }
> 
> --
> Jim McBeath
> On Tue, Sep 13, 2005 at 08:08:10PM +0200, Eelco Hillenius wrote:
> > From: Eelco Hillenius <[EMAIL PROTECTED]>
> > To: [email protected]
> > Subject: Re: [Wicket-user] ListItemModel doesn't update the item in the List
> > Date: Tue, 13 Sep 2005 20:08:10 +0200
> >
> > The trick here is that there is the ListItem's model shouldn't matter.
> > It's not a form component, and thus recieves no input.
> >
> > When you add a textfield in your ListView's populateItem method, any
> > value that comes from the form should be passed directly to that
> > component. When this doesn't happen, something else is wrong...
> >
> > Eelco
> >
> >
> > On 9/13/05, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> > > Ok, that's not about your problem, though you should know it. I'll put
> > > together a test for your issue now.
> > >
> > > Eelco
> > >
> > > On 9/13/05, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> > > > Before you look any further, did you read/do:
> > > > http://wicket.sourceforge.net/wiki/index.php/Listviews_in_a_form ?
> > > >
> > > > Eelco
> > > >
> > > >
> > > > On 9/13/05, Jim McBeath <[EMAIL PROTECTED]> wrote:
> > > > > I am working on an app with a form containing a table where some of 
> > > > > the
> > > > > cells are editable.  The model for the app is a bean with a property
> > > > > for the data whose value is a List of Lists.  At the bottom, I create 
> > > > > a
> > > > > CheckBox or TextField using the ListItem passed to me in populateItem.
> > > > > Since my models are all chained back to the original model, I expected
> > > > > that when I submitted the form, the data in my app model would be 
> > > > > updated.
> > > > > However, this does not happen.  From looking at the code for 
> > > > > ListItemModel,
> > > > > it looks like the new value gets stored in the ListItemModel itself
> > > > > rather than getting stored in the List from which that model was 
> > > > > created.
> > > > >
> > > > > ListItemModel.setObject() line 95 sets a local "object" variable 
> > > > > rather
> > > > > than setting the data into the underlying list in the same way as it
> > > > > accesses it in ListItemModel.onAttach() line 70.
> > > > >
> > > > > Am I reading this correctly?  Shouldn't it be updating the List 
> > > > > itself?
> > > > > I can do this myself in an onModelChanged() method, but it seems like 
> > > > > I
> > > > > shouldn't have to.
> > > > >
> > > > > This is in rc1.
> > > > >
> > > > > --
> > > > > Jim McBeath
> > > > >
> > > > >
> > > > > -------------------------------------------------------
> > > > > SF.Net email is Sponsored by the Better Software Conference & EXPO
> > > > > September 19-22, 2005 * San Francisco, CA * Development Lifecycle 
> > > > > Practices
> > > > > Agile & Plan-Driven Development * Managing Projects & Teams * Testing 
> > > > > & QA
> > > > > Security * Process Improvement & Measurement * 
> > > > > http://www.sqe.com/bsce5sf
> > > > > _______________________________________________
> > > > > Wicket-user mailing list
> > > > > [email protected]
> > > > > https://lists.sourceforge.net/lists/listinfo/wicket-user
> > > > >
> > > >
> > >
> >
> >
> > -------------------------------------------------------
> > SF.Net email is Sponsored by the Better Software Conference & EXPO
> > September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
> > Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> > Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> > _______________________________________________
> > Wicket-user mailing list
> > [email protected]
> > https://lists.sourceforge.net/lists/listinfo/wicket-user
> 
> 
> -------------------------------------------------------
> SF.Net email is Sponsored by the Better Software Conference & EXPO
> September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
> Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
> Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
> _______________________________________________
> Wicket-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/wicket-user
>


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
Wicket-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/wicket-user

Reply via email to