[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Gavin King
gavin.king at jboss.com
Mon Dec 18 06:52:50 EST 2006
User: gavin
Date: 06/12/18 06:52:49
Modified: src/main/org/jboss/seam/core LocaleSelector.java
Manager.java TimeZoneSelector.java
Added: src/main/org/jboss/seam/core Selector.java
Log:
JBSEAM-610, JBSEAM-536, refactor
Revision Changes Path
1.17 +19 -41 jboss-seam/src/main/org/jboss/seam/core/LocaleSelector.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: LocaleSelector.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/LocaleSelector.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- LocaleSelector.java 26 Nov 2006 03:22:59 -0000 1.16
+++ LocaleSelector.java 18 Dec 2006 11:52:49 -0000 1.17
@@ -3,7 +3,6 @@
import static org.jboss.seam.InterceptionType.NEVER;
import static org.jboss.seam.annotations.Install.BUILT_IN;
-import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -13,9 +12,7 @@
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.ServletRequest;
-import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
@@ -38,41 +35,40 @@
@Name("org.jboss.seam.core.localeSelector")
@Intercept(NEVER)
@Install(precedence=BUILT_IN)
-public class LocaleSelector extends AbstractMutable implements Serializable
+public class LocaleSelector extends Selector
{
private String language;
private String country;
private String variant;
- private boolean cookieEnabled;
- private int cookieMaxAge = 31536000; //1 year
-
@Create
public void initLocale()
{
- if (cookieEnabled)
- {
- Cookie cookie = (Cookie) FacesContext.getCurrentInstance().getExternalContext()
- .getRequestCookieMap().get("org.jboss.seam.core.Locale");
- if (cookie!=null) setLocaleString( cookie.getValue() );
+ String localeString = getCookieValue();
+ if (localeString!=null) setLocaleString(localeString);
}
+
+ @Override
+ protected String getCookieName()
+ {
+ return "org.jboss.seam.core.Locale";
}
/**
- * Force the resource bundle to reload, using the current locale
+ * Force the resource bundle to reload, using the current locale,
+ * and raise the org.jboss.seam.localeSelected event.
*/
public void select()
{
FacesContext.getCurrentInstance().getViewRoot().setLocale( getLocale() );
Contexts.removeFromAllContexts( Seam.getComponentName(ResourceBundle.class) );
Contexts.removeFromAllContexts( Seam.getComponentName(Messages.class) );
- if (cookieEnabled)
- {
- HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
- Cookie cookie = new Cookie( "org.jboss.seam.core.Locale", getLocaleString() );
- cookie.setMaxAge(cookieMaxAge);
- response.addCookie(cookie);
+
+ setCookieValue( getLocaleString() );
+
+ if ( Events.exists() ) {
+ Events.instance().raiseEvent( "org.jboss.seam.localeSelected", getLocaleString() );
}
}
@@ -140,6 +136,9 @@
return selectItems;
}
+ /**
+ * Get the selected locale
+ */
public Locale getLocale()
{
FacesContext facesContext = FacesContext.getCurrentInstance();
@@ -201,25 +200,4 @@
this.variant = variant;
}
- public boolean isCookieEnabled()
- {
- return cookieEnabled;
- }
-
- public void setCookieEnabled(boolean cookieEnabled)
- {
- setDirty(this.cookieEnabled, cookieEnabled);
- this.cookieEnabled = cookieEnabled;
- }
-
- protected int getCookieMaxAge()
- {
- return cookieMaxAge;
- }
-
- protected void setCookieMaxAge(int cookieMaxAge)
- {
- this.cookieMaxAge = cookieMaxAge;
- }
-
}
1.129 +5 -2 jboss-seam/src/main/org/jboss/seam/core/Manager.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Manager.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Manager.java,v
retrieving revision 1.128
retrieving revision 1.129
diff -u -b -r1.128 -r1.129
--- Manager.java 18 Dec 2006 01:46:24 -0000 1.128
+++ Manager.java 18 Dec 2006 11:52:49 -0000 1.129
@@ -43,7 +43,7 @@
*
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.128 $
+ * @version $Revision: 1.129 $
*/
@Scope(ScopeType.EVENT)
@Name("org.jboss.seam.core.manager")
@@ -1144,7 +1144,10 @@
}
if (validationFailedAction!=null)
{
- validationFailedAction.invoke(ctx, null);
+ Object result = validationFailedAction.invoke(ctx, null);
+ String outcome = result==null ? null : result.toString();
+ ctx.getApplication().getNavigationHandler()
+ .handleNavigation(ctx, validationFailedAction.getExpressionString(), outcome);
}
}
1.7 +97 -122 jboss-seam/src/main/org/jboss/seam/core/TimeZoneSelector.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TimeZoneSelector.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/TimeZoneSelector.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- TimeZoneSelector.java 26 Nov 2006 03:22:59 -0000 1.6
+++ TimeZoneSelector.java 18 Dec 2006 11:52:49 -0000 1.7
@@ -3,12 +3,6 @@
import static org.jboss.seam.InterceptionType.NEVER;
import static org.jboss.seam.annotations.Install.BUILT_IN;
-import java.io.Serializable;
-
-import javax.faces.context.FacesContext;
-import javax.servlet.http.Cookie;
-import javax.servlet.http.HttpServletResponse;
-
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Create;
@@ -28,36 +22,35 @@
@Name("org.jboss.seam.core.timeZoneSelector")
@Intercept(NEVER)
@Install(value=false, precedence=BUILT_IN)
-public class TimeZoneSelector extends AbstractMutable implements Serializable
+public class TimeZoneSelector extends Selector
{
private String id;
- private boolean cookieEnabled;
- private int cookieMaxAge = 31536000; //1 year
-
@Create
public void initTimeZone()
{
- if (cookieEnabled)
- {
- Cookie cookie = (Cookie) FacesContext.getCurrentInstance().getExternalContext()
- .getRequestCookieMap().get("org.jboss.seam.core.TimeZone");
- if (cookie!=null) setTimeZoneId( cookie.getValue() );
+ String timeZoneId = getCookieValue();
+ if (timeZoneId!=null) setTimeZoneId(timeZoneId);
}
+
+ @Override
+ protected String getCookieName()
+ {
+ return "org.jboss.seam.core.TimeZone";
}
/**
- * Force the resource bundle to reload, using the current locale
+ * Force the resource bundle to reload, using the current locale,
+ * and raise the org.jboss.seam.timeToneSelected event
*/
public void select()
{
- if (cookieEnabled)
+ setCookieValue( getTimeZoneId() );
+
+ if ( Events.exists() )
{
- HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
- Cookie cookie = new Cookie( "org.jboss.seam.core.TimeZone", getTimeZoneId() );
- cookie.setMaxAge(cookieMaxAge);
- response.addCookie(cookie);
+ Events.instance().raiseEvent( "org.jboss.seam.timeToneSelected", getTimeZoneId() );
}
}
@@ -77,6 +70,9 @@
return id;
}
+ /**
+ * Get the selected timezone
+ */
public java.util.TimeZone getTimeZone()
{
if (id==null)
@@ -98,25 +94,4 @@
return (TimeZoneSelector) Component.getInstance(TimeZoneSelector.class, ScopeType.SESSION);
}
- public boolean isCookieEnabled()
- {
- return cookieEnabled;
- }
-
- public void setCookieEnabled(boolean cookieEnabled)
- {
- setDirty(this.cookieEnabled, cookieEnabled);
- this.cookieEnabled = cookieEnabled;
- }
-
- protected int getCookieMaxAge()
- {
- return cookieMaxAge;
- }
-
- protected void setCookieMaxAge(int cookieMaxAge)
- {
- this.cookieMaxAge = cookieMaxAge;
- }
-
}
1.1 date: 2006/12/18 11:52:49; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/core/Selector.java
Index: Selector.java
===================================================================
package org.jboss.seam.core;
import java.io.Serializable;
import javax.faces.context.FacesContext;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
/**
* Support for selector objects which remember their selection as a cookie
*
* @author Gavin King
*/
public abstract class Selector extends AbstractMutable implements Serializable
{
private boolean cookieEnabled;
private int cookieMaxAge = 31536000; //1 year
/**
* Is the cookie enabled?
* @return false by default
*/
public boolean isCookieEnabled()
{
return cookieEnabled;
}
public void setCookieEnabled(boolean cookieEnabled)
{
setDirty(this.cookieEnabled, cookieEnabled);
this.cookieEnabled = cookieEnabled;
}
/**
* The max age of the cookie
* @return 1 year by default
*/
public int getCookieMaxAge()
{
return cookieMaxAge;
}
public void setCookieMaxAge(int cookieMaxAge)
{
this.cookieMaxAge = cookieMaxAge;
}
/**
* Override to define the cookie name
*/
protected abstract String getCookieName();
/**
* Get the value of the cookie
*/
protected String getCookieValue()
{
if ( isCookieEnabled() )
{
Cookie cookie = (Cookie) FacesContext.getCurrentInstance().getExternalContext()
.getRequestCookieMap().get( getCookieName() );
return cookie==null ? null : cookie.getValue();
}
else
{
return null;
}
}
/**
* Set the cookie
*/
protected void setCookieValue(String value)
{
if ( isCookieEnabled() )
{
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
Cookie cookie = new Cookie( getCookieName(), value );
cookie.setMaxAge( getCookieMaxAge() );
response.addCookie(cookie);
}
}
}
More information about the jboss-cvs-commits
mailing list