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 registe开发者_运维百科r 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.
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.
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().
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.
精彩评论