[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...
Gavin King
gavin.king at jboss.com
Mon Dec 18 10:38:49 EST 2006
User: gavin
Date: 06/12/18 10:38:49
Modified: src/main/org/jboss/seam/core Manager.java Pageflow.java
Pages.java Validation.java
Added: src/main/org/jboss/seam/core Validators.java
Log:
new validation component,
reworked navigation rules
Revision Changes Path
1.130 +3 -32 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.129
retrieving revision 1.130
diff -u -b -r1.129 -r1.130
--- Manager.java 18 Dec 2006 11:52:49 -0000 1.129
+++ Manager.java 18 Dec 2006 15:38:49 -0000 1.130
@@ -20,11 +20,8 @@
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
-import javax.faces.el.MethodBinding;
import javax.faces.event.PhaseId;
-import org.jboss.seam.log.LogProvider;
-import org.jboss.seam.log.Logging;
import org.jboss.seam.Component;
import org.jboss.seam.ScopeType;
import org.jboss.seam.Seam;
@@ -36,6 +33,8 @@
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.contexts.Lifecycle;
import org.jboss.seam.contexts.ServerConversationContext;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
import org.jboss.seam.util.Id;
/**
@@ -43,7 +42,7 @@
*
* @author Gavin King
* @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
- * @version $Revision: 1.129 $
+ * @version $Revision: 1.130 $
*/
@Scope(ScopeType.EVENT)
@Name("org.jboss.seam.core.manager")
@@ -1123,32 +1122,4 @@
this.parentConversationIdParameter = nestedConversationIdParameter;
}
- private boolean forceModelUpdate;
- private MethodBinding validationFailedAction;
-
- public void setValidationFailedAction(MethodBinding action)
- {
- validationFailedAction = action;
- }
-
- public void setForceModelUpdate()
- {
- forceModelUpdate = true;
- }
-
- public void afterValidationFailure(FacesContext ctx)
- {
- if (forceModelUpdate)
- {
- ctx.getViewRoot().processUpdates(ctx);
- }
- if (validationFailedAction!=null)
- {
- Object result = validationFailedAction.invoke(ctx, null);
- String outcome = result==null ? null : result.toString();
- ctx.getApplication().getNavigationHandler()
- .handleNavigation(ctx, validationFailedAction.getExpressionString(), outcome);
- }
- }
-
}
1.48 +3 -2 jboss-seam/src/main/org/jboss/seam/core/Pageflow.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Pageflow.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Pageflow.java,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -b -r1.47 -r1.48
--- Pageflow.java 16 Dec 2006 02:58:10 -0000 1.47
+++ Pageflow.java 18 Dec 2006 15:38:49 -0000 1.48
@@ -261,7 +261,8 @@
return getNode().getLeavingTransition(null)!=null;
}
- private boolean isNullOutcome(String outcome) {
+ private boolean isNullOutcome(String outcome)
+ {
return outcome==null || "".equals(outcome);
}
@@ -285,7 +286,7 @@
{
//we don't use jBPM's default transition,
//instead we use the "anonymous" transition
- PageflowHelper.signal(processInstance, (String) null);
+ PageflowHelper.signal(processInstance, null);
navigate(context);
}
}
1.68 +32 -36 jboss-seam/src/main/org/jboss/seam/core/Pages.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Pages.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Pages.java,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -b -r1.67 -r1.68
--- Pages.java 17 Dec 2006 19:46:41 -0000 1.67
+++ Pages.java 18 Dec 2006 15:38:49 -0000 1.68
@@ -125,25 +125,18 @@
outcomeValue = value==null ? null : value.toString();
}
- Outcome outcome;
- if (outcomeValue==null)
+ for ( Outcome outcome: navigation.getOutcomes() )
{
- //JSF navhandler says ignore all rules when null outcome.
- //so we have a special case for that
- outcome = navigation.getNullOutcome();
- }
- else
- {
- outcome = navigation.getOutcomes().get(outcomeValue);
- if (outcome==null) outcome = navigation.getAnyOutcome();
- }
-
- if (outcome!=null)
+ if ( outcome.matches(outcomeValue) )
{
outcome.getConversationControl().beginOrEndConversation();
outcome.getNavigationHandler().navigate(context);
return true;
}
+ }
+
+ navigation.getOutcome().getConversationControl().beginOrEndConversation();
+ navigation.getOutcome().getNavigationHandler().navigate(context);
}
@@ -779,34 +772,24 @@
private static void parseActionNavigation(Page entry, Element element)
{
ActionNavigation navigation = new ActionNavigation();
- String outcomeExpression = element.attributeValue("outcome");
+ String outcomeExpression = element.attributeValue("evaluate");
if (outcomeExpression!=null)
{
navigation.setOutcomeValueBinding( Expressions.instance().createValueBinding(outcomeExpression) );
}
+
List<Element> cases = element.elements("outcome");
for (Element childElement: cases)
{
- Outcome caze = parseOutcome(childElement);
- String value = childElement.attributeValue("value");
- if (value==null)
- {
- throw new IllegalStateException("Must specify value for <outcome/> declaration");
- }
- navigation.getOutcomes().put(value, caze);
- }
- Element childElement = element.element("any-outcome");
- if (childElement!=null)
- {
- navigation.setAnyOutcome( parseOutcome(childElement) );
- }
- childElement = element.element("null-outcome");
- if (childElement!=null)
- {
- navigation.setNullOutcome( parseOutcome(childElement) );
+ navigation.getOutcomes().add( parseOutcome(childElement) );
}
- String expression = element.attributeValue("action");
+ Outcome outcome = new Outcome();
+ parseNavigationHandler(element, outcome);
+ parseConversationControl( element, outcome.getConversationControl() );
+ navigation.setOutcome(outcome);
+
+ String expression = element.attributeValue("from-action");
if (expression==null)
{
entry.setDefaultNavigation(navigation);
@@ -852,8 +835,22 @@
private static Outcome parseOutcome(Element element)
{
Outcome outcome = new Outcome();
+
+ outcome.setValue( element.attributeValue("if-value") );
+ String expression = element.attributeValue("if");
+ if (expression!=null)
+ {
+ outcome.setExpression( Expressions.instance().createValueBinding(expression) );
+ }
+
parseConversationControl( element, outcome.getConversationControl() );
+ parseNavigationHandler(element, outcome);
+
+ return outcome;
+ }
+ private static void parseNavigationHandler(Element element, Outcome outcome)
+ {
Element render = element.element("render");
if (render!=null)
{
@@ -872,7 +869,6 @@
final String viewId = redirect.attributeValue("view-id");
outcome.setNavigationHandler( new RedirectNavigationHandler(viewId, params) );
}
- return outcome;
}
}
1.6 +29 -60 jboss-seam/src/main/org/jboss/seam/core/Validation.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Validation.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Validation.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- Validation.java 15 Dec 2006 06:50:41 -0000 1.5
+++ Validation.java 18 Dec 2006 15:38:49 -0000 1.6
@@ -2,93 +2,62 @@
import static org.jboss.seam.annotations.Install.BUILT_IN;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
import javax.faces.context.FacesContext;
-import org.hibernate.validator.ClassValidator;
-import org.hibernate.validator.InvalidValue;
import org.jboss.seam.Component;
import org.jboss.seam.InterceptionType;
import org.jboss.seam.ScopeType;
+import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Intercept;
import org.jboss.seam.annotations.Name;
-import org.jboss.seam.annotations.Install;
-import org.jboss.seam.annotations.Scope;
import org.jboss.seam.contexts.Contexts;
+/**
+ * Allows the application to determine whether the JSF validation
+ * phase completed successfully, or if a validation failure
+ * occurred.
+ *
+ * @author Gavin king
+ *
+ */
@Name("org.jboss.seam.core.validation")
@Intercept(InterceptionType.NEVER)
- at Scope(ScopeType.APPLICATION)
@Install(precedence=BUILT_IN)
public class Validation
{
- private Map<Class, ClassValidator> classValidators = Collections.synchronizedMap( new HashMap<Class, ClassValidator>() );
+ private boolean succeeded;
+ private boolean failed;
- public ClassValidator getValidator(Class modelClass, String name)
+ public static Validation instance()
{
- ClassValidator result = classValidators.get(modelClass);
- if (result==null)
+ if ( !Contexts.isEventContextActive() )
{
- result = createValidator(modelClass, name);
- classValidators.put(modelClass, result);
+ throw new IllegalStateException("No active event scope");
}
- return result;
+ return (Validation) Component.getInstance(Validation.class, ScopeType.EVENT);
}
- public ClassValidator createValidator(Class modelClass, String name)
- {
- Component component = name==null ? null : Component.forName(name);
- if (component==null)
+ public void afterProcessValidations(FacesContext facesContext)
{
- java.util.ResourceBundle bundle = ResourceBundle.instance();
- return bundle==null ?
- new ClassValidator(modelClass) :
- new ClassValidator(modelClass, bundle);
- }
- else
- {
- return component.getValidator();
- }
+ failed = facesContext.getRenderResponse();
+ succeeded = !failed;
}
- public InvalidValue[] validate(FacesContext context, String propertyExpression, Object value)
- {
- int dot = propertyExpression.lastIndexOf('.');
- int bracket = propertyExpression.lastIndexOf('[');
- if (dot<=0 && bracket<=0)
+ public boolean isSucceeded()
{
- return new InvalidValue[0];
- }
- String componentName;
- String propertyName;
- if (dot>bracket)
- {
- componentName = propertyExpression.substring(2, dot);
- propertyName = propertyExpression.substring( dot+1, propertyExpression.length()-1 );
- }
- else
- {
- componentName = propertyExpression.substring(2, bracket);
- propertyName = propertyExpression.substring( bracket+1, propertyExpression.length()-2 );
+ return succeeded;
}
- String modelExpression = propertyExpression.substring(0, dot) + '}';
- Object model = context.getApplication().createValueBinding(modelExpression).getValue(context);
- ClassValidator validator = getValidator( model.getClass(), componentName );
- return validator.getPotentialInvalidValues(propertyName, value);
+ public boolean isFailed()
+ {
+ return failed;
}
- public static Validation instance()
+ public void fail()
{
- if ( !Contexts.isApplicationContextActive() )
- {
- throw new IllegalStateException("No active application scope");
- }
- return (Validation) Component.getInstance(Validation.class, ScopeType.APPLICATION);
+ failed = true;
+ succeeded = false;
}
}
1.1 date: 2006/12/18 15:38:49; author: gavin; state: Exp;jboss-seam/src/main/org/jboss/seam/core/Validators.java
Index: Validators.java
===================================================================
package org.jboss.seam.core;
import static org.jboss.seam.annotations.Install.BUILT_IN;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import javax.faces.context.FacesContext;
import org.hibernate.validator.ClassValidator;
import org.hibernate.validator.InvalidValue;
import org.jboss.seam.Component;
import org.jboss.seam.InterceptionType;
import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.Install;
import org.jboss.seam.annotations.Intercept;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.contexts.Contexts;
/**
* Caches instances of Hibernate Validator ClassValidator
*
* @author Gavin King
*
*/
@Name("org.jboss.seam.core.validators")
@Intercept(InterceptionType.NEVER)
@Scope(ScopeType.APPLICATION)
@Install(precedence=BUILT_IN)
public class Validators
{
private Map<Class, ClassValidator> classValidators = Collections.synchronizedMap( new HashMap<Class, ClassValidator>() );
public ClassValidator getValidator(Class modelClass, String name)
{
ClassValidator result = classValidators.get(modelClass);
if (result==null)
{
result = createValidator(modelClass, name);
classValidators.put(modelClass, result);
}
return result;
}
public ClassValidator createValidator(Class modelClass, String name)
{
Component component = name==null ? null : Component.forName(name);
if (component==null)
{
java.util.ResourceBundle bundle = ResourceBundle.instance();
return bundle==null ?
new ClassValidator(modelClass) :
new ClassValidator(modelClass, bundle);
}
else
{
return component.getValidator();
}
}
public InvalidValue[] validate(FacesContext context, String propertyExpression, Object value)
{
int dot = propertyExpression.lastIndexOf('.');
int bracket = propertyExpression.lastIndexOf('[');
if (dot<=0 && bracket<=0)
{
return new InvalidValue[0];
}
String componentName;
String propertyName;
if (dot>bracket)
{
componentName = propertyExpression.substring(2, dot);
propertyName = propertyExpression.substring( dot+1, propertyExpression.length()-1 );
}
else
{
componentName = propertyExpression.substring(2, bracket);
propertyName = propertyExpression.substring( bracket+1, propertyExpression.length()-2 );
}
String modelExpression = propertyExpression.substring(0, dot) + '}';
Object model = context.getApplication().createValueBinding(modelExpression).getValue(context);
ClassValidator validator = getValidator( model.getClass(), componentName );
return validator.getPotentialInvalidValues(propertyName, value);
}
public static Validators instance()
{
if ( !Contexts.isApplicationContextActive() )
{
throw new IllegalStateException("No active application scope");
}
return (Validators) Component.getInstance(Validators.class, ScopeType.APPLICATION);
}
}
More information about the jboss-cvs-commits
mailing list