From: <mal...@us...> - 2008-11-11 16:10:42
|
Revision: 4183 http://j-wings.svn.sourceforge.net/j-wings/?rev=4183&view=rev Author: maldfeld Date: 2008-11-11 16:10:36 +0000 (Tue, 11 Nov 2008) Log Message: ----------- default button handling optimized Modified Paths: -------------- wings3/trunk/wings/src/java/org/wings/SForm.java wings3/trunk/wings/src/java/org/wings/plaf/FormCG.java wings3/trunk/wings/src/java/org/wings/plaf/css/FormCG.java wings3/trunk/wings/src/res/org/wings/js/wings/modules/global.js wings3/trunk/wings/src/res/org/wings/js/wings/modules/update.js wings3/trunk/wings-integration/src/java/org/wings/plaf/css/TemplateIntegrationFormCG.java Modified: wings3/trunk/wings/src/java/org/wings/SForm.java =================================================================== --- wings3/trunk/wings/src/java/org/wings/SForm.java 2008-11-10 10:20:25 UTC (rev 4182) +++ wings3/trunk/wings/src/java/org/wings/SForm.java 2008-11-11 16:10:36 UTC (rev 4183) @@ -140,10 +140,13 @@ * If <code>null</code> enter key pressed will be catched by the wings framework. */ public void setDefaultButton(SButton defaultButton) { - SButton oldVal = this.defaultButton; - reloadIfChange(this.defaultButton, defaultButton); + SButton oldButton = this.defaultButton; + String oldName = oldButton != null ? oldButton.getName() : null; + String newName = defaultButton != null ? defaultButton.getName() : null; + if (isDifferent(oldName, newName)) + update(getCG().getDefaultButtonNameUpdate(this, newName)); this.defaultButton = defaultButton; - propertyChangeSupport.firePropertyChange("defaultButton", oldVal, this.defaultButton); + propertyChangeSupport.firePropertyChange("defaultButton", oldButton, this.defaultButton); } /** Modified: wings3/trunk/wings/src/java/org/wings/plaf/FormCG.java =================================================================== --- wings3/trunk/wings/src/java/org/wings/plaf/FormCG.java 2008-11-10 10:20:25 UTC (rev 4182) +++ wings3/trunk/wings/src/java/org/wings/plaf/FormCG.java 2008-11-11 16:10:36 UTC (rev 4183) @@ -21,6 +21,8 @@ Update getEncodingUpdate(SForm form, String encoding); Update getMethodUpdate(SForm form, String postMethod); + + Update getDefaultButtonNameUpdate(SForm form, String postMethod); } Modified: wings3/trunk/wings/src/java/org/wings/plaf/css/FormCG.java =================================================================== --- wings3/trunk/wings/src/java/org/wings/plaf/css/FormCG.java 2008-11-10 10:20:25 UTC (rev 4182) +++ wings3/trunk/wings/src/java/org/wings/plaf/css/FormCG.java 2008-11-11 16:10:36 UTC (rev 4183) @@ -14,8 +14,10 @@ import org.wings.*; +import org.wings.session.ScriptManager; import org.wings.io.Device; import org.wings.plaf.css.script.LayoutFillScript; +import org.wings.plaf.css.script.OnPageRenderedScript; import org.wings.plaf.Update; import java.io.IOException; @@ -32,6 +34,15 @@ boolean formTagRequired = !form.getResidesInForm(); if (formTagRequired) { + // Is there a default button? + String defaultButtonName = "undefined"; + if (form.getDefaultButton() != null) { + defaultButtonName = Utils.event(form.getDefaultButton()); + } + StringBuilder script = new StringBuilder(); + script.append("wingS.update.defaultButtonName('").append(defaultButtonName).append("');"); + ScriptManager.getInstance().addScriptListener(new OnPageRenderedScript(script.toString())); + device.print("<form method=\""); if (form.isPostMethod()) { device.print("post"); @@ -45,12 +56,6 @@ Utils.optAttribute(device, "action", form.getRequestURL()); Utils.writeEvents(device, form, null); - // Is there a default button? - String defaultButtonName = "undefined"; - if (form.getDefaultButton() != null) { - defaultButtonName = Utils.event(form.getDefaultButton()); - } - // The "onsubmit"-handler of the form gets triggered // ONLY if the user submits it by pressing <enter> in // any of its fields. In all other cases - i.e. if a @@ -68,9 +73,7 @@ device.print("event,"); device.print("true,"); device.print(!component.isReloadForced()); - device.print(",'default_button','"); - device.print(defaultButtonName); - device.print("'); return false;\">"); + device.print(",'default_button', wingS.global.defaultButtonName); return false;\">"); writeCapture(device, form); @@ -153,6 +156,10 @@ return new MethodUpdate(form, method != null ? method : ""); } + public Update getDefaultButtonNameUpdate(SForm form, String defaultButtonName) { + return new DefaultButtonNameUpdate(form, defaultButtonName != null ? defaultButtonName : "undefined"); + } + protected class EncodingUpdate extends AbstractUpdate { private String encoding; @@ -187,4 +194,21 @@ return handler; } } + + protected class DefaultButtonNameUpdate + extends AbstractUpdate { + + private String defaultButtonName; + + public DefaultButtonNameUpdate(SComponent component, String defaultButtonName) { + super(component); + this.defaultButtonName = defaultButtonName; + } + + public Handler getHandler() { + UpdateHandler handler = new UpdateHandler("defaultButtonName"); + handler.addParameter(defaultButtonName); + return handler; + } + } } Modified: wings3/trunk/wings/src/res/org/wings/js/wings/modules/global.js =================================================================== --- wings3/trunk/wings/src/res/org/wings/js/wings/modules/global.js 2008-11-10 10:20:25 UTC (rev 4182) +++ wings3/trunk/wings/src/res/org/wings/js/wings/modules/global.js 2008-11-11 16:10:36 UTC (rev 4183) @@ -30,6 +30,7 @@ */ wingS.global.init = function(configObject) { // Initialize -wingS.global- + wingS.global.defaultButtonName = 'undefined'; wingS.global.eventEpoch = configObject.eventEpoch; wingS.global.reloadResource = configObject.reloadResource; wingS.global.updateResource = configObject.updateResource; Modified: wings3/trunk/wings/src/res/org/wings/js/wings/modules/update.js =================================================================== --- wings3/trunk/wings/src/res/org/wings/js/wings/modules/update.js 2008-11-10 10:20:25 UTC (rev 4182) +++ wings3/trunk/wings/src/res/org/wings/js/wings/modules/update.js 2008-11-11 16:10:36 UTC (rev 4183) @@ -562,3 +562,11 @@ wingS.update.runScript = function(scriptToEval) { eval(scriptToEval); }; + +/** + * Updates the current default button name of this frame. + * @param {String} defaultButtonName - the current default button name + */ +wingS.update.defaultButtonName = function(defaultButtonName) { + wingS.global.defaultButtonName = defaultButtonName; +}; Modified: wings3/trunk/wings-integration/src/java/org/wings/plaf/css/TemplateIntegrationFormCG.java =================================================================== --- wings3/trunk/wings-integration/src/java/org/wings/plaf/css/TemplateIntegrationFormCG.java 2008-11-10 10:20:25 UTC (rev 4182) +++ wings3/trunk/wings-integration/src/java/org/wings/plaf/css/TemplateIntegrationFormCG.java 2008-11-11 16:10:36 UTC (rev 4183) @@ -9,8 +9,10 @@ import org.wings.SForm; import org.wings.SGridBagLayout; import org.wings.SLayoutManager; +import org.wings.session.ScriptManager; import org.wings.io.Device; import org.wings.plaf.css.script.LayoutFillScript; +import org.wings.plaf.css.script.OnPageRenderedScript; /** * <code>TemplateIntegrationFormCG<code>. @@ -35,6 +37,15 @@ boolean formTagRequired = !form.getResidesInForm(); if (formTagRequired) { + // Is there a default button? + String defaultButtonName = "undefined"; + if (form.getDefaultButton() != null) { + defaultButtonName = Utils.event(form.getDefaultButton()); + } + StringBuilder script = new StringBuilder(); + script.append("wingS.update.defaultButtonName('").append(defaultButtonName).append("');"); + ScriptManager.getInstance().addScriptListener(new OnPageRenderedScript(script.toString())); + device.print("<form method=\""); if (form.isPostMethod()) { device.print("post"); @@ -48,12 +59,6 @@ Utils.optAttribute(device, "action", form.getRequestURL()); Utils.writeEvents(device, form, null); - // Is there a default button? - String defaultButtonName = "undefined"; - if (form.getDefaultButton() != null) { - defaultButtonName = Utils.event(form.getDefaultButton()); - } - // The "onsubmit"-handler of the form gets triggered // ONLY if the user submits it by pressing <enter> in // any of its fields. In all other cases - i.e. if a @@ -71,9 +76,7 @@ device.print("event,"); device.print("true,"); device.print(!component.isReloadForced()); - device.print(",'default_button','"); - device.print(defaultButtonName); - device.print("'); return false;\">"); + device.print(",'default_button', wingS.global.defaultButtonName); return false;\">"); writeCapture(device, form); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |