Update of 
/var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard
In directory 
james.mmbase.org:/tmp/cvs-serv31224/src/org/mmbase/applications/editwizard

Modified Files:
        Wizard.java 
Log Message:
also execute a query if a optionlist is included directly in a field


See also: 
http://cvs.mmbase.org/viewcvs/applications/editwizard/src/org/mmbase/applications/editwizard


Index: Wizard.java
===================================================================
RCS file: 
/var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard/Wizard.java,v
retrieving revision 1.159
retrieving revision 1.160
diff -u -b -r1.159 -r1.160
--- Wizard.java 14 Feb 2008 17:16:17 -0000      1.159
+++ Wizard.java 15 Feb 2008 13:24:47 -0000      1.160
@@ -46,7 +46,7 @@
  * @author Pierre van Rooden
  * @author Hillebrand Gelderblom
  * @since MMBase-1.6
- * @version $Id: Wizard.java,v 1.159 2008/02/14 17:16:17 nklasens Exp $
+ * @version $Id: Wizard.java,v 1.160 2008/02/15 13:24:47 pierre Exp $
  *
  */
 public class Wizard implements org.mmbase.util.SizeMeasurable, 
java.io.Serializable {
@@ -897,6 +897,47 @@
 
                 // Test if this list has a query and get the time-out related 
values.
                 Node query = Utils.selectSingleNode(list, "query");
+                if (query != null) {
+                    if (!runQuery(list, query)) continue;
+                }
+
+                // Now copy the items of the list definition to the preHTML 
list.
+                NodeList items = Utils.selectNodeList(list, "option");
+                Utils.appendNodeList(items, optionlist);
+
+            } else {
+                // test if query occurs inline and get the time-out related 
values.
+                Node query = Utils.selectSingleNode(optionlist, "query");
+                if (query != null) {
+                    if (!runQuery(optionlist, query)) continue;
+                }
+            }
+
+            // set selected=true for option which is currently selected
+            String selectedValue = Utils.selectSingleNodeText(optionlist,
+                                                              
"../value/text()", ""); //.getNodeValue();
+            log.debug("Trying to preselect the list at value: " + 
selectedValue);
+
+            Node selectedoption = Utils.selectSingleNode(optionlist,
+                                                         "[EMAIL PROTECTED]'" 
+ selectedValue + "']");
+
+            if (selectedoption != null) {
+                // found! Let's set it selected.
+                Utils.setAttribute(selectedoption, "selected", "true");
+            }
+        }
+
+        // Okee, we are ready. Let's return what we've been working on so hard.
+        return preHtml;
+    }
+
+    /**
+     * This method tests if a query in a nodelist needs to be run, and runs it 
if needed, adding the resulting options to the optionlist.
+     *
+     * @param list    the node of the optionlist in which the query is defined
+     * @param query    the node of the query definition
+     */
+    boolean runQuery(Node list, Node query) {
                 long currentTime = new Date().getTime();
                 long queryTimeOut = 1000 * 
Long.parseLong(Utils.getAttribute(list,
                                                                              
"query-timeout", String.valueOf(this.listQueryTimeOut)));
@@ -912,10 +953,11 @@
 
                 // Execute the query if it's there and only if it has timed 
out.
                 if ((query != null) && ((currentTime - lastExecuted) > 
queryTimeOut)) {
-                    log.debug("Performing query for optionlist '" + listname +
+            if (log.isDebugEnabled()) {
+              log.debug("Performing query for optionlist '" + 
Utils.getAttribute(list, "select") +
                               "'. Cur time " + currentTime + " last executed " 
+ lastExecuted +
                               " timeout " + queryTimeOut + " > " + 
(currentTime - lastExecuted));
-
+            }
                     Node queryresult = null;
 
                     try {
@@ -928,12 +970,12 @@
                         // Bad luck, tell the user and try the next list.
                         log.debug("Error during query, proceeding with next 
list: " + e.toString());
 
-                        Element option = 
optionlist.getOwnerDocument().createElement("option");
+                Element option = 
list.getOwnerDocument().createElement("option");
                         option.setAttribute("id", "-");
-                        Utils.storeText(option, "Error: query for '" + 
listname + "' failed");
-                        optionlist.appendChild(option);
+                Utils.storeText(option, "Error: query for '" + 
Utils.getAttribute(list, "select") + "' failed");
+                list.appendChild(option);
 
-                        continue;
+                return false;
                     }
 
                     // Remind the current time.
@@ -967,29 +1009,7 @@
                         list.appendChild(option);
                     }
                 }
-
-                // Now copy the items of the list definition to the preHTML 
list.
-                NodeList items = Utils.selectNodeList(list, "option");
-                Utils.appendNodeList(items, optionlist);
-
-            }
-
-            // set selected=true for option which is currently selected
-            String selectedValue = Utils.selectSingleNodeText(optionlist,
-                                                              
"../value/text()", ""); //.getNodeValue();
-            log.debug("Trying to preselect the list at value: " + 
selectedValue);
-
-            Node selectedoption = Utils.selectSingleNode(optionlist,
-                                                         "[EMAIL PROTECTED]'" 
+ selectedValue + "']");
-
-            if (selectedoption != null) {
-                // found! Let's set it selected.
-                Utils.setAttribute(selectedoption, "selected", "true");
-            }
-        }
-
-        // Okee, we are ready. Let's return what we've been working on so hard.
-        return preHtml;
+        return true;
     }
 
     /**
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs

Reply via email to