You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Artem Zhmurov <da...@yandex.ru> on 2006/09/08 10:36:38 UTC
RE: Forward to the same page
What about using JavaScript? Try this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Changing location</title>
</head>
<body>
<script language="JavaScript">
function changeLanguage(lang){
var location = window.location.href;
if(location.indexOf("?") == -1){
location += "?lang=";
location += lang;
window.location = location;
} else {
var pos = location.indexOf("lang=");
if(pos != -1){
var new_location = location.substring(0, pos + 5);
new_location += lang;
window.location = new_location;
} else {
location += "&lang=";
location += lang;
window.location = location;
}
}
}
</script>
<input type="button" value="RUS" onclick="changeLanguage('ru')"/>
<input type="button" value="ENG" onclick="changeLanguage('en')"/>
</body>
</html>
It will work if you don't need the addition page (such as when dealing with
login).
Also you have to be sure, that your lang=.. parameter is in the end of
parameters line (that is true until you're not trying to add lang=..
somewhere outside). And there will be problem if your application dealing
with parameters named, for example, 'XXXlang'. All imperfections mentioned
can be removed by some little changes in script.
> -----Original Message-----
> From: Antonio Petrelli [mailto:brenmcguire@tariffenet.it]
> Sent: Friday, August 25, 2006 12:09 PM
> To: Struts Users Mailing List
> Subject: Re: Forward to the same page
>
> Thomas Hamacher ha scritto:
> > How do I forward to the same page I was coming from? The typical example
> for
> > this is the "change-language-problem". Someone is on one page and simply
> > wants to change the language and expects to see the same page in a
> different
> > language.
> >
>
> Just an idea, <html:form> tag has the "action" attribute that is no more
> required. If it is not specified the last servlet path (i.e. "post
> back") will be taken.
> http://struts.apache.org/1.x/struts-taglib/tlddoc/html/form.html
> You could grab the code that controls the value of the "action"
> attribute to determine the path you're coming from. Then you "change the
> language" and then redirect (I think it's better than forwarding) to the
> previous servlet path.
>
> HTH
> Antonio
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
[OT] Re: Forward to the same page
Posted by Antonio Petrelli <br...@tariffenet.it>.
Manfred Wolff ha scritto:
> hi antonio,
>
It wasn't me that asked the question, thank you anyway :-)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Forward to the same page
Posted by Manfred Wolff <wo...@manfred-wolff.de>.
hi antonio,
Try http://www.manfred-wolff.de/struts/articles/HowTo-Back.html. In this
solution you can go back and stay where you are for language switching.
Manfred
Struts goes mobile. See http://www.strutsme.org
leo mj wrote:
> hi antonio,
>
>
> It can be done by using ActionForwards.Also go tru internatinalization in struts
> for displaying langauage :
> http://www.allapplabs.com/struts/struts_internationalization.htm
>
>
> in the action class use
> ActionForward forward=new ActionForward();
>
> if(chk whther the language combo box has been selected ){
>
> forward=mapping.getInputForward();
>
> }
>
> add internationalization code using
> <bean:messageKey>
> get language to be selected using request.getAttribute("fieldName");
>
> in ur jsp...
>
> Regards,
> Leo
>
>
>
>
>
>
>
>
>
> Artem Zhmurov <da...@yandex.ru> wrote: What about using JavaScript? Try this:
>
>
>
>
>
> Changing location
>
>
>
>
> function changeLanguage(lang){
> var location = window.location.href;
> if(location.indexOf("?") == -1){
> location += "?lang=";
> location += lang;
> window.location = location;
> } else {
> var pos = location.indexOf("lang=");
> if(pos != -1){
> var new_location = location.substring(0, pos + 5);
> new_location += lang;
> window.location = new_location;
> } else {
> location += "&lang=";
> location += lang;
> window.location = location;
> }
> }
> }
>
>
>
> [input]
> [input]
>
>
>
> It will work if you don't need the addition page (such as when dealing with
> login).
>
> Also you have to be sure, that your lang=.. parameter is in the end of
> parameters line (that is true until you're not trying to add lang=..
> somewhere outside). And there will be problem if your application dealing
> with parameters named, for example, 'XXXlang'. All imperfections mentioned
> can be removed by some little changes in script.
>
>
>> -----Original Message-----
>> From: Antonio Petrelli [mailto:brenmcguire@tariffenet.it]
>> Sent: Friday, August 25, 2006 12:09 PM
>> To: Struts Users Mailing List
>> Subject: Re: Forward to the same page
>>
>> Thomas Hamacher ha scritto:
>>
>>> How do I forward to the same page I was coming from? The typical example
>>>
>> for
>>
>>> this is the "change-language-problem". Someone is on one page and simply
>>> wants to change the language and expects to see the same page in a
>>>
>> different
>>
>>> language.
>>>
>>>
>> Just an idea, tag has the "action" attribute that is no more
>> required. If it is not specified the last servlet path (i.e. "post
>> back") will be taken.
>> http://struts.apache.org/1.x/struts-taglib/tlddoc/html/form.html
>> You could grab the code that controls the value of the "action"
>> attribute to determine the path you're coming from. Then you "change the
>> language" and then redirect (I think it's better than forwarding) to the
>> previous servlet path.
>>
>> HTH
>> Antonio
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
> ---------------------------------
> How low will we go? Check out Yahoo! Messenger’s low PC-to-Phone call rates.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
RE: Forward to the same page
Posted by leo mj <le...@yahoo.com>.
hi antonio,
It can be done by using ActionForwards.Also go tru internatinalization in struts
for displaying langauage :
http://www.allapplabs.com/struts/struts_internationalization.htm
in the action class use
ActionForward forward=new ActionForward();
if(chk whther the language combo box has been selected ){
forward=mapping.getInputForward();
}
add internationalization code using
<bean:messageKey>
get language to be selected using request.getAttribute("fieldName");
in ur jsp...
Regards,
Leo
Artem Zhmurov <da...@yandex.ru> wrote: What about using JavaScript? Try this:
Changing location
function changeLanguage(lang){
var location = window.location.href;
if(location.indexOf("?") == -1){
location += "?lang=";
location += lang;
window.location = location;
} else {
var pos = location.indexOf("lang=");
if(pos != -1){
var new_location = location.substring(0, pos + 5);
new_location += lang;
window.location = new_location;
} else {
location += "&lang=";
location += lang;
window.location = location;
}
}
}
[input]
[input]
It will work if you don't need the addition page (such as when dealing with
login).
Also you have to be sure, that your lang=.. parameter is in the end of
parameters line (that is true until you're not trying to add lang=..
somewhere outside). And there will be problem if your application dealing
with parameters named, for example, 'XXXlang'. All imperfections mentioned
can be removed by some little changes in script.
> -----Original Message-----
> From: Antonio Petrelli [mailto:brenmcguire@tariffenet.it]
> Sent: Friday, August 25, 2006 12:09 PM
> To: Struts Users Mailing List
> Subject: Re: Forward to the same page
>
> Thomas Hamacher ha scritto:
> > How do I forward to the same page I was coming from? The typical example
> for
> > this is the "change-language-problem". Someone is on one page and simply
> > wants to change the language and expects to see the same page in a
> different
> > language.
> >
>
> Just an idea, tag has the "action" attribute that is no more
> required. If it is not specified the last servlet path (i.e. "post
> back") will be taken.
> http://struts.apache.org/1.x/struts-taglib/tlddoc/html/form.html
> You could grab the code that controls the value of the "action"
> attribute to determine the path you're coming from. Then you "change the
> language" and then redirect (I think it's better than forwarding) to the
> previous servlet path.
>
> HTH
> Antonio
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
---------------------------------
How low will we go? Check out Yahoo! MessengerÂ’s low PC-to-Phone call rates.