views:

167

answers:

3

Hi, I'm new to wicket and stuck with the following problem:

I have a table with 5 rows. Each row contains 7 cells. Each cell has a unique value. Once a cell is clicked, its unqiue value should be posted to the server.

I would like to register only one ajaxfallbacklink (or similar) on the table and adjust the value of the model to the unique value of cell that has been clicked.

Any ideas?

A: 

How can you know, in general, which cell has been clicked when you only have one handler for all? Sounds pretty much impossible.

But the Wicket side of the problem is easy, you can always write your own IModel, or extend AbstractReadOnlyModel. You only need to implement one method, getObject().

Thomas Kappler
+1  A: 

My immediate response would be "why do you want to it like that" - the obvious solution is to add an ajax onClick behaviour to each cell/cell content component (obviously you only have to write one behaviour). That's how it is designed to work.

You could write a handler as you suggest, but it would have to trawl through the table's component tree, adding the correct JS onClick callbacks to each cell. You then have to think about the semantics of adding an onClick behaviour to a component that doesn't actually express the onClick event.

Basically a load of custom code, circumventing the frameworks (pretty neat) ajax model for no benefit at all.

ireddick
you're right - really not a good idea
Markus Maria Miedaner
A: 

Obviously this will need client side javascript extract the information to send to the server. when that information is ready the following code can generate a ajax callback (from an AbstractDefaultAjaxBehavior subclass)

generateCallbackScript(new AppendingStringBuffer("wicketAjaxPost(\'").append(getCallbackUrl(false)).append("\', 'param=' + Wicket.Form.encode(yourDataGoesHere) "));

and RequestCycle.get().getRequest().getParameter("param") to get the decoded value on the java side of things.

someone45