Java Reference
In-Depth Information
To continue using the clean URL convention of converting the path to
lowercase with underscores, use the same MyActionResolver extension
as on page 288 , but return the URL without the "/action" prefix. 1
The URL bindings are now the same as before but without the /action
prefix. For example, here is the URL binding for the contact list:
Download email_32/src/stripesbook/action/ContactListActionBean.java
@UrlBinding("/contact_list/{$event}/{contact}")
public class ContactListActionBean extends ContactBaseActionBean {
As we can see, we can customize URL bindings in just about any way
we want and keep our boss, our customers, and those Unstoppable
Forces of Nature happy.
Specifying the Event Name
Let's look at one last thing concerning URLs: the different ways that an
event name can be mapped from a URL to an event handler method. By
convention, the name of an event handler corresponds to the name of
the method, as follows:
public Resolution view()
The name of this event handler is view . If we need to use an event
handler name that does not correspond to the method name, we can
set a different name with the @HandlesEvent annotation:
@HandlesEvent("visualize")
public Resolution view()
This would cause the visualize event to be handled by the view ( ) method.
As for specifying event names in URLs, we have several options. Know-
ing how this works is useful when we're testing and want to manually
type a URL and is particularly important when working with Ajax, as
we'll see in Chapter 15 , Using JavaScript and Ajax. So, here are the
different ways of indicating an event name:
• Include a request parameter with the same name as the event
name. This is what Stripes does by default, as follows:
/ContactList.action?view=&contact=5
1. Again, the lowercase-with-underscores convention is optional. To use clean URLs, the
bare minimum is either to override getBindingSuffix ( ) and return an empty string so that
".action" is not used or to annotate every action bean with @UrlBinding .
 
 
 
Search WWH ::




Custom Search