Thiago H. de Paula Figueiredo wrote: > Em Fri, 08 May 2009 17:39:07 -0300, Andy Buckley > <andy.buck...@durham.ac.uk> escreveu: > >> So, is there a Tapestry meachnism for doing something like this? I can >> do it right now, but I'd rather not have to fight the system. I would >> expect Tapestry to do it a bit prettier than what I've shown, maybe >> *something* like >> .../view/irn/12349876/d/1,2,4 >> (yes, there are issues with telling what's a param name and what's a >> value... I just mean this schematically) But right now I don't even >> know where to start looking! Help, please!? ;) > > Just use a List as the activation context value. For each named > parameter one want, add the name first, the value second. > The above URL would be constructed by Tapestry if you returned a List > populated like this: > > List list = new ArrayList(); > list.add("irn"); > list.add(1245569); > list.add("d"); > list.add("1,2,4"); > > Then, declare a onActivate(EventContext context) method and reconstruct > the pairs: > > for (int i = 0; i < context.getCount() / 2; i++) { > String name = context.get(String.class, i * 2); > String value = context.get(String.class, i * 2 + 1) // instead of > String, you could use any type here > }
Thanks: I've opted to use something similar to this, but with regex matching instead of twice as many "directory" levels as expected, e.g. decoding URLs like .../view/irn1245569/d1,2,4/x1 in the obvious way. Seems to work fairly well so far, so thanks for the pointer. This has sparked an extra question, though: I also want to be able to render my data records in several different ways, i.e. nice HTML tables by default, but also structured plain text, XML, plotting code and other formats on demand. Like the main page, these should be accessible via the URL. So far, I've been using event handlers, e.g. .../view:xml?irn=1245569&d=1 to call a View.onXML() method. In moving to this new regexy context encoding, I tried using ActionLinks to make these alternative-format links, but it doesn't pass the parameters as expected: I have to add an "@OnEvent(component="xml")" annotation to the onXML() method for it to work at all, and when I do that the ActionLink uses a dot in the URL rather than a colon, and ignores the context. I assume there's some session magic going on to make it work at all, but it means that the alternative formats can't be accessed via URLs. If I explicitly build the URL with the context used before, e.g. .../view.xml/irn1245569/d1 then I get an exception. Is there a way that I can keep using event handlers for alternative formats and still pass the context params in the URL? I'd rather not have to split all these formats off into separate pages, since each contains relatively little logic and the context decoding seems best defined in the page class (not least for class reloading convenience.) Looking forward to more useful answers ;) By the way, T5 developers, it would be nice if the EventContext was Iterable<String>, so the old-style for-loop can be replaced with something more Java 5+ish like "for (String s : context) { ..." for those who just want strings back from the URL context. But that's a minor, minor point! ;) Thanks again, Andy -- Dr Andy Buckley Institute for Particle Physics Phenomenology Durham University 0191 3343798 | 0191 3732613 | www.insectnation.org --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org For additional commands, e-mail: users-h...@tapestry.apache.org