Re: [REVIEW] Update Link renderer to write component value when disabled
Ryan Lubke wrote:
> If commandLink is marked as disabled, render the value of the
> component as the
> text of the span.
>
>
> SECTION: Modified Files
> ----------------------------
> M jsf-ri/src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java
> - add new method 'writeValue' which write the component value.
> Called in
> both the enabled and disabled cases
> - minor cleanup tweaks.
>
>
> SECTION: Diffs
> ----------------------------
> Index: CommandLinkRenderer.java
> ===================================================================
> RCS file:
> /cvs/javaserverfaces-sources/jsf-ri/src/com/sun/faces/renderkit/html_basic/CommandLinkRenderer.java,v
>
> retrieving revision 1.37
> diff -u -r1.37 CommandLinkRenderer.java
> --- CommandLinkRenderer.java 14 Sep 2005 21:27:17 -0000 1.37
> +++ CommandLinkRenderer.java 10 Oct 2005 15:15:41 -0000
> @@ -32,7 +32,6 @@
> package com.sun.faces.renderkit.html_basic;
>
> import java.io.IOException;
> -import java.util.Iterator;
> import java.util.Map;
> import java.util.ArrayList;
>
> @@ -138,8 +137,7 @@
> if (logger.isLoggable(Level.FINER)) {
> logger.log(Level.FINER,
> "End decoding component " + component.getId());
> - }
> - return;
> + } }
>
> public boolean getRendersChildren() {
> @@ -206,9 +204,7 @@
> }
> return;
> }
> - Iterator<UIComponent> kids = component.getChildren().iterator();
> - while (kids.hasNext()) {
> - UIComponent kid = kids.next();
> + for (UIComponent kid : component.getChildren()) {
> kid.encodeBegin(context);
> if (kid.getRendersChildren()) {
> kid.encodeChildren(context);
> @@ -271,7 +267,7 @@
>
>
> renderHiddenFieldsAndScriptIfNecessary(context, writer,
> component, fieldName);
>
>
> - UIForm uiform = getMyForm(context, command);
> + UIForm uiform = getMyForm(command);
> if ( uiform == null ) {
> if (logger.isLoggable(Level.WARNING)) {
> logger.warning("component " + component.getId() +
> @@ -283,9 +279,7 @@
> if (logger.isLoggable(Level.FINER)) {
> logger.log(Level.FINER,
> "End encoding component " + component.getId());
> - }
> -
>
> - return;
> + } }
>
> private void renderAsActive(FacesContext context, UICommand command)
> @@ -296,7 +290,7 @@
>
> String clientId = command.getClientId(context);
>
> - UIForm uiform = getMyForm(context, command);
> + UIForm uiform = getMyForm(command);
> if ( uiform == null ) {
> if (logger.isLoggable(Level.WARNING)) {
> logger.warning("component " + command.getId() +
> @@ -336,14 +330,16 @@
> // call the javascript function that clears the all the
> hidden field
> // parameters in the form.
> - sb.append(CLEAR_HIDDEN_FIELD_FN_NAME + "_" +
> formClientId.replace(NamingContainer.SEPARATOR_CHAR, '_'));
> + sb.append(CLEAR_HIDDEN_FIELD_FN_NAME);
> + sb.append('_');
> +
> sb.append(formClientId.replace(NamingContainer.SEPARATOR_CHAR, '_'));
> sb.append("('");
> sb.append(formClientId);
> sb.append("');");
> sb.append("document.forms[");
> - sb.append("'");
> + sb.append('\'');
> sb.append(formClientId);
> - sb.append("'");
> + sb.append('\'');
> sb.append("]['");
> sb.append(getHiddenFieldName(context, command));
> sb.append("'].value='");
> @@ -351,9 +347,9 @@
> sb.append("';");
> for (int i = 0, len = paramList.length; i < len; i++) {
> sb.append("document.forms[");
> - sb.append("'");
> + sb.append('\'');
> sb.append(formClientId);
> - sb.append("'");
> + sb.append('\'');
> sb.append("]['");
> sb.append(paramList[i].getName());
> sb.append("'].value='");
> @@ -367,17 +363,17 @@
> String target = (String) command.getAttributes().get("target");
> if (target != null && target.trim().length() > 0) {
> sb.append(" document.forms[");
> - sb.append("'");
> + sb.append('\'');
> sb.append(formClientId);
> - sb.append("'");
> + sb.append('\'');
> sb.append("].target='");
> sb.append(target);
> sb.append("';");
> }
> sb.append(" document.forms[");
> - sb.append("'");
> + sb.append('\'');
> sb.append(formClientId);
> - sb.append("'");
> + sb.append('\'');
> sb.append("].submit()");
>
> sb.append("; return false;");
> @@ -397,17 +393,7 @@
> }
> // render the current value as link text.
> - String label = null;
> - Object value = ((UICommand) command).getValue();
> - if (value != null) {
> - label = value.toString();
> - }
> - if (logger.isLoggable(Level.FINE)) {
> - logger.fine("Value to be rendered " + value);
> - }
> - if (label != null && label.length() != 0) {
> - writer.write(label);
> - }
> + writeValue(command, writer);
> writer.flush();
>
> }
> @@ -441,14 +427,32 @@
> if (styleClass != null) {
> writer.writeAttribute("class", styleClass, "styleClass");
> }
> +
> + // render the current value as span text.
> + writeValue(command, writer);
> writer.flush();
> }
>
> + private void writeValue(UICommand command, ResponseWriter writer)
> + throws IOException {
> + String label = null;
> + Object value = command.getValue();
> + if (value != null) {
> + label = value.toString();
> + }
> + if (logger.isLoggable(Level.FINE)) {
> + logger.fine("Value to be rendered " + value);
> + }
> + if (label != null && label.length() != 0) {
> + writer.write(label);
> + }
> + }
> +
> private void writeScriptContent(FacesContext context,
> ResponseWriter writer,
> UIComponent component) throws IOException {
> Map<String,Object> requestMap =
> context.getExternalContext().getRequestMap();
> - UIForm myForm = getMyForm(context, component);
> + UIForm myForm = getMyForm(component);
> boolean isXHTML =
> requestMap.containsKey(RIConstants.CONTENT_TYPE_IS_XHTML);
>
> @@ -510,7 +514,7 @@
> * with that name, or there is one, but it's a different name then
> * "our" hidden field name, render the hidden field.</p>
> */
> -
> + private void
> renderHiddenFieldsAndScriptIfNecessary(FacesContext context,
> ResponseWriter writer,
> UIComponent component,
> @@ -522,11 +526,10 @@
> return;
> }
> String keyName = RIConstants.FACES_PREFIX + fieldName;
> - Object keyVal = null;
> + Object keyVal;
> // if the hidden field for this form hasn't yet been rendered
> if ((null == (keyVal = requestMap.get(keyName)))
> - ||
> - (null != keyVal && !keyVal.equals(keyName))) {
> + || (!keyVal.equals(keyName))) {
> writer.startElement("input", component);
> writer.writeAttribute("type", "hidden", null);
> @@ -541,26 +544,28 @@
> // get UIParameter children...
> Param paramList[] = getParamList(context, component);
> if (paramList != null && paramList.length > 0) {
> - renderedFields =
> (ArrayList)requestMap.get(RENDERED_HIDDEN_FIELDS);
> + renderedFields =
> (ArrayList<String>)requestMap.get(RENDERED_HIDDEN_FIELDS);
> if (renderedFields == null) {
> - renderedFields = new ArrayList();
> + renderedFields = new ArrayList<String>();
> }
> - }
> - // render any hidden fields that haven't been already for
> this form.
> - // Hidden fields should be rendered only once per form.
> - for (int i = 0; i < paramList.length; i++) {
> - fieldName = paramList[i].getName();
> - keyName = RIConstants.FACES_PREFIX + fieldName;
> - int keyLocation = renderedFields.indexOf(keyName);
> - - if (keyLocation == -1) {
> - writer.startElement("input", component);
> - writer.writeAttribute("type", "hidden", null);
> - writer.writeAttribute("name", fieldName, null);
> - writer.endElement("input");
> - renderedFields.add(keyName);
> +
> + // render any hidden fields that haven't been already for
> this form.
> + // Hidden fields should be rendered only once per form.
> + for (int i = 0; i < paramList.length; i++) {
> + fieldName = paramList[i].getName();
> + keyName = RIConstants.FACES_PREFIX + fieldName;
> + int keyLocation = renderedFields.indexOf(keyName);
> +
> + if (keyLocation == -1) {
> + writer.startElement("input", component);
> + writer.writeAttribute("type", "hidden", null);
> + writer.writeAttribute("name", fieldName, null);
> + writer.endElement("input");
> + renderedFields.add(keyName);
> + }
> }
> }
> + requestMap.put(RENDERED_HIDDEN_FIELDS, renderedFields);
> writeScriptContent(context, writer, component);
> }
> @@ -568,7 +573,7 @@
> private String getHiddenFieldName(FacesContext context,
> UIComponent component) {
> - UIForm uiform = getMyForm(context, component);
> + UIForm uiform = getMyForm(component);
> if (null == uiform) {
> return null;
> }
> @@ -577,7 +582,7 @@
> UIViewRoot.UNIQUE_ID_PREFIX + "cl");
> }
> - private UIForm getMyForm(FacesContext context, UIComponent
> component) {
> + private UIForm getMyForm(UIComponent component) {
> UIComponent parent = component.getParent();
> while (parent != null) {
> if (parent instanceof UIForm) {
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe_at_javaserverfaces.dev.java.net
> For additional commands, e-mail: dev-help_at_javaserverfaces.dev.java.net
>
r=rogerk