Update of 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring
In directory 
james.mmbase.org:/tmp/cvs-serv15021/applications/vpro-wizards/src/org/mmbase/applications/vprowizards/spring

Modified Files:
        CloudFactory.java BasicCommand.java FieldError.java 
        ResultContainer.java Command.java WizardController.java 
        BasicCommandFactory.java ReferrerResolver.java 
        GlobalError.java 
Log Message:
work in progress


See also: 
http://cvs.mmbase.org/viewcvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring


Index: CloudFactory.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/CloudFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- CloudFactory.java   11 Aug 2008 13:03:30 -0000      1.1
+++ CloudFactory.java   8 Sep 2008 16:52:10 -0000       1.2
@@ -13,3 +13,4 @@
        public Transaction getTransaction( HttpServletRequest request);
 }
 
+


Index: BasicCommand.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/BasicCommand.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- BasicCommand.java   11 Aug 2008 13:03:30 -0000      1.1
+++ BasicCommand.java   8 Sep 2008 16:52:10 -0000       1.2
@@ -39,14 +39,15 @@
         * @see 
org.mmbase.applications.vprowizard.spring.Command#processActions(org.mmbase.bridge.Transaction,
 javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, 
java.util.Map, org.mmbase.applications.vprowizard.spring.ResultContainer)
         */
        public void processActions(HttpServletRequest request,
-                       HttpServletResponse response, Map<String, Node> 
nodeMap, ResultContainer resultContainer) {
+                       HttpServletResponse response, ResultContainer 
resultContainer) {
                //we only iterate over the actions until there is an error
                actions:
                for(String actionMapping :  actions.keySet()){
                        Map<String, Action> mappedActions = 
actions.get(actionMapping);
+                       log.service(String.format("%s actions found for mapping 
'%s'", ""+mappedActions.size(), actionMapping));
                        for (Action action: mappedActions.values()){
-                               action.process(nodeMap, resultContainer);
-                               if(resultContainer.containsGlobalErrors() || 
resultContainer.containsFieldErrors()){
+                               action.process(resultContainer);
+                               if(resultContainer.hasGlobalErrors() || 
resultContainer.hasFieldErrors()){
                                         break actions;
                                }
                        }
@@ -54,7 +55,7 @@
        }
 
        public void addAction(String mappingName, Class<? extends Action> 
actionClass) {
-               log.info("mapping action class '"+actionClass.toString()+"' to 
'"+mappingName+"'");
+               log.debug("mapping action class '"+actionClass.toString()+"' to 
'"+mappingName+"'");
                actions.put(mappingName, MapUtils.lazyMap(new HashMap<String, 
Action>(), new MyFactory(actionClass)));
        }
        


Index: FieldError.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/FieldError.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- FieldError.java     11 Aug 2008 13:03:30 -0000      1.1
+++ FieldError.java     8 Sep 2008 16:52:10 -0000       1.2
@@ -3,10 +3,9 @@
 import java.util.Locale;
 
 /**
- * Indien er tijdens het verwerken van de acties een fout optreedt worden 
fielderror gegooit. Deze geven aan welke
- * velden niet verwerkt konden worden.
- * 
- * @author Rob Vermeulen (VPRO)
+ * This is the kind of error that will be created when something went wrong 
with a field value, or setting a field on a node. This kind of error
+ * should be displayed in the referrer page (in connection with a specific 
field input element). It is primerily intended for validation errors.
+ * @author Ernst Bunders
  */
 public class FieldError extends GlobalError {
        private static final long serialVersionUID = 1L;


Index: ResultContainer.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/ResultContainer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ResultContainer.java        11 Aug 2008 13:03:30 -0000      1.1
+++ ResultContainer.java        8 Sep 2008 16:52:10 -0000       1.2
@@ -13,6 +13,8 @@
 import org.mmbase.bridge.Cloud;
 import org.mmbase.bridge.Node;
 import org.mmbase.bridge.Transaction;
+import org.mmbase.util.logging.Logger;
+import org.mmbase.util.logging.Logging;
 
 
 
@@ -32,15 +34,17 @@
     private List<CacheFlushHint> cacheFlushHints = new 
ArrayList<CacheFlushHint>();
     private Transaction transaction = null;
     private Locale locale;
+    private static final Logger log = 
Logging.getLoggerInstance(ResultContainer.class);
 
        HttpServletRequest request;
        HttpServletResponse response;
        private Map<String,Node>idMap = new HashMap<String, Node>();
 
 
-       public ResultContainer(HttpServletRequest request, HttpServletResponse 
response, Cloud transaction, Locale locale) {
+       public ResultContainer(HttpServletRequest request, HttpServletResponse 
response, Transaction transaction, Locale locale) {
                this.request = request;
                this.response = response;
+               this.transaction = transaction;
                this.locale = locale;
        }
 
@@ -61,10 +65,25 @@
 
        }
 
-       public boolean containsFieldErrors() {
+       public void addGlobalError(GlobalError e){
+               if(log.isDebugEnabled()){
+                       log.debug("adding global error: "+e);
+               }
+               globalErrors.add(e);
+       }
+       
+       public void addFieldError(FieldError e){
+               if(log.isDebugEnabled()){
+                       log.debug("adding field error: "+e);
+               }
+               fieldErrors.add(e);
+       }
+       
+
+       public boolean hasFieldErrors() {
                return !fieldErrors.isEmpty();
        }
-       public boolean containsGlobalErrors() {
+       public boolean hasGlobalErrors() {
                return !globalErrors.isEmpty();
        }
 


Index: Command.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/Command.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Command.java        11 Aug 2008 13:03:30 -0000      1.1
+++ Command.java        8 Sep 2008 16:52:10 -0000       1.2
@@ -34,8 +34,7 @@
         * @param transaction an mmbase transaction in which all 
datamanipulation is done
         * @param request
         * @param response
-        * @param nodeMap a map where all the processed nodes that have an 'id' 
attribute set should be added to.
         * @return
         */
-       public void processActions(HttpServletRequest request, 
HttpServletResponse response, Map<String, Node> nodeMap, ResultContainer 
resultContainer);
+       public void processActions(HttpServletRequest request, 
HttpServletResponse response, ResultContainer resultContainer);
 }


Index: WizardController.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/WizardController.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- WizardController.java       11 Aug 2008 13:03:30 -0000      1.1
+++ WizardController.java       8 Sep 2008 16:52:10 -0000       1.2
@@ -40,6 +40,8 @@
                setLocale(new Locale("nl-NL"));
        }
 
+       
+
        /*
         * (non-Javadoc)
         * 
@@ -61,16 +63,13 @@
 
                // process all the actions.
                ResultContainer resultContainer = new ResultContainer(request, 
response, transaction, locale);
-               command.processActions(request, response, nodeMap, 
resultContainer);
+               command.processActions(request, response, resultContainer);
+
+               if (resultContainer.hasGlobalErrors() || 
resultContainer.hasFieldErrors()) {
+                       log.debug("Errors found, transaction not committed.");
 
-               if (resultContainer.containsGlobalErrors()) {
-                       if (log.isDebugEnabled()) {
-                               log.debug("Errors found, redirecting to error 
page.");
-                       }
                } else {
-                       if (log.isDebugEnabled()) {
                                log.debug("No errors found. Commit the 
transaction and put the cache flush hints on the request.");
-                       }
                        transaction.commit();
 
                        // create the request type cache flush hint


Index: BasicCommandFactory.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/BasicCommandFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- BasicCommandFactory.java    11 Aug 2008 13:03:30 -0000      1.1
+++ BasicCommandFactory.java    8 Sep 2008 16:52:10 -0000       1.2
@@ -44,7 +44,7 @@
        public void setActionClasses(List<Class<? extends Action>> 
actionClasses) {
                for(Class<? extends Action> clazz: actionClasses){
                        this.actionClasses.add(clazz);
-                       log.info("Action class "+clazz+" added.");
+                       log.debug("Action class "+clazz+" added.");
                }
        }
        


Index: ReferrerResolver.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/ReferrerResolver.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- ReferrerResolver.java       11 Aug 2008 13:03:30 -0000      1.1
+++ ReferrerResolver.java       8 Sep 2008 16:52:10 -0000       1.2
@@ -13,9 +13,11 @@
 import org.springframework.web.servlet.view.RedirectView;
 
 /**
- * This return page resolver will return the referrer url wiht a parameter 
'nodenr' added
- * when there is a new node in the result container.
- * if there is an error it will return the value of the errorPage field.
+ * This return page resolver will return the referrer url wiht a parameter 
'nodenr' added when there is a new node in
+ * the result container. if there is an error it will return the value of the 
errorPage field. TODO: make sure the error
+ * page exists and shows the errors well. only global errors should trigger 
the error page. field errors should be shown
+ * in the editor.
+ * 
  * @author ebunders
  *
  */
@@ -28,43 +30,57 @@
         String newPage;
         Map<String, Object> model =  new HashMap<String, Object>();
 
-        if (result.containsGlobalErrors()) {
-               model.put("errors", result.getGlobalErrors());
-               return new ModelAndView("html-errors", model);
-        }else{
+               //mainly for testing?
+               model.put("idmap", result.getIdMap());
                
-                       // has a new object been created?
-//                     String newObject = result.getNewObjects();
-                       //set the new object in the request (why?)
-//                     if (newObject != null) {
-//                             request.setAttribute("newObject", newObject);
-//                             if (log.isDebugEnabled()) {
-//                                     log.debug("object number " + newObject);
-//                             }
-//                     }
+               List<GlobalError> globalErrors = result.getGlobalErrors();
+               if (result.hasGlobalErrors()) {
+                       model.put("globalerrors", globalErrors);
+                       return new ModelAndView(errorPage, model);
+               } 
+               
+               if (result.hasFieldErrors()) {
+                       model.put("fielderrors", result.getFieldErrors());
+                       // Field errors are not displayed in the error page but 
in the referrer page (the form)
+               }
                        
-                       newPage = request.getHeader("Referer");
-                       //add the node number of the new object to the referer 
url.
+               // has a new object been created?
+               // String newObject = result.getNewObjects();
+               // set the new object in the request (why?)
+               // if (newObject != null) {
+               // request.setAttribute("newObject", newObject);
+               // if (log.isDebugEnabled()) {
+               // log.debug("object number " + newObject);
+               // }
+               // }
+
+               newPage = request.getHeader("Referrer");
+               if(newPage == null){
+                       //this is an error for this view resolver
+                       globalErrors.add(new 
GlobalError("error.no.referrer.header", result.getLocale()));
+                       model.put("globalerrors", globalErrors);
+                       log.error("REFERRER NOT SET! This request's redirection 
wil fail.");
+                       return new ModelAndView(errorPage, model);
+               }
+               // add the node number of the new object to the referer url.
                        if (result.getNewObject().size() > 0) {
                                if (log.isDebugEnabled()) {
                                        log.debug("new object created.");
                                }
 
-//                             if (referer.indexOf('?') == -1) {
-//                                     newPage = referer + "?nodenr=" + 
result.getNewObject();
-//                             } else {
-//                                     newPage = referer + "&nodenr=" + 
result.getNewObject();
-//                             }
+                       // if (referer.indexOf('?') == -1) {
+                       // newPage = referer + "?nodenr=" + 
result.getNewObject();
+                       // } else {
+                       // newPage = referer + "&nodenr=" + 
result.getNewObject();
+                       // }
                                
-                               //if we put the new node in the model, it 
should be added to the query string for redirect views.
+                       // if we put the new node in the model, it should be 
added to the query string for redirect views.
                                model.put("nodenr", 
result.getNewObject().get(0));
                        } 
-               }
         
                return new ModelAndView(new RedirectView(newPage), model);
        }
 
-
        public void setErrorPage(String errorPage) {
                this.errorPage = errorPage;
        }


Index: GlobalError.java
===================================================================
RCS file: 
/var/cvs/speeltuin/ernst/vpro-wizards/src/org/mmbase/applications/vprowizards/spring/GlobalError.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- GlobalError.java    18 Aug 2008 19:13:06 -0000      1.2
+++ GlobalError.java    8 Sep 2008 16:52:10 -0000       1.3
@@ -9,8 +9,8 @@
        
 
        /**
-        * Indien er tijdens het verwerken van de acties een fout optreedt 
worden fielderror gegooit. Deze geven aan welke
-        * velden niet verwerkt konden worden.
+        * This is the type of error that is created when something went wrong, 
and the transaction can not be committed in the end.
+        * A global error is a kind of error that will return an error page, in 
stead of the referrer page.
         * 
         * @author Ernst Bunders
         */
@@ -43,6 +43,10 @@
                return messageKey;
        }
 
+       public String[] getProperties(){
+               return properties;
+       }
+
        /**
         * @return the message as defined in the mesasges resource bundle.
         * @throws RuntimeException when the key was not found in the bundle
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to