[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Gavin King gavin.king at jboss.com
Sat Dec 16 19:25:14 EST 2006


  User: gavin   
  Date: 06/12/16 19:25:14

  Modified:    src/main/org/jboss/seam/core    Exceptions.java Page.java
                        Pages.java
  Log:
  JBSEAM-605, navigation in pages.xml
  make s:link action trigger navigation even if outcome is null (but not page actions)
  
  Revision  Changes    Path
  1.18      +3 -47     jboss-seam/src/main/org/jboss/seam/core/Exceptions.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Exceptions.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Exceptions.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -b -r1.17 -r1.18
  --- Exceptions.java	16 Dec 2006 02:58:10 -0000	1.17
  +++ Exceptions.java	17 Dec 2006 00:25:14 -0000	1.18
  @@ -7,12 +7,9 @@
   import java.util.ArrayList;
   import java.util.List;
   
  -import javax.faces.component.UIViewRoot;
   import javax.faces.context.FacesContext;
   import javax.faces.event.PhaseId;
   
  -import org.jboss.seam.log.LogProvider;
  -import org.jboss.seam.log.Logging;
   import org.dom4j.Document;
   import org.dom4j.Element;
   import org.dom4j.io.SAXReader;
  @@ -29,6 +26,8 @@
   import org.jboss.seam.contexts.Context;
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.contexts.Lifecycle;
  +import org.jboss.seam.log.LogProvider;
  +import org.jboss.seam.log.Logging;
   import org.jboss.seam.util.DTDEntityResolver;
   import org.jboss.seam.util.Reflections;
   import org.jboss.seam.util.Resources;
  @@ -45,7 +44,7 @@
   @Intercept(NEVER)
   @Install(precedence=BUILT_IN)
   @Name("org.jboss.seam.core.exceptions")
  -public class Exceptions 
  +public class Exceptions extends Navigator
   {
      private static final LogProvider log = Logging.getLogProvider(Exceptions.class);
      
  @@ -415,49 +414,6 @@
         }
      }
      
  -   protected static void error(int code, String message)
  -   {
  -      if ( log.isDebugEnabled() ) log.debug("sending error: " + code);
  -      org.jboss.seam.core.HttpError httpError = org.jboss.seam.core.HttpError.instance();
  -      if (message==null)
  -      {
  -         httpError.send(code);
  -      }
  -      else
  -      {
  -         httpError.send(code, message);
  -      }
  -   }
  -
  -   protected static void redirect(String viewId)
  -   {
  -      if ( Strings.isEmpty(viewId) )
  -      {
  -         viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
  -      }
  -      if ( log.isDebugEnabled() ) log.debug("redirecting to: " + viewId);
  -      org.jboss.seam.core.Redirect redirect = org.jboss.seam.core.Redirect.instance();
  -      redirect.setViewId(viewId);
  -      redirect.execute();
  -   }
  -   
  -   protected static void render(String viewId)
  -   {
  -      FacesContext facesContext = FacesContext.getCurrentInstance();
  -      if ( !Strings.isEmpty(viewId) )
  -      {
  -         UIViewRoot viewRoot = facesContext.getApplication().getViewHandler()
  -               .createView(facesContext, viewId);
  -         facesContext.setViewRoot(viewRoot);
  -      }
  -      else
  -      {
  -         viewId = facesContext.getViewRoot().getViewId(); //just for the log message
  -      }
  -      if ( log.isDebugEnabled() ) log.debug("rendering: " + viewId);
  -      facesContext.renderResponse();
  -   }
  -
      private static Object rethrow(Exception e) throws Exception
      {
         //SeamExceptionFilter does *not* do these things, which 
  
  
  
  1.9       +141 -19   jboss-seam/src/main/org/jboss/seam/core/Page.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Page.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Page.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -b -r1.8 -r1.9
  --- Page.java	16 Dec 2006 14:37:37 -0000	1.8
  +++ Page.java	17 Dec 2006 00:25:14 -0000	1.9
  @@ -1,7 +1,9 @@
   package org.jboss.seam.core;
   
   import java.util.ArrayList;
  +import java.util.HashMap;
   import java.util.List;
  +import java.util.Map;
   import java.util.MissingResourceException;
   
   import javax.faces.context.FacesContext;
  @@ -93,6 +95,109 @@
   
      }
   
  +   public static final class Navigation
  +   {
  +      private ValueBinding<Object> outcomeValueBinding;
  +      private Map<String, Case> cases = new HashMap<String, Case>();
  +      private Case defaultCase;
  +      
  +      public Map<String, Case> getCases()
  +      {
  +         return cases;
  +      }
  +      
  +      void setDefaultCase(Case defaultCase)
  +      {
  +         this.defaultCase = defaultCase;
  +      }
  +      public Case getDefaultCase()
  +      {
  +         return defaultCase;
  +      }
  +      
  +      void setOutcomeValueBinding(ValueBinding<Object> outcomeValueBinding)
  +      {
  +         this.outcomeValueBinding = outcomeValueBinding;
  +      }
  +      public ValueBinding<Object> getOutcomeValueBinding()
  +      {
  +         return outcomeValueBinding;
  +      }
  +   }
  +   
  +   public static final class Case
  +   {
  +      private Result result;
  +      private boolean isBeginConversation;
  +      private boolean isEndConversation;
  +      private boolean join;
  +      private boolean nested;
  +      private FlushModeType flushMode;
  +      private String pageflow;
  +      
  +      void setResult(Result result)
  +      {
  +         this.result = result;
  +      }
  +      Result getResult()
  +      {
  +         return result;
  +      }
  +      void setBeginConversation(boolean isBeginConversation)
  +      {
  +         this.isBeginConversation = isBeginConversation;
  +      }
  +      boolean isBeginConversation()
  +      {
  +         return isBeginConversation;
  +      }
  +      void setEndConversation(boolean isEndConversation)
  +      {
  +         this.isEndConversation = isEndConversation;
  +      }
  +      boolean isEndConversation()
  +      {
  +         return isEndConversation;
  +      }
  +      void setJoin(boolean join)
  +      {
  +         this.join = join;
  +      }
  +      boolean isJoin()
  +      {
  +         return join;
  +      }
  +      void setNested(boolean nested)
  +      {
  +         this.nested = nested;
  +      }
  +      boolean isNested()
  +      {
  +         return nested;
  +      }
  +      void setFlushMode(FlushModeType flushMode)
  +      {
  +         this.flushMode = flushMode;
  +      }
  +      FlushModeType getFlushMode()
  +      {
  +         return flushMode;
  +      }
  +      void setPageflow(String pageflow)
  +      {
  +         this.pageflow = pageflow;
  +      }
  +      String getPageflow()
  +      {
  +         return pageflow;
  +      }
  +   }
  +   
  +   public interface Result
  +   {
  +      public void navigate(FacesContext context);
  +   }
  +
      private final String viewId;
      private String description;
      private Integer timeout;
  @@ -101,7 +206,9 @@
      private String noConversationViewId;
      private String resourceBundleName;
      private boolean switchEnabled = true;
  -   private List<Page.PageParameter> pageParameters = new ArrayList<Page.PageParameter>();
  +   private List<PageParameter> pageParameters = new ArrayList<PageParameter>();
  +   private Map<String, Navigation> navigations = new HashMap<String, Navigation>();
  +   private Navigation defaultNavigation;
      private boolean isBeginConversation;
      private boolean isEndConversation;
      private boolean join;
  @@ -163,7 +270,7 @@
         return Interpolator.instance().interpolate( getDescription() );
      }
      
  -   public void setDescription(String description)
  +   void setDescription(String description)
      {
         this.description = description;
      }
  @@ -173,7 +280,7 @@
         return description;
      }
   
  -   public void setTimeout(Integer timeout)
  +   void setTimeout(Integer timeout)
      {
         this.timeout = timeout;
      }
  @@ -183,7 +290,7 @@
         return timeout;
      }
   
  -   public void setAction(MethodBinding action)
  +   void setAction(MethodBinding action)
      {
         this.action = action;
      }
  @@ -193,7 +300,7 @@
         return action;
      }
   
  -   public void setOutcome(String outcome)
  +   void setOutcome(String outcome)
      {
         this.outcome = outcome;
      }
  @@ -203,7 +310,7 @@
         return outcome;
      }
   
  -   public void setNoConversationViewId(String noConversationViewId)
  +   void setNoConversationViewId(String noConversationViewId)
      {
         this.noConversationViewId = noConversationViewId;
      }
  @@ -213,7 +320,7 @@
         return noConversationViewId;
      }
   
  -   public void setResourceBundleName(String resourceBundleName)
  +   void setResourceBundleName(String resourceBundleName)
      {
         this.resourceBundleName = resourceBundleName;
      }
  @@ -223,7 +330,7 @@
         return resourceBundleName;
      }
   
  -   public void setSwitchEnabled(boolean switchEnabled)
  +   void setSwitchEnabled(boolean switchEnabled)
      {
         this.switchEnabled = switchEnabled;
      }
  @@ -238,6 +345,11 @@
         return pageParameters;
      }
   
  +   public Map<String, Page.Navigation> getNavigations()
  +   {
  +      return navigations;
  +   }
  +
      public boolean hasDescription()
      {
         return description!=null;
  @@ -248,7 +360,7 @@
         return isBeginConversation;
      }
   
  -   public void setBeginConversation(boolean isBeginConversation)
  +   void setBeginConversation(boolean isBeginConversation)
      {
         this.isBeginConversation = isBeginConversation;
      }
  @@ -258,7 +370,7 @@
         return isEndConversation;
      }
   
  -   public void setEndConversation(boolean isEndConversation)
  +   void setEndConversation(boolean isEndConversation)
      {
         this.isEndConversation = isEndConversation;
      }
  @@ -283,42 +395,42 @@
         }
      }
   
  -   protected FlushModeType getFlushMode()
  +   public FlushModeType getFlushMode()
      {
         return flushMode;
      }
   
  -   protected void setFlushMode(FlushModeType flushMode)
  +   void setFlushMode(FlushModeType flushMode)
      {
         this.flushMode = flushMode;
      }
   
  -   protected boolean isJoin()
  +   public boolean isJoin()
      {
         return join;
      }
   
  -   protected void setJoin(boolean join)
  +   void setJoin(boolean join)
      {
         this.join = join;
      }
   
  -   protected boolean isNested()
  +   public boolean isNested()
      {
         return nested;
      }
   
  -   protected void setNested(boolean nested)
  +   void setNested(boolean nested)
      {
         this.nested = nested;
      }
   
  -   protected String getPageflow()
  +   public String getPageflow()
      {
         return pageflow;
      }
   
  -   protected void setPageflow(String pageflow)
  +   void setPageflow(String pageflow)
      {
         this.pageflow = pageflow;
      }
  @@ -328,9 +440,19 @@
         return conversationRequired;
      }
   
  -   protected void setConversationRequired(boolean conversationRequired)
  +   void setConversationRequired(boolean conversationRequired)
      {
         this.conversationRequired = conversationRequired;
      }
   
  +   public Navigation getDefaultNavigation()
  +   {
  +      return defaultNavigation;
  +   }
  +
  +   void setDefaultNavigation(Navigation defaultActionOutcomeMapping)
  +   {
  +      this.defaultNavigation = defaultActionOutcomeMapping;
  +   }
  +
   }
  \ No newline at end of file
  
  
  
  1.61      +183 -52   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.60
  retrieving revision 1.61
  diff -u -b -r1.60 -r1.61
  --- Pages.java	16 Dec 2006 14:37:37 -0000	1.60
  +++ Pages.java	17 Dec 2006 00:25:14 -0000	1.61
  @@ -19,8 +19,6 @@
   import javax.faces.context.FacesContext;
   import javax.faces.convert.Converter;
   
  -import org.jboss.seam.log.LogProvider;
  -import org.jboss.seam.log.Logging;
   import org.dom4j.Document;
   import org.dom4j.DocumentException;
   import org.dom4j.Element;
  @@ -36,6 +34,8 @@
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.core.Expressions.MethodBinding;
   import org.jboss.seam.core.Expressions.ValueBinding;
  +import org.jboss.seam.log.LogProvider;
  +import org.jboss.seam.log.Logging;
   import org.jboss.seam.util.DTDEntityResolver;
   import org.jboss.seam.util.Parameters;
   import org.jboss.seam.util.Resources;
  @@ -50,7 +50,7 @@
   @Intercept(NEVER)
   @Name("org.jboss.seam.core.pages")
   @Install(precedence=BUILT_IN)
  -public class Pages 
  +public class Pages extends Navigator
   {
      
      private static final LogProvider log = Logging.getLogProvider(Pages.class);
  @@ -122,82 +122,133 @@
         return root;
      }
   
  -   private void parse(Element page, String viewId)
  +   private void parse(Element element, String viewId)
  +   {
  +      Page page = parsePage(element, viewId);
  +      
  +      List<Element> children = element.elements("param");
  +      for (Element param: children)
  +      {
  +         page.getPageParameters().add( parsePageParameter(param) );
  +      }
  +      
  +      List<Element> moreChildren = element.elements("navigation");
  +      for (Element fromAction: moreChildren)
  +      {
  +         parseNavigation(page, fromAction);
  +      }
  +   }
  +
  +   private Page parsePage(Element element, String viewId)
      {
         if ( viewId.endsWith("*") )
         {
            wildcardViewIds.add(viewId);
         }
  -      Page entry = new Page(viewId);
  -      pagesByViewId.put(viewId, entry);
  +      Page page = new Page(viewId);
  +      pagesByViewId.put(viewId, page);
         
  -      entry.setSwitchEnabled( !"disabled".equals( page.attributeValue("switch") ) );
  +      page.setSwitchEnabled( !"disabled".equals( element.attributeValue("switch") ) );
         
  -      String description = page.getTextTrim();
  +      Element optionalElement = element.element("description");
  +      String description = optionalElement==null ? 
  +               element.getTextTrim() : optionalElement.getTextTrim();
         if (description!=null && description.length()>0)
         {
  -         entry.setDescription(description);
  +         page.setDescription(description);
         }
         
  -      String timeoutString = page.attributeValue("timeout");
  +      String timeoutString = element.attributeValue("timeout");
         if (timeoutString!=null)
         {
  -         entry.setTimeout(Integer.parseInt(timeoutString));
  +         page.setTimeout(Integer.parseInt(timeoutString));
         }
         
  -      entry.setNoConversationViewId( page.attributeValue("no-conversation-view-id") );
  -      entry.setConversationRequired( "true".equals( page.attributeValue("conversation-required") ) );
  +      page.setNoConversationViewId( element.attributeValue("no-conversation-view-id") );
  +      page.setConversationRequired( "true".equals( element.attributeValue("conversation-required") ) );
         
  -      String action = page.attributeValue("action");
  +      String action = element.attributeValue("action");
         if (action!=null)
         {
            if ( action.startsWith("#{") )
            {
               MethodBinding methodBinding = Expressions.instance().createMethodBinding(action);
  -            entry.setAction(methodBinding);
  +            page.setAction(methodBinding);
            }
            else
            {
  -            entry.setOutcome(action);
  +            page.setOutcome(action);
            }
         }
         
  -      Element endConversation = page.element("end-conversation");
  +      Element endConversation = element.element("end-conversation");
         if ( endConversation!=null )
         {
  -         entry.setEndConversation(true);
  +         page.setEndConversation(true);
         }
         
  -      Element beginConversation = page.element("begin-conversation");
  +      Element beginConversation = element.element("begin-conversation");
         if ( beginConversation!=null )
         {
  -         entry.setBeginConversation(true);
  -         entry.setJoin( "true".equals( beginConversation.attributeValue("join") ) );
  -         entry.setNested( "true".equals( beginConversation.attributeValue("nested") ) );
  -         entry.setPageflow( beginConversation.attributeValue("pageflow") );
  +         page.setBeginConversation(true);
  +         page.setJoin( "true".equals( beginConversation.attributeValue("join") ) );
  +         page.setNested( "true".equals( beginConversation.attributeValue("nested") ) );
  +         page.setPageflow( beginConversation.attributeValue("pageflow") );
            String flushMode = beginConversation.attributeValue("flush-mode");
            if (flushMode!=null)
            {
  -            entry.setFlushMode( FlushModeType.valueOf( flushMode.toUpperCase() ) );
  +            page.setFlushMode( FlushModeType.valueOf( flushMode.toUpperCase() ) );
            }
         }
         
  -      if ( entry.isBeginConversation() && entry.isEndConversation() )
  +      if ( page.isBeginConversation() && page.isEndConversation() )
         {
            throw new IllegalStateException("cannot use both <begin-conversation/> and <end-conversation/>");
         }
         
  -      String bundle = page.attributeValue("bundle");
  +      String bundle = element.attributeValue("bundle");
         if (bundle!=null)
         {
  -         entry.setResourceBundleName(bundle);
  +         page.setResourceBundleName(bundle);
  +      }
  +      return page;
         }
         
  -      List<Element> children = page.elements("param");
  -      for (Element param: children)
  +   private void parseNavigation(Page entry, Element element)
  +   {
  +      Page.Navigation navigation = new Page.Navigation(); 
  +      String outcomeExpression = element.attributeValue("outcome");
  +      if (outcomeExpression!=null)
  +      {
  +         navigation.setOutcomeValueBinding(Expressions.instance().createValueBinding(outcomeExpression));
  +      }
  +      List<Element> cases = element.elements("case");
  +      for (Element childElement: cases)
  +      {
  +         Page.Case caze = parseCase(childElement);
  +         navigation.getCases().put( childElement.attributeValue("outcome"), caze );
  +      }
  +      Element childElement = element.element("default");
  +      if (childElement!=null)
  +      {
  +         navigation.setDefaultCase(parseCase(childElement));
  +      }
  +      
  +      String expression = element.attributeValue("action");
  +      if (expression==null)
  +      {
  +         entry.setDefaultNavigation(navigation);
  +      }
  +      else
  +      {
  +         entry.getNavigations().put(expression, navigation);
  +      }
  +   }
  +
  +   private Page.PageParameter parsePageParameter(Element element)
         {
  -         String valueExpression = param.attributeValue("value");
  -         String name = param.attributeValue("name");
  +      String valueExpression = element.attributeValue("value");
  +      String name = element.attributeValue("name");
            if (name==null)
            {
               if (valueExpression==null)
  @@ -211,14 +262,88 @@
            {
               pageParameter.setValueBinding(Expressions.instance().createValueBinding(valueExpression));
            }
  -         pageParameter.setConverterId(param.attributeValue("converterId"));
  -         String converterExpression = param.attributeValue("converter");
  +      pageParameter.setConverterId(element.attributeValue("converterId"));
  +      String converterExpression = element.attributeValue("converter");
            if (converterExpression!=null)
            {
               pageParameter.setConverterValueBinding(Expressions.instance().createValueBinding(converterExpression));
            }
  -         entry.getPageParameters().add(pageParameter);
  +      return pageParameter;
  +   }
  +
  +   private Page.Case parseCase(Element element)
  +   {
  +      Page.Case caze = new Page.Case();
  +      Element render = element.element("render");
  +      if (render!=null)
  +      {
  +         final String viewId = render.attributeValue("view-id");
  +         caze.setResult(new Page.Result() {
  +            public void navigate(FacesContext context)
  +            {
  +               render(viewId);
  +            }
  +         });
  +      }
  +      Element redirect = element.element("redirect");
  +      if (redirect!=null)
  +      {
  +         final String viewId = redirect.attributeValue("view-id");
  +         caze.setResult(new Page.Result() {
  +            public void navigate(FacesContext context)
  +            {
  +               redirect(viewId);
         }
  +         });
  +      }
  +      return caze;
  +   }
  +
  +   public boolean navigate(FacesContext context, String actionExpression, final String actionOutcome)
  +   {
  +      String viewId = context.getViewRoot().getViewId();
  +      if (viewId!=null)
  +      {
  +         List<Page> stack = getPageStack(viewId);
  +         for (int i=stack.size()-1; i>=0; i--)
  +         {
  +            Page page = stack.get(i);
  +            Page.Navigation navigation = page.getNavigations().get(actionExpression);
  +            if (navigation==null)
  +            {
  +               navigation = page.getDefaultNavigation();
  +            }
  +            
  +            if (navigation!=null)
  +            {
  +               
  +               String outcome;
  +               if ( navigation.getOutcomeValueBinding()==null )
  +               {
  +                  outcome = actionOutcome;
  +               }
  +               else
  +               {
  +                  Object value = navigation.getOutcomeValueBinding().getValue();
  +                  outcome = value==null ? null : value.toString();
  +               }
  +               
  +               Page.Case caze = outcome==null ?
  +                  //JSF navhandler says ignore all rules when null outcome
  +                  navigation.getDefaultCase() :
  +                  navigation.getCases().get(outcome);
  +               if (caze!=null)
  +               {
  +                  //TODO: begin/end conversation, etc!!
  +                  caze.getResult().navigate(context);
  +                  return true;
  +               }
  +               
  +            }
  +            
  +         }
  +      }
  +      return false;
      }
      
      /**
  @@ -363,7 +488,10 @@
            }
         }
         
  +      if (outcome!=null)
  +      {
         handleOutcome(facesContext, outcome, fromAction);
  +      }
         
         return result;
   
  @@ -376,11 +504,11 @@
   
      private static void handleOutcome(FacesContext facesContext, String outcome, String fromAction)
      {
  -      if (outcome!=null)
  -      {
  +      /*if (outcome!=null)
  +      {*/
            facesContext.getApplication().getNavigationHandler()
                  .handleNavigation(facesContext, fromAction, outcome);
  -      }
  +      //}
      }
      
      public static Pages instance()
  @@ -419,10 +547,13 @@
               MethodBinding actionBinding = Expressions.instance().createMethodBinding(expression);
               outcome = toString( actionBinding.invoke() );
               fromAction = expression;
  +            handleOutcome(facesContext, outcome, fromAction);
            }
         }
  -      
  +      else
  +      {
         handleOutcome(facesContext, outcome, fromAction);
  +      }
         
         return result;
      }
  
  
  



More information about the jboss-cvs-commits mailing list