That's just a matter of how HTML forms work. They don't concern themselves
with clean URLs. When you submit with a POST, the URL will show the form's
action attribute. When you submit with a GET, the URL will show the action
plus all the form's inputs in the query string.
You have a couple of options if you really want to see a clean URL after
submitting the form. You can do it with Javascript, such that the normal
submit is canceled (form's onsubmit returns false) and you set the
window.location based on what's in the query field. Or you can POST the form
to an event handler that immediately redirects back to the same ActionBean
with a clean URL. Something like ...
== form
<s:form beanclass="${actionBean.class}">
<s:hidden name="_eventName" value="search" />
<s:text name="q" />
<s:submit name="search" value="Search" />
</s:form>
== ActionBean
@UrlBinding("/search/{q}.html")
public class SearchActionBean extends BaseActionBean {
private String q; // add getter & setter
@DefaultHandler
public Resolution view() {
return new ForwardResolution("/search.jsp");
}
public Resolution search() {
return new RedirectResolution(getClass()).addParameter("q", getQ());
}
public Resolution q() {
// do search stuff
return new ForwardResolution("/results.jsp");
}
}
What that will do is the following:
1. Hit /search.html and it loads the initial search page
2. Submit to /search.html with a POST. The _eventName overrides every
other way of specifying the event to execute. The form sets
_eventName=search to force the search() event to execute, which redirects
to, for example, /search/foo.html if you search for "foo". You need to force
search() to execute this way because ...
3. You also have an event handler named q(). After the redirect, the "q"
parameter serves two purposes: bind its value as an ActionBean property and
specify the event name. The q() event then does the search and forwards to
the results view.
I've never actually tried this. This was all off the top of my head so it
might need some touching up, but I'm sure it can work. The dual-purpose "q"
parameter and use of _eventName to override it are a little bit of magic,
but other than that it's pretty straightforward.
-Ben
On Thu, Jan 22, 2009 at 8:17 PM, Randy Jones <[email protected]> wrote:
> Newbie question. Using Stripes 1.5.
>
> Given this JSP fragment:
>
> <stripes:form id="searchBox" beanclass="org.randy.web.ListViewBean"
> focus="searchText">
> <stripes:text name="searchText" value="Search our Site" class="text
> medium"/>
> <stripes:submit name="search" value="Search" class="button"/>
> </stripes:form>
>
> I would like my URL to show the searchText value so that it can be
> bookmarked.
> If "stuff" was entered in the field I would like the URL to look like this:
>
> http://www.randy.com/myapp/list/stuff.html
>
> or
>
> http://www.randy.com/myapp/list.html?search=stuff
>
> I tried changing the form method to GET but than I get an un-pretty URl.
>
> Thanks,
>
> Randy
>
------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users