Mike Watson wrote:
Hi Jeromy,
I've finally found time to try to resolve this but haven't had much luck.
Just to recap, I'm looking to be able to do something similar to the following:
/book -> returns a list of books
/book/123 -> returns book with id 123
/book/123/chapter/1 -> return chapter with id 1, retrieved from book
123 (this is a simplistic example, all resources have a unique ID)
I'd also like to be able to control access based on the
context/namespace used to access a resource e.g.:
/logo/abc -> read or update
/book/123/logo/abc -> read only
(would I need multiple LogoControllers for this?)
Using Namespaces as described by Jeromy below certainly seems to make
sense but as soon as I start to try the example provided I lose the
ability to GET /book/123, and I've tried with BookController having
namespace of "/" or "/book" and neither works. And so far I haven't
been able to successfully hit the ChapterController using a url like
/book/123/chapter.
Am I missing something really obvious? Is there something I need to
put in the struts.xml to configure the namespaces as well as using the
@Namespace annotation?
Jeromy, you seem to be pretty knowledgeable about this - can you think
of anything I might be doing wrong?
Thanks in advance for your help.
Mike
Hi Mike, I'll throw a quick answer together now and try to give you a
more in-depth one in a day or two by building an example.
The steps are:
1. ensure struts is up-to-date. (2.1.3-SNAPSHOT preferably, to ensure
you have the latest ActionMappingParamsInterceptor)
2. enable the NamedVariablePatternMatcher via struts.xml
3. Create the BookController in the root namespace. GET /book/123 will
invoke BookController.show() with id=123
4. Create the ChapterController in the namespace containing the book id
variable (/book/{bookid}). GET /book/123/chapter will invoke
ChapterContoller.index() with bookId=123.
ie.
@Namespace("/")
public class BookController implements ModelDriven<Book> { }
@Namespace("/book/{bookId}")
public class ChapterController implements ModelDriven<Chapter> { }
Now that's what *should* happen. I use it in a large application that
includes many other related tweaks so I'll throw together a vanilla
sample and post it somewhere.
I'll come back to the authorization issue separately. The quick answer
is that you can omit methods that are never permitted and/or filter URLs
based on a URI pattern and/or user's role.
regards,
Jeromy Evans
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]