Oh and the table isn't the parent:
// get the table to rerender
 target.addComponent(this.getParent());

I had to do a six step "parental grab"; I'm sure there is a better way! :D



On Fri, Oct 22, 2010 at 11:54 AM, Mark Doyle
<markjohndo...@googlemail.com>wrote:

> Thanks Mike, this was definitely a great pointer in the right direction;
> I'm beginning to grasp the column system now.
>
> I do have some issues though as detailed below.
>
> Firstly, my business model is out of my control so I had to wrap that in a
> class that contains the editable state.  I don't like doing that it but it's
> useful to see if I can get it to work and it shouldn't effect the process on
> the whole.
>
> The main difference is I'm attempting to do this using different columns,
> that is, not having a custom column that takes a type and switches.  The
> problem is that the models for each column seem to wrap different instances
> of the business object.
>
> The code below shows how I'm creating the columns.  The link in the
> AbstractColumn grabs the business object and toggles editable.
>  The EditablePropertyColumn's populateItem method then get's it's rowModel
> object (the business object) and checks the editable state.  This is where
> it goes wrong as each column seems to have it's own copy of the rows
> business model object.  I guess this is how the columns with with datagrid.
>
> /**
>  * Creates the columns for the synonym data table
>  *
>  * @return
>  */
> @SuppressWarnings("serial")
>  private List<IColumn<EditStateSynonymWrapper>> createColumns() {
> List<IColumn<EditStateSynonymWrapper>> columns = new
> ArrayList<IColumn<EditStateSynonymWrapper>>();
>
> columns.add(new AbstractColumn<EditStateSynonymWrapper>(new
> Model<String>("Edit")) {
>  public void populateItem(Item<ICellPopulator<EditStateSynonymWrapper>>
> cellItem, String componentId, IModel<EditStateSynonymWrapper> model) {
>  AjaxFallbackLink<EditStateSynonymWrapper> editLink = new
> AjaxFallbackLink<EditStateSynonymWrapper>(componentId, model) {
> @Override
>  public void onClick(AjaxRequestTarget target) {
> EditStateSynonymWrapper selected = (EditStateSynonymWrapper)
> getDefaultModelObject();
>  System.out.println("selected value = " + selected.wrappedSynonym.value);
> selected.setEditing(!selected.isEditing());
>
> // FIXME WHAT!? There must be a better way than this to get the parent
> table. :D
> MarkupContainer dataTable =
> getParent().getParent().getParent().getParent().getParent().getParent();
>  target.addComponent(dataTable);
> }
> };
>  cellItem.add(editLink);
> // cellItem.add(new EditLinkFragment(componentId, SynonymAdminPanel.this,
> model));
>  }
> });
>
> columns.add(new PropertyColumn<EditStateSynonymWrapper>(new
> Model<String>("Category"), "wrappedSynonym.category"));
>  // columns.add(new EditablePropertyColumn<EditStateSynonymWrapper>(new
> Model<String>("State"),
> // "wrappedSynonym.state", new PropertyModel<Synonym>(this, "selected")));
>  columns.add(new EditablePropertyColumn<EditStateSynonymWrapper>(new
> Model<String>("State"), "wrappedSynonym.state"));
>  columns.add(new PropertyColumn<EditStateSynonymWrapper>(new
> Model<String>("Root"), "wrappedSynonym.root"));
> columns.add(new PropertyColumn<EditStateSynonymWrapper>(new
> Model<String>("Value"), "wrappedSynonym.value"));
>  columns.add(new PropertyColumn<EditStateSynonymWrapper>(new
> Model<String>("Rational"), "wrappedSynonym.rational"));
>  columns.add(new PropertyColumn<EditStateSynonymWrapper>(new
> Model<String>("Taxonomy parent"), "wrappedSynonym.taxonomyParent"));
>
> return columns;
> }
>
>
>
> On Thu, Oct 21, 2010 at 3:50 PM, Michael O'Cleirigh <
> michael.ocleir...@rivulet.ca> wrote:
>
>>  Hi Mark,
>>
>> The cell's of a datatable are created by the IColumn.  So you need to
>> create a wrapping object or additional IModel that contains the edit-ability
>> of each row and then use that inside the populateItem(...) method of the
>> column to figure out which case to show (i.e. the label or the textfield).
>>
>> One way to persist the change immediately is to use an
>> AjaxFormComponentUpdatingBehavior on the onblur event of the textfield to
>> push the changes through.
>>
>> Do something like this:
>>
>> class MyColumn extends AbstractColumn<BusinessObject> {
>>
>>    public static enum ColumnType { LINK, COL1, COL2 };
>>
>>    private ColumnType type;
>>
>>    public MyColumn (IModel<String>header, ColumnType type) {
>>        super (header);
>>        this.type = type;
>>    }
>>    @Override
>>    public void populateItem(Item<ICellPopulator<BusinessObject>> cellItem,
>>            String componentId, IModel<BusinessObject> rowModel) {
>>
>>
>>            switch (this.type) {
>>
>>                case LINK :
>>                // add in the ajax link to the cell item
>>                // inside the onclick do:
>>                // get the row model object and then set its editable
>> field.
>>                cellItem.add(new AjaxLink(componentId) {
>>                        public void onClick(AjaxRequestTarget target) {
>>                                  BusinessObject bo = rowModel.getObject();
>>
>>
>>                                   bo.setEditable(true);
>>                                    // get the table to rerender
>>                                    target.addComponent(this.getParent());
>>                        }
>>                });
>>
>>                break;
>>
>>                case COL1:
>>                case COL2:
>>
>>                        BusinessObject bo = rowModel.getObject();
>>
>>
>>                    if (bo.isEditable()) {
>>                        // this might not work as textfield wants an input
>> tag but you can put the field on a panel and then add in the panel here.
>>                        cellItem.add (new TextField(componentId, )
>>                    }
>>                    else {
>>                        cellItem.add(new Label(componentId, ...)
>>                    }
>>
>>            }
>>
>>    }
>> };
>>
>> Regards,
>>
>> Mike
>>
>>  Hi all,
>>>
>>> I'm having a bit of trouble wrapping my head around the DataTable with
>>> regards to what I need to do.
>>>
>>> The perfect example of my goal is in Wicket Examples, namely, the Ajax
>>> Editable Tree Table:
>>> http://wicketstuff.org/wicket14/ajax/tree/table/editable.0
>>>
>>> <http://wicketstuff.org/wicket14/ajax/tree/table/editable.0>Rather than
>>> use
>>> the Tree table I must alter an existing DataTable.  I was thinking that
>>> I could create an editable textfield for the cells which I could enable
>>> or
>>> disable using an edit link in the first column.
>>>
>>> A bit like this:
>>>
>>> Edit | col1 | col2
>>> ============
>>> edit | text  | ksfuh
>>> -------------------------
>>> edit | text  | fsdkl
>>>
>>> Using the edit link I can get the model object of the row but I'm not
>>> sure
>>> how I can get the row that represents this and set it's cells to
>>> editable.
>>>
>>> The Editable text field is much like the one in the example and with the
>>> entire table wrapped in a form.  This means I can deal with the
>>> submission
>>> of the changes easy enough.
>>>
>>>
>>> Perhaps this is the wrong way to go about it....hmmm, thoughts?
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>>
>>
>

Reply via email to