Update of /var/cvs/applications/editwizard/src/org/mmbase/applications/editwizard In directory james.mmbase.org:/tmp/cvs-serv31291/src/org/mmbase/applications/editwizard
Modified Files: Tag: MMBase-1_8 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.149.2.3 retrieving revision 1.149.2.4 diff -u -b -r1.149.2.3 -r1.149.2.4 --- Wizard.java 14 Feb 2008 17:16:11 -0000 1.149.2.3 +++ Wizard.java 15 Feb 2008 13:25:35 -0000 1.149.2.4 @@ -45,7 +45,7 @@ * @author Pierre van Rooden * @author Hillebrand Gelderblom * @since MMBase-1.6 - * @version $Id: Wizard.java,v 1.149.2.3 2008/02/14 17:16:11 nklasens Exp $ + * @version $Id: Wizard.java,v 1.149.2.4 2008/02/15 13:25:35 pierre Exp $ * */ public class Wizard implements org.mmbase.util.SizeMeasurable { @@ -883,11 +883,48 @@ // 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))); + long queryTimeOut = 1000 * Long.parseLong(Utils.getAttribute(list, "query-timeout", String.valueOf(this.listQueryTimeOut))); long lastExecuted = currentTime - queryTimeOut - 1; - if (query != null) { String lastExecutedString = Utils.getAttribute(query, "last-executed", "never"); @@ -895,13 +932,13 @@ lastExecuted = Long.parseLong(lastExecutedString); } } - // 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 { @@ -914,12 +951,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. @@ -953,29 +990,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 Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs