You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jim Young <jy...@asd.net> on 2007/04/26 23:52:29 UTC
Struts 2 changing locale from an action
Can anybody tell us how to change the locale from an action in Struts 2. We have users that log-on and in their profile is the language that they wish the web site to be displayed in. I have not be able to find out how to change the locale. All the examples for changing the locale for Struts 2 seem to be from a jsp and using a link. This will not work for us.
Any ideas?
Re: Struts 2 changing locale from an action
Posted by Forest79 <ma...@gmail.com>.
Your actions must extends ActionSupport (or implements LocaleProvider). Than
you must to implement this method:
public Locale getLocale() {
return [user logged locale];
}
Jim Young wrote:
>
> Can anybody tell us how to change the locale from an action in Struts 2.
> We have users that log-on and in their profile is the language that they
> wish the web site to be displayed in. I have not be able to find out how
> to change the locale. All the examples for changing the locale for Struts
> 2 seem to be from a jsp and using a link. This will not work for us.
>
> Any ideas?
>
>
--
View this message in context: http://www.nabble.com/Struts-2-changing-locale-from-an-action-tp10209761p15434479.html
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
S2: ParametersInterceptor setParameters error
Posted by An...@PlayStation.Sony.com.
Hi,
I'm trying to write a very simple web app to do login using Struts2 and
tiles. But when I submit the login form, I get the following errors:
ERROR 14:22.42 [http-8080-2] ParametersInterceptor - ParametersInterceptor
- [setParameters]: Unexpected Exception catched: Error setting expression
'password' with value '[Ljava.lang.String;@d642fd'
ERROR 14:22.42 [http-8080-2] ParametersInterceptor - ParametersInterceptor
- [setParameters]: Unexpected Exception catched: Error setting expression
'username' with value '[Ljava.lang.String;@c7f38c'
Here's my configuration and action code:
-----------------------------------------------------------------
web.xml -
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd"
version="2.5">
<display-name>Sample application</display-name>
<context-param>
<param-name>org.apache.tiles.CONTAINER_FACTORY</param-name>
<param-value>org.apache.struts2.tiles.StrutsTilesContainerFactory</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
---------------------------------------------------------------------------
applicationContext.xml -
<!DOCTYPE beans PUBLIC
"-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
</beans>
---------------------------------------------------------------------------
struts.xml -
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml"/>
<include file="struts-tiles.xml" />
<!-- Add packages here -->
<package name="login" extends="struts-default">
<!-- Add your actions here -->
<action name="login*" method="{1}" class="sample.Login">
<result name="input">/pages/login-body.jsp</result>
<result type="redirect-action">/pages/welcome.jsp</result>
</action>
</package>
</struts>
---------------------------------------------------------------------------
struts-tiles.xml -
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="tiles" extends="tiles-default" namespace="/layout">
<default-action-ref name="index"/>
<action name="index">
<result type="tiles">login.index</result>
<result name="success" type="tiles">login.index</result>
</action>
<action name="sanity">
<result type="redirect">/layout/common-layout.jsp</result>
<result type="redirect"
name="success">/layout/common-layout.jsp</result>
</action>
</package>
</struts>
---------------------------------------------------------------------------
struts.properties -
struts.custom.i18n.resources = globalMessages
struts.enable.DynamicMethodInvocation = true
struts.devMode = true
struts.i18n.reload=false
struts.configuration.xml.reload=false
struts.dispatcher.parametersWorkaround = false
---------------------------------------------------------------------------
Login.java -
package sample;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport {
private static final long serialVersionUID = 3274944238727965478L;
private String username;
private String password;
public Login() {
System.out.println("DEBUGGING - Login constructor...");
}
public String execute() throws Exception {
if (isInvalid(credential.getUsername()) ||
isInvalid(credential.getPassword())) {
return INPUT;
}
return SUCCESS;
}
private boolean isInvalid(String value) {
return ((value == null) || (value.length() == 0));
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
---------------------------------------------------------------------------
login-body.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Sign On</title>
</head>
<div class="content_body">
<body>
<s:form action="login">
<s:textfield label="Username" name="username"/>
<s:password label="Password" name="password" />
<s:submit/>
</s:form>
</body>
</div>
</html>
---------------------------------------------------------------------------
I have searched thru the entire struts-user forum for similar problem but
with no luck.
Any Idea what I did wrong and how to fix it. I am using Struts 2.0.6
Thanks in advance.
Regards,
Annie
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org