Igor -

Are you saying that your approach below is better than parsing the component path string as I was doing, for navigating up the component hierarchy? That makes sense to me.

That addresses the first three questions:

* What row am I in?
* What column am I in?
* What is the table that contains me?


Is there a connection with the other questions that I'm missing?

* What are my sibling components in this row?
* What is my sibling component in this row for the column whose property is
"foo"?
* What is the component in my table at column x and row y?
* What is the component in my table at the column whose key is "foo" and row y?


Are there others who share my interest in this functionality? It would be really helpful if it were incorporated into the Wicket distribution if so. Having the methods on the Component class would be really handy, even though they would usually not be applicable (and it could be argued that it's not a good idea for that reason). Second best is a static class as I had it. Is there a better way? I wouldn't want to subclass every Wicket component we ever use to get this functionality.

Can anyone point me to a better implementation of it, to add to Igor's suggestion, or otherwise provide any helpful advice?

Thanks,
Keith


Igor Vaynberg wrote:
datatable {
 populateitem(item i) {
   int col=i.getindex();
   int row=i.getparent(Item.class).getindex();
 }
}

-igor

On Thu, Nov 26, 2009 at 7:27 PM, Keith Bennett <[email protected]> wrote:
Hi, all.  I'd like some feedback as to whether my need is already addressed
in Wicket, or, if not, if I'm on the right track with some code I've written
to address this need.

I've been working with a DataTable and need to be able to query it for
things like:

For a given component:

* What row am I in?
* What column am I in?
* What is the table that contains me?
* What are my sibling components in this row?
* What is my sibling component in this row for the column whose property is
"foo"?
* What is the component in my table at column x and row y?
* What is the component in my table at the column whose key is "foo" and row
y?

I need this information because I want to be able to inspect the components'
input before the values are saved to the underlying model (data provider).

For example, in my form validation, I want to inspect those unsaved values.
 I can't do that in field validation because the error state depends on
relationships between data items in several columns in the row.

Or, I may have an error indicator icon in one column that is added to the
Ajax target for other components in that row, and the error icon's
visibility is dependent partly on components in that row whose data have not
yet been saved.

* * *

I wrote some code that does this.  Because it was difficult to guarantee
that all components would have access to an object, I implemented this
functionality as static methods.

It relies heavily on the components' page relative paths (e.g.
"form:table:rows:1:cells:1:cell").

One of the challenges was that the row number of the first row changes!
 When the table is repopulated, new row numbers are assigned.  For example,
a 5 row table will start out having its first row as #1, but later in its
life it will be #6, and then later, #11...

I don't think there's any hook into being notified of these changes, and
even if there were, the static methods couldn't easily use them, so I wind
up recalculating the row offset (1, 6, etc.) every time I need it.  This
involves inspecting all the columns rows and calculating the minimum, and is
a bit unfortunate.

Because all cell components have an id of "cell", there is no way to tell
which cell contains a "foo" field, which contains a "bar" field, etc.,
without getting its column number and looking it up somehow.  (In some cases
one could identify it by the class, but that wouldn't work all the time.)
 So I made an interface:

/**
 * For columns that can be identified by a key name.
 */
public interface ColumnWithKey {
   String getColumnKey();
}

Ideally, the need for a ColumnWithKey interface could be eliminated by
adding getKey() to the IColumn interface.

The code is at:

http://gist.github.com/243802 and
http://gist.github.com/243800

It uses Google Collections, a really cool generics-enabled collections
library that brings some functional programming type goodies to Java.

Any feedback on any of this?  Would this code be helpful to anyone?

Thanks,
Keith

---
Keith R. Bennett
Senior Software Consultant
Linked In: http://www.linkedin.com/in/keithrbennett
Blogs: http://krbtech.wordpress.com, http://keithrbennett.wordpress.com





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to