Ed,
Doesn't this remove support for "onclick" on commandButton?
JSF developers are definitely using that today.
What happens if there's no CommandLinks on a page? I'd
think that would mean that the commandLink hidden field
wouldn't function, and the commandButton's onclick would
result in a Javascript error.
Also, getHiddenFieldName() was a reasonable name for
a method on CommandLinkRenderer, but is very confusing
as a name on HtmlBasicRenderer.
FWIW, what we (Oracle UIX) did for this category of problem
was to take *all* the "NeededHiddenFields" and explicitly
null them all out in Javascript before continuing with the
code that sets parameters and then submits.
-- Adam
Ed Burns wrote:
> Here's one fix that works. I'm not sure if it's clean though.
>
> Issue: jsf-ri 63
>
> This fix introduces a dependency between ButtonRenderer and
> CommandLinkRenderer. The buttonRenderer now must clear out the hidden
> field value rendered by the commandLink renderer.
>
> M src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java
>
> - use methods newly located to superclass HtmlBasicRenderer to cause
> onclick javascript to be generated that sets the empty string as the
> value of the hidden field used by commandLink entries in this form.
> This is necessary to prevent the value from a previous viewing and
> clicking from being submitted along with the button's value, causing
> *two* ActionEvents to be queued.
>
> M src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java
> M src/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java
>
> - move getMyForm() and getHiddenFieldName() up to HtmlBasicRenderer()
>
> Index: src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java
> ===================================================================
> RCS file:
> /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java,v
> retrieving revision 1.78
> diff -u -r1.78 ButtonRenderer.java
> --- src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java 12 Oct 2004
> 14:39:51 -0000 1.78
> +++ src/com/sun/faces/renderkit/html_basic/ButtonRenderer.java 20 Oct 2004
> 21:56:45 -0000
> @@ -17,6 +17,7 @@
>
> import javax.faces.component.UICommand;
> import javax.faces.component.UIComponent;
> +import javax.faces.component.UIForm;
> import javax.faces.context.FacesContext;
> import javax.faces.context.ResponseWriter;
> import javax.faces.event.ActionEvent;
> @@ -171,7 +172,30 @@
> writer.writeAttribute("value", label, "value");
> }
>
> - Util.renderPassThruAttributes(writer, component);
> + // write out some javascript to overwrite any latent commandLink
> + // script fields.
> + UIForm uiform = getMyForm(context, component);
> + if ( uiform == null ) {
> + if (log.isErrorEnabled()) {
> + log.error("component " + component.getId() +
> + " must be enclosed inside a form ");
> + }
> + return;
> + }
> + String formClientId = uiform.getClientId(context);
> +
> + StringBuffer sb = new StringBuffer();
> + sb.append("document.forms[");
> + sb.append("'");
> + sb.append(formClientId);
> + sb.append("'");
> + sb.append("]['");
> + sb.append(getHiddenFieldName(context, component));
> + sb.append("'].value='';");
> + writer.writeAttribute("onclick", sb.toString(), null);
> +
> + Util.renderPassThruAttributes(writer, component,
> + new String[]{"onclick"});
> Util.renderBooleanPassThruAttributes(writer, component);
>
> if (null != (styleClass = (String)
> Index: src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java
> ===================================================================
> RCS file:
> /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java,v
> retrieving revision 1.23
> diff -u -r1.23 CommandLinkRenderer.java
> --- src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java 12 Oct 2004
> 14:39:52 -0000 1.23
> +++ src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java 20 Oct 2004
> 21:56:46 -0000
> @@ -118,28 +118,6 @@
> return;
> }
>
> -
> - protected UIForm getMyForm(FacesContext context, UICommand command) {
> - UIComponent parent = command.getParent();
> - while (parent != null) {
> - if (parent instanceof UIForm) {
> - break;
> - }
> - parent = parent.getParent();
> - }
> - return (UIForm) parent;
> - }
> -
> - protected String getHiddenFieldName(FacesContext context,
> - UICommand command) {
> - UIForm uiform = getMyForm(context, command);
> - String formClientId = uiform.getClientId(context);
> - return (formClientId + NamingContainer.SEPARATOR_CHAR +
> - UIViewRoot.UNIQUE_ID_PREFIX + "cl");
> - }
> -
> -
> -
> public boolean getRendersChildren() {
> return true;
> }
> Index: src/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java
> ===================================================================
> RCS file:
> /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java,v
> retrieving revision 1.86
> diff -u -r1.86 HtmlBasicRenderer.java
> --- src/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java 12 Oct 2004
> 14:39:52 -0000 1.86
> +++ src/com/sun/faces/renderkit/html_basic/HtmlBasicRenderer.java 20 Oct 2004
> 21:56:46 -0000
> @@ -19,6 +19,7 @@
> import javax.faces.component.NamingContainer;
> import javax.faces.component.UIComponent;
> import javax.faces.component.UIInput;
> +import javax.faces.component.UIForm;
> import javax.faces.component.UIParameter;
> import javax.faces.component.UIViewRoot;
> import javax.faces.component.ValueHolder;
> @@ -561,5 +562,27 @@
> return value;
> }
> }
> +
> + protected UIForm getMyForm(FacesContext context, UIComponent component) {
> + UIComponent parent = component.getParent();
> + while (parent != null) {
> + if (parent instanceof UIForm) {
> + break;
> + }
> + parent = parent.getParent();
> + }
> + return (UIForm) parent;
> + }
> +
> + protected String getHiddenFieldName(FacesContext context,
> + UIComponent component) {
> + UIForm uiform = getMyForm(context, component);
> + String formClientId = uiform.getClientId(context);
> + return (formClientId + NamingContainer.SEPARATOR_CHAR +
> + UIViewRoot.UNIQUE_ID_PREFIX + "cl");
> + }
> +
> +
> +
>
> } // end of class HtmlBasicRenderer
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net