Uploaded image for project: 'MyFaces Core'
  1. MyFaces Core
  2. MYFACES-2726

CommandLink renderer do not escape \ characters in generated javascript

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.7
    • 1.1.8, 1.2.9, 2.0.1
    • General
    • None
    • Websphere 7

    Description

      The link is declared by

      <h:commandLink id="select" action="#

      {locationListManagedBean.associate}

      " styleClass="detailLink" title="#

      {messages['associate']}

      ">
      <t:div />
      <f:param name="locationSelectedBean" value="#

      {location.bean}

      " />
      </h:commandLink>

      The associated generated HTML code is valid but the \ character is not escaped :

      <a href="#"
      onclick="return oamSubmitForm('xnetForm','xnetForm:_idJsp30:tablelocation:2:select',null,[['locationSelectedBean','com.michelin.wrh.bo.LocationBean CAR/T1[]5%Car\m+es|']]);"
      id="xnetForm:_idJsp30:tablelocation:2:select" title="Associer" class="detailLink">
      <div></div>
      </a>

      The associated javascript method does not manage special characters !

      The locationSelectedBean param retrieved from
      context.getExternalContext().getRequestParameterMap().get("locationSelectedBean");
      has lost the "\" character

      We can fix the issue by overwritting the org.apache.myfaces.shared_impl.renderkit.html.HtmlLinkRendererBase class and modify the following method :

      private StringBuffer addChildParameters(UIComponent component, UIComponent nestingForm)
      {
      StringBuffer params = new StringBuffer();
      params.append("[");
      Iterator it = getChildren(component).iterator();
      do
      {
      if(!it.hasNext())
      break;
      UIComponent child = (UIComponent)it.next();
      if(child instanceof UIParameter)

      { String name = ((UIParameter)child).getName(); if(name == null) throw new IllegalArgumentException("Unnamed parameter value not allowed within command link."); addHiddenCommandParameter(FacesContext.getCurrentInstance(), nestingForm, name); Object value = ((UIParameter)child).getValue(); //FIX // We need to escape \ characters in generated javascript code // String strParamValue = value == null ? "" : value.toString(); String strParamValue = value == null ? "" : value.toString().replace("\\", "\\\\"); //ENDFIX if(params.length() > 1) params.append(","); params.append("['"); params.append(name); params.append("','"); params.append(strParamValue); params.append("']"); }

      } while(true);
      params.append("]");
      return params;
      }

      Attachments

        Issue Links

          Activity

            People

              lu4242 Leonardo Uribe
              rseguy Romain Seguy
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: