Hi,
We use a simple and empty <s:url includeParam="get"/> tag to loop back
to the current action/url.
The only thing you have to look for are those "unsafe" urls: we don't
have any "unsafe" urls in our application, thanks to an extensive POST
then GET approach. Whenever some action is done in the application
(through a POST), we process this action, update the relevant stuff in
the database, and issue a redirect answer to a GET url, that will
display the result of the action. That way, we can reload the current
page (be it for switching language or just a browser reload) without any
issue. This approach takes care of the bookmarking issue as well. I
think this approach way more robust that tinkering with URLs to define
safe and "unsafe" URLs.
We had to do a bit a workaround code so that on the redirect to a GET,
we don't lose all of our context. We actually save the current action in
the session, and when the get comes back, pop it out of the session to
place it in the stack. If somebody is interested, I can share that code....
Denis.
Le 2010-03-29 04:55, Alex Rodriguez Lopez a écrit :
Thanks Zoran for sharing your approach, greatly appreciated, I'm
thinking about implementing a similar interceptor, and maybe replace
the i18n one so work is done implicitly with only a change in
struts.xml and the new interceptor.
Em 29-03-2010 02:58, Zoran Avtarovski escreveu:
Hi Guys,
We simplified it for struts to use a simple interceptor. Can’t show the
exact code due to legal crap, but here’s the overview.
In our base action we have a String called requestString, with
appropriate getters and setters. We also have a Map<String, String> of
unsafe URL’s and their safe counterparts. For example if the unsafe url
was deleteObject.action it’s safe option would be listObject.action
The interceptor uses the following code:
if(unsafeUrls.get(request.getRequestURI()) != null)
responseUrl = unsafeUrls.get(request.getRequestURI());
else
responseUrl = request.getRequestURI();
StringBuffer rStr = new StringBuffer(responseUrl);
rStr.append(“?”);
for (Iterator iter = request.getParameterMap().keySet().iterator();
iter.hasNext();) {
String key = (String) iter.next();
if (!"request_locale".equalsIgnoreCase(key)) {
if (request.getParameter(key) != null) { // you can also include
your own parameter specific exceptions. With the tag we used to have
a comma delimited list of excluded parameters.
rStr.append(key);
rStr.append("=");
rStr.append((String) request.getParameter(key));
rStr.append("&");
}
}
}
action.setRequestString(sStr.toString());
And then on the page we have:
<div class=”localeFlag”><a
href="${requestString}&request_locale=${localeOpt.lang}" ><img
src="${pageContext.request.contextPath}/image/icons/${localeOpt.lang}_flag.gif"
alt="<s:text name="%{“select.”+ attr.localeOpt.lang}" />"
title="<s:text name="%{“select.”+ attr.localeOpt.lang}" />" /></a></div>
I had to modify the code to satisfy our people but let me know if you
have any questions. We use a complex parameter filtering process to
unsure that security isn’t compromised.
We’ve had to do quite a bit of i18n which has involved implementing DB
based properties and tighter integration with S2 and spring.
Z.
Hi Zoran,
would you mind sharing the code of this tag? It would be helpful
to me,
as somehow I've been able to link to the same sction with an
empty url
tag but unable to retain params. Thanks!
Em 24-03-2010 22:42, Zoran Avtarovski escreveu:
> I wrote a small custom tag which builds the link with the existing
action
> and parameters. This way it just reloads the page. I also included a
> parameter that wouldn’t allow the change (a jQuery dialog would
give the
> user feed back) to take place if there might me an issue with system
> integrity – for example submitting a form twice.
>
> Z.
> >
> > hi,
> > I have a quick and basic question.
> > Regarding internationalization, whenever a user clicks on a link
with a flag,
> > i want to change the locale (language)
> > of the web application.
> > That works well with the i18n interceptor.
> > However i always redirect the user to the home page (home.jsp)
when i do that
> > because that is how i have setup the input result :
> > <action name="changeLanguage" class="ServicesAction"
> > method="changeLocale">
> > <result name="input">/home/home.jsp</result>
> > </action>
> >
> > My JSP looks like this :
> > <s:url id="url" action="changeLanguage.action">
> > <s:param name="request_locale">fr</s:param>
> > </s:url>
> > <s:a href="%{url}" theme="xhtml"><img
> > src="<%=request.getContextPath()%>/images/flag_fr.png" /></s:a>
> >
> > So my question is :
> > how do you specify the current page in the input result name ?
> > so that the user stays on the current page when he changes
languages.
> > Thanks for helping.
> >
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@struts.apache.org
For additional commands, e-mail: user-h...@struts.apache.org