Coverage Report - org.apache.myfaces.shared.renderkit.html.HtmlLinkRendererBase
 
Classes in this File Line Coverage Branch Coverage Complexity
HtmlLinkRendererBase
0%
0/454
0%
0/290
7.478
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 18  
  */
 19  
 package org.apache.myfaces.shared.renderkit.html;
 20  
 
 21  
 import java.io.IOException;
 22  
 import java.io.UnsupportedEncodingException;
 23  
 import java.net.URLEncoder;
 24  
 import java.util.Collection;
 25  
 import java.util.Collections;
 26  
 import java.util.List;
 27  
 import java.util.Map;
 28  
 import java.util.RandomAccess;
 29  
 
 30  
 import javax.faces.component.UICommand;
 31  
 import javax.faces.component.UIComponent;
 32  
 import javax.faces.component.UIOutcomeTarget;
 33  
 import javax.faces.component.UIOutput;
 34  
 import javax.faces.component.UIParameter;
 35  
 import javax.faces.component.behavior.ClientBehavior;
 36  
 import javax.faces.component.behavior.ClientBehaviorContext;
 37  
 import javax.faces.component.behavior.ClientBehaviorHint;
 38  
 import javax.faces.component.behavior.ClientBehaviorHolder;
 39  
 import javax.faces.component.html.HtmlCommandLink;
 40  
 import javax.faces.component.html.HtmlOutputLink;
 41  
 import javax.faces.context.FacesContext;
 42  
 import javax.faces.context.ResponseWriter;
 43  
 import javax.faces.event.ActionEvent;
 44  
 
 45  
 import org.apache.myfaces.shared.config.MyfacesConfig;
 46  
 import org.apache.myfaces.shared.renderkit.ClientBehaviorEvents;
 47  
 import org.apache.myfaces.shared.renderkit.JSFAttr;
 48  
 import org.apache.myfaces.shared.renderkit.RendererUtils;
 49  
 import org.apache.myfaces.shared.renderkit.html.util.FormInfo;
 50  
 import org.apache.myfaces.shared.renderkit.html.util.ResourceUtils;
 51  
 import org.apache.myfaces.shared.util._ComponentUtils;
 52  
 
 53  0
 public abstract class HtmlLinkRendererBase
 54  
     extends HtmlRenderer
 55  
 {
 56  
     /* this one is never used
 57  
     public static final String URL_STATE_MARKER      = "JSF_URL_STATE_MARKER=DUMMY";
 58  
     public static final int    URL_STATE_MARKER_LEN  = URL_STATE_MARKER.length();
 59  
     */
 60  
 
 61  
     //private static final Log log = LogFactory.getLog(HtmlLinkRenderer.class);
 62  
     
 63  
     public static final String END_LINK_OUTCOME_AS_SPAN = 
 64  
         "oam.shared.HtmlLinkRendererBase.END_LINK_OUTCOME_AS_SPAN";
 65  
 
 66  
     public boolean getRendersChildren()
 67  
     {
 68  
         // We must be able to render the children without a surrounding anchor
 69  
         // if the Link is disabled
 70  0
         return true;
 71  
     }
 72  
 
 73  
     public void decode(FacesContext facesContext, UIComponent component)
 74  
     {
 75  0
         super.decode(facesContext, component);  //check for NP
 76  
 
 77  0
         if (component instanceof UICommand)
 78  
         {
 79  0
             String clientId = component.getClientId(facesContext);
 80  0
             FormInfo formInfo = findNestingForm(component, facesContext);
 81  0
             boolean disabled = HtmlRendererUtils.isDisabled(component);
 82  
             // MYFACES-3960 Decode, decode client behavior and queue action event at the end
 83  0
             boolean activateActionEvent = false;
 84  0
             if (formInfo != null && !disabled)
 85  
             {
 86  0
                 String reqValue = (String) facesContext.getExternalContext().getRequestParameterMap().get(
 87  
                         HtmlRendererUtils.getHiddenCommandLinkFieldName(formInfo, facesContext));
 88  0
                 activateActionEvent = reqValue != null && reqValue.equals(clientId)
 89  
                     || HtmlRendererUtils.isPartialOrBehaviorSubmit(facesContext, clientId);
 90  0
                 if (activateActionEvent)
 91  
                 {
 92  0
                     RendererUtils.initPartialValidationAndModelUpdate(component, facesContext);
 93  
                 }
 94  
             }
 95  0
             if (component instanceof ClientBehaviorHolder &&
 96  
                     !disabled)
 97  
             {
 98  0
                 HtmlRendererUtils.decodeClientBehaviors(facesContext, component);
 99  
             }
 100  0
             if (activateActionEvent)
 101  
             {
 102  0
                 component.queueEvent(new ActionEvent(component));
 103  
             }
 104  0
         }
 105  0
         else if (component instanceof UIOutput)
 106  
         {
 107  
             //do nothing
 108  0
             if (component instanceof ClientBehaviorHolder &&
 109  
                     !HtmlRendererUtils.isDisabled(component))
 110  
             {
 111  0
                 HtmlRendererUtils.decodeClientBehaviors(facesContext, component);
 112  
             }
 113  
         }
 114  
         else
 115  
         {
 116  0
             throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
 117  
         }
 118  0
     }
 119  
 
 120  
 
 121  
     public void encodeBegin(FacesContext facesContext, UIComponent component) throws IOException
 122  
     {
 123  0
         super.encodeBegin(facesContext, component);  //check for NP
 124  
 
 125  0
         Map<String, List<ClientBehavior>> behaviors = null;
 126  0
         if (component instanceof ClientBehaviorHolder)
 127  
         {
 128  0
             behaviors = ((ClientBehaviorHolder) component).getClientBehaviors();
 129  0
             if (!behaviors.isEmpty())
 130  
             {
 131  0
                 ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, facesContext.getResponseWriter());
 132  
             }
 133  
         }
 134  
         
 135  0
         if (component instanceof UICommand)
 136  
         {
 137  0
             renderCommandLinkStart(facesContext, component,
 138  
                                    component.getClientId(facesContext),
 139  
                                    ((UICommand)component).getValue(),
 140  
                                    getStyle(facesContext, component),
 141  
                                    getStyleClass(facesContext, component));
 142  
         }
 143  0
         else if (component instanceof UIOutcomeTarget)
 144  
         {
 145  0
             renderOutcomeLinkStart(facesContext, (UIOutcomeTarget)component);
 146  
         }        
 147  0
         else if (component instanceof UIOutput)
 148  
         {
 149  0
             renderOutputLinkStart(facesContext, (UIOutput)component);
 150  
         }
 151  
         else
 152  
         {
 153  0
             throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
 154  
         }
 155  0
     }
 156  
 
 157  
 
 158  
     /**
 159  
      * Can be overwritten by derived classes to overrule the style to be used.
 160  
      */
 161  
     protected String getStyle(FacesContext facesContext, UIComponent link)
 162  
     {
 163  0
         if (link instanceof HtmlCommandLink)
 164  
         {
 165  0
             return ((HtmlCommandLink)link).getStyle();
 166  
         }
 167  
 
 168  0
         return (String)link.getAttributes().get(HTML.STYLE_ATTR);
 169  
 
 170  
     }
 171  
 
 172  
     /**
 173  
      * Can be overwritten by derived classes to overrule the style class to be used.
 174  
      */
 175  
     protected String getStyleClass(FacesContext facesContext, UIComponent link)
 176  
     {
 177  0
         if (link instanceof HtmlCommandLink)
 178  
         {
 179  0
             return ((HtmlCommandLink)link).getStyleClass();
 180  
         }
 181  
 
 182  0
         return (String)link.getAttributes().get(HTML.STYLE_CLASS_ATTR);
 183  
 
 184  
     }
 185  
 
 186  
     public void encodeChildren(FacesContext facesContext, UIComponent component) throws IOException
 187  
     {
 188  0
         RendererUtils.renderChildren(facesContext, component);
 189  0
     }
 190  
 
 191  
     public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException
 192  
     {
 193  0
         super.encodeEnd(facesContext, component);  //check for NP
 194  
 
 195  0
         if (component instanceof UICommand)
 196  
         {
 197  0
             renderCommandLinkEnd(facesContext, component);
 198  
 
 199  0
             FormInfo formInfo = findNestingForm(component, facesContext);
 200  
             
 201  0
             if (formInfo != null)
 202  
             {
 203  0
                 HtmlFormRendererBase.renderScrollHiddenInputIfNecessary(
 204  
                         formInfo.getForm(), facesContext, facesContext.getResponseWriter());
 205  
             }
 206  0
         }
 207  0
         else if (component instanceof UIOutcomeTarget)
 208  
         {
 209  0
             renderOutcomeLinkEnd(facesContext, component);
 210  
         }
 211  0
         else if (component instanceof UIOutput)
 212  
         {
 213  0
             renderOutputLinkEnd(facesContext, component);
 214  
         }
 215  
         else
 216  
         {
 217  0
             throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
 218  
         }
 219  0
     }
 220  
 
 221  
     protected void renderCommandLinkStart(FacesContext facesContext, UIComponent component,
 222  
                                           String clientId,
 223  
                                           Object value,
 224  
                                           String style,
 225  
                                           String styleClass)
 226  
             throws IOException
 227  
     {
 228  0
         ResponseWriter writer = facesContext.getResponseWriter();
 229  0
         Map<String, List<ClientBehavior>> behaviors = null;
 230  
 
 231  
         // h:commandLink can be rendered outside a form, but with warning (jsf 2.0 TCK)
 232  0
         FormInfo formInfo = findNestingForm(component, facesContext);
 233  
         
 234  0
         boolean disabled = HtmlRendererUtils.isDisabled(component);
 235  
         
 236  0
         if (disabled || formInfo == null)
 237  
         {
 238  0
             writer.startElement(HTML.SPAN_ELEM, component);
 239  0
             if (component instanceof ClientBehaviorHolder)
 240  
             {
 241  0
                 behaviors = ((ClientBehaviorHolder) component).getClientBehaviors();
 242  0
                 if (!behaviors.isEmpty())
 243  
                 {
 244  0
                     HtmlRendererUtils.writeIdAndName(writer, component, facesContext);
 245  
                 }
 246  
                 else
 247  
                 {
 248  0
                     HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
 249  
                 }
 250  0
                 long commonPropertiesMarked = 0L;
 251  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 252  
                 {
 253  0
                     commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(component);
 254  
                 }
 255  
                 
 256  
                 // only render onclick if != disabled
 257  0
                 if (!disabled)
 258  
                 {
 259  0
                     if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 260  
                     {
 261  0
                         CommonPropertyUtils.renderEventProperties(writer, 
 262  
                                 commonPropertiesMarked, component);
 263  0
                         CommonPropertyUtils.renderFocusBlurEventProperties(writer,
 264  
                                 commonPropertiesMarked, component);
 265  
                     }
 266  
                     else
 267  
                     {
 268  0
                         if (isCommonEventsOptimizationEnabled(facesContext))
 269  
                         {
 270  0
                             Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(component);
 271  0
                             CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
 272  
                                     commonPropertiesMarked, commonEventsMarked, component, behaviors);
 273  0
                             CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 274  
                                 facesContext, writer, commonPropertiesMarked, commonEventsMarked, component, behaviors);
 275  0
                         }
 276  
                         else
 277  
                         {
 278  0
                             HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, component, 
 279  
                                     behaviors);
 280  0
                             HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 281  
                                     facesContext, writer, component, behaviors);
 282  
                         }
 283  
                     }
 284  
                 }
 285  
                 else
 286  
                 {
 287  0
                     if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 288  
                     {
 289  0
                         CommonPropertyUtils.renderEventPropertiesWithoutOnclick(writer, 
 290  
                                 commonPropertiesMarked, component);
 291  0
                         CommonPropertyUtils.renderFocusBlurEventProperties(writer,
 292  
                                 commonPropertiesMarked, component);
 293  
                     }
 294  
                     else
 295  
                     {
 296  0
                         if (isCommonEventsOptimizationEnabled(facesContext))
 297  
                         {
 298  0
                             Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(component);
 299  0
                             CommonEventUtils.renderBehaviorizedEventHandlersWithoutOnclick(facesContext, writer, 
 300  
                                     commonPropertiesMarked, commonEventsMarked, component, behaviors);
 301  0
                             CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 302  
                                 facesContext, writer, commonPropertiesMarked, commonEventsMarked, component, behaviors);
 303  0
                         }
 304  
                         else
 305  
                         {
 306  0
                             HtmlRendererUtils.renderBehaviorizedEventHandlersWithoutOnclick(facesContext, writer,
 307  
                                     component, behaviors);
 308  0
                             HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 309  
                                     facesContext, writer, component, behaviors);
 310  
                         }
 311  
                     }
 312  
                 }
 313  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 314  
                 {
 315  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesDisabledWithoutEvents(writer, 
 316  
                             commonPropertiesMarked, component);
 317  
                 }
 318  
                 else
 319  
                 {
 320  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, component, 
 321  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_DISABLED_WITHOUT_EVENTS);
 322  
                 }
 323  0
             }
 324  
             else
 325  
             {
 326  0
                 HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
 327  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 328  
                 {
 329  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesDisabled(writer, 
 330  
                             CommonPropertyUtils.getCommonPropertiesMarked(component), component);
 331  
                 }
 332  
                 else
 333  
                 {
 334  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, component, 
 335  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_DISABLED);
 336  
                 }
 337  
             }
 338  
         }
 339  
         else
 340  
         {
 341  
             //String[] anchorAttrsToRender;
 342  0
             if (component instanceof ClientBehaviorHolder)
 343  
             {
 344  0
                 behaviors = ((ClientBehaviorHolder) component).getClientBehaviors();
 345  0
                 renderBehaviorizedJavaScriptAnchorStart(
 346  
                         facesContext, writer, component, clientId, behaviors, formInfo);
 347  0
                 if (!behaviors.isEmpty())
 348  
                 {
 349  0
                     HtmlRendererUtils.writeIdAndName(writer, component, facesContext);
 350  
                 }
 351  
                 else 
 352  
                 {
 353  
                     // If onclick is not null, both onclick and server side script are rendered 
 354  
                     // using jsf.util.chain(...) js function. We need to check that case and force
 355  
                     // id/name rendering. It is possible to do something else in that case and 
 356  
                     // do not render the script using jsf.util.chain, but for now it is ok.
 357  
                     String commandOnclick;
 358  0
                     if (component instanceof HtmlCommandLink)
 359  
                     {
 360  0
                         commandOnclick = ((HtmlCommandLink)component).getOnclick();
 361  
                     }
 362  
                     else
 363  
                     {
 364  0
                         commandOnclick = (String)component.getAttributes().get(HTML.ONCLICK_ATTR);
 365  
                     }
 366  
 
 367  0
                     if (commandOnclick != null)
 368  
                     {
 369  0
                         HtmlRendererUtils.writeIdAndName(writer, component, facesContext);
 370  
                     }
 371  
                     else
 372  
                     {
 373  0
                         HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
 374  
                     }
 375  
                 }
 376  0
                 long commonPropertiesMarked = 0L;
 377  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 378  
                 {
 379  0
                     commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(component);
 380  
                 }
 381  0
                 if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 382  
                 {
 383  0
                     CommonPropertyUtils.renderEventPropertiesWithoutOnclick(writer,
 384  
                         commonPropertiesMarked, component);
 385  0
                     CommonPropertyUtils.renderFocusBlurEventProperties(writer,
 386  
                             commonPropertiesMarked, component);
 387  
                 }
 388  
                 else
 389  
                 {
 390  0
                     HtmlRendererUtils.renderBehaviorizedEventHandlersWithoutOnclick(
 391  
                             facesContext, writer, component, behaviors);
 392  0
                     HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 393  
                             facesContext, writer, component, behaviors);
 394  
                 }
 395  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 396  
                 {
 397  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesWithoutStyleAndEvents(writer, 
 398  
                             commonPropertiesMarked, component);
 399  
                 }
 400  
                 else
 401  
                 {
 402  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, component, 
 403  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_WITHOUT_STYLE_AND_EVENTS);
 404  
                 }
 405  0
             }
 406  
             else
 407  
             {
 408  0
                 renderJavaScriptAnchorStart(facesContext, writer, component, clientId, formInfo);
 409  0
                 HtmlRendererUtils.writeIdIfNecessary(writer, component, facesContext);
 410  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 411  
                 {
 412  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesWithoutOnclickAndStyle(writer, 
 413  
                             CommonPropertyUtils.getCommonPropertiesMarked(component), component);
 414  
                 }
 415  
                 else
 416  
                 {
 417  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, component, 
 418  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_WITHOUT_ONCLICK_WITHOUT_STYLE);
 419  
                 }
 420  
             }
 421  
 
 422  
 
 423  
             //HtmlRendererUtils.renderHTMLAttributes(writer, component,
 424  
             //                                       anchorAttrsToRender);
 425  0
             HtmlRendererUtils.renderHTMLAttribute(writer, HTML.STYLE_ATTR, HTML.STYLE_ATTR,
 426  
                                                   style);
 427  0
             HtmlRendererUtils.renderHTMLAttribute(writer, HTML.STYLE_CLASS_ATTR, HTML.STYLE_CLASS_ATTR,
 428  
                                                   styleClass);
 429  
         }
 430  
 
 431  
         // render value as required by JSF 1.1 renderkitdocs
 432  0
         if(value != null)
 433  
         {
 434  0
             writer.writeText(value.toString(), JSFAttr.VALUE_ATTR);
 435  
         }
 436  
         
 437  
         // render warning message for a h:commandLink with no nesting form
 438  0
         if (formInfo == null)
 439  
         {
 440  0
             writer.writeText(": This link is deactivated, because it is not embedded in a JSF form.", null);
 441  
         }
 442  0
     }
 443  
 
 444  
     protected void renderJavaScriptAnchorStart(FacesContext facesContext,
 445  
                                                ResponseWriter writer,
 446  
                                                UIComponent component,
 447  
                                                String clientId,
 448  
                                                FormInfo formInfo)
 449  
         throws IOException
 450  
     {
 451  0
         UIComponent nestingForm = formInfo.getForm();
 452  0
         String formName = formInfo.getFormName();
 453  
 
 454  0
         StringBuilder onClick = new StringBuilder();
 455  
 
 456  
         String commandOnclick;
 457  0
         if (component instanceof HtmlCommandLink)
 458  
         {
 459  0
             commandOnclick = ((HtmlCommandLink)component).getOnclick();
 460  
         }
 461  
         else
 462  
         {
 463  0
             commandOnclick = (String)component.getAttributes().get(HTML.ONCLICK_ATTR);
 464  
         }
 465  0
         if (commandOnclick != null)
 466  
         {
 467  0
             onClick.append("var cf = function(){");
 468  0
             onClick.append(commandOnclick);
 469  0
             onClick.append('}');
 470  0
             onClick.append(';');
 471  0
             onClick.append("var oamSF = function(){");
 472  
         }
 473  
 
 474  0
         if (RendererUtils.isAdfOrTrinidadForm(formInfo.getForm()))
 475  
         {
 476  0
             onClick.append("submitForm('");
 477  0
             onClick.append(formInfo.getForm().getClientId(facesContext));
 478  0
             onClick.append("',1,{source:'");
 479  0
             onClick.append(component.getClientId(facesContext));
 480  0
             onClick.append("'});return false;");
 481  
         }
 482  
         else
 483  
         {
 484  0
             HtmlRendererUtils.renderFormSubmitScript(facesContext);
 485  
 
 486  0
             StringBuilder params = addChildParameters(facesContext, component, nestingForm);
 487  
 
 488  0
             String target = getTarget(component);
 489  
 
 490  0
             onClick.append("return ").
 491  
                 append(HtmlRendererUtils.SUBMIT_FORM_FN_NAME_JSF2).append("('").
 492  
                 append(formName).append("','").
 493  
                 append(clientId).append("'");
 494  
 
 495  0
             if (params.length() > 2 || target != null)
 496  
             {
 497  0
                 onClick.append(",").
 498  
                     append(target == null ? "null" : ("'" + target + "'")).append(",").
 499  
                     append(params);
 500  
             }
 501  0
             onClick.append(");");
 502  
 
 503  
             //Not necessary since we are using oamSetHiddenInput to create input hidden fields
 504  
             //render hidden field - todo: in here for backwards compatibility
 505  0
             if (MyfacesConfig.getCurrentInstance(
 506  
                     facesContext.getExternalContext()).isRenderHiddenFieldsForLinkParams())
 507  
             {
 508  0
                 String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(
 509  
                         formInfo, facesContext);
 510  0
                 addHiddenCommandParameter(facesContext, nestingForm, hiddenFieldName);
 511  
             }
 512  
 
 513  
         }
 514  
         
 515  0
         if (commandOnclick != null)
 516  
         {
 517  0
             onClick.append('}');
 518  0
             onClick.append(';');
 519  0
             onClick.append("return (cf.apply(this, [])==false)? false : oamSF.apply(this, []); ");
 520  
         }        
 521  
 
 522  0
         writer.startElement(HTML.ANCHOR_ELEM, component);
 523  0
         writer.writeURIAttribute(HTML.HREF_ATTR, "#", null);
 524  0
         writer.writeAttribute(HTML.ONCLICK_ATTR, onClick.toString(), null);
 525  0
     }
 526  
 
 527  
     
 528  
     protected void renderBehaviorizedJavaScriptAnchorStart(FacesContext facesContext,
 529  
             ResponseWriter writer,
 530  
             UIComponent component,
 531  
             String clientId,
 532  
             Map<String, List<ClientBehavior>> behaviors,
 533  
             FormInfo formInfo)
 534  
     throws IOException
 535  
     {
 536  
         String commandOnclick;
 537  0
         if (component instanceof HtmlCommandLink)
 538  
         {
 539  0
             commandOnclick = ((HtmlCommandLink)component).getOnclick();
 540  
         }
 541  
         else
 542  
         {
 543  0
             commandOnclick = (String)component.getAttributes().get(HTML.ONCLICK_ATTR);
 544  
         }
 545  
 
 546  
         //Calculate the script necessary to submit form
 547  0
         String serverEventCode = buildServerOnclick(facesContext, component, clientId, formInfo);
 548  
         
 549  0
         String onclick = null;
 550  
         
 551  0
         if (commandOnclick == null && (behaviors.isEmpty() || 
 552  
             (!behaviors.containsKey(ClientBehaviorEvents.CLICK) && 
 553  
              !behaviors.containsKey(ClientBehaviorEvents.ACTION) ) ) )
 554  
         {
 555  
             //we need to render only the submit script
 556  0
             onclick = serverEventCode;
 557  
         }
 558  
         else
 559  
         {
 560  0
             boolean hasSubmittingBehavior = hasSubmittingBehavior(behaviors, ClientBehaviorEvents.CLICK)
 561  
                 || hasSubmittingBehavior(behaviors, ClientBehaviorEvents.ACTION);
 562  0
             if (!hasSubmittingBehavior)
 563  
             {
 564  
                 //Ensure required resource javascript is available
 565  0
                 ResourceUtils.renderDefaultJsfJsInlineIfNecessary(facesContext, writer);
 566  
             }
 567  
             
 568  
             //render a javascript that chain the related code
 569  0
             Collection<ClientBehaviorContext.Parameter> paramList = 
 570  
                 HtmlRendererUtils.getClientBehaviorContextParameters(
 571  
                     HtmlRendererUtils.mapAttachedParamsToStringValues(facesContext, component));
 572  
             
 573  0
             onclick = HtmlRendererUtils.buildBehaviorChain(facesContext, component,
 574  
                     ClientBehaviorEvents.CLICK, paramList, ClientBehaviorEvents.ACTION, paramList, behaviors,
 575  
                     commandOnclick , hasSubmittingBehavior ? null : serverEventCode);
 576  
         }
 577  
         
 578  0
         writer.startElement(HTML.ANCHOR_ELEM, component);
 579  0
         writer.writeURIAttribute(HTML.HREF_ATTR, "#", null);
 580  0
         writer.writeAttribute(HTML.ONCLICK_ATTR, onclick, null);
 581  0
     }
 582  
 
 583  
     private boolean hasSubmittingBehavior(Map<String, List<ClientBehavior>> clientBehaviors, String eventName)
 584  
     {
 585  0
         List<ClientBehavior> eventBehaviors = clientBehaviors.get(eventName);
 586  0
         if (eventBehaviors != null && !eventBehaviors.isEmpty())
 587  
         {
 588  
             // perf: in 99% cases is  eventBehaviors javax.faces.component._DeltaList._DeltaList(int) = RandomAccess
 589  
             // instance created in javax.faces.component.UIComponentBase.addClientBehavior(String, ClientBehavior), but
 590  
             // component libraries can provide own implementation
 591  0
             if (eventBehaviors instanceof RandomAccess)
 592  
             {
 593  0
                 for (int i = 0, size = eventBehaviors.size(); i < size; i++)
 594  
                 {
 595  0
                     ClientBehavior behavior = eventBehaviors.get(i);
 596  0
                     if (behavior.getHints().contains(ClientBehaviorHint.SUBMITTING))
 597  
                     {
 598  0
                         return true;
 599  
                     }
 600  
                 }
 601  
             }
 602  
             else
 603  
             {
 604  0
                 for (ClientBehavior behavior : eventBehaviors)
 605  
                 {
 606  0
                     if (behavior.getHints().contains(ClientBehaviorHint.SUBMITTING))
 607  
                     {
 608  0
                         return true;
 609  
                     }
 610  0
                 }
 611  
             }
 612  
         }
 613  0
         return false;
 614  
     }
 615  
 
 616  
     protected String buildServerOnclick(FacesContext facesContext, UIComponent component, 
 617  
             String clientId, FormInfo formInfo) throws IOException
 618  
     {
 619  0
         UIComponent nestingForm = formInfo.getForm();
 620  0
         String formName = formInfo.getFormName();
 621  
 
 622  0
         StringBuilder onClick = new StringBuilder();
 623  
 
 624  0
         if (RendererUtils.isAdfOrTrinidadForm(formInfo.getForm()))
 625  
         {
 626  0
             onClick.append("submitForm('");
 627  0
             onClick.append(formInfo.getForm().getClientId(facesContext));
 628  0
             onClick.append("',1,{source:'");
 629  0
             onClick.append(component.getClientId(facesContext));
 630  0
             onClick.append("'});return false;");
 631  
         }
 632  
         else
 633  
         {
 634  0
             HtmlRendererUtils.renderFormSubmitScript(facesContext);
 635  
 
 636  0
             StringBuilder params = addChildParameters(facesContext, component, nestingForm);
 637  
 
 638  0
             String target = getTarget(component);
 639  
 
 640  0
             onClick.append("return ").
 641  
                 append(HtmlRendererUtils.SUBMIT_FORM_FN_NAME_JSF2).append("('").
 642  
                 append(formName).append("','").
 643  
                 append(clientId).append("'");
 644  
 
 645  0
             if (params.length() > 2 || target != null)
 646  
             {
 647  0
                 onClick.append(",").
 648  
                     append(target == null ? "null" : ("'" + target + "'")).append(",").
 649  
                     append(params);
 650  
             }
 651  0
             onClick.append(");");
 652  
 
 653  
             //Not necessary since we are using oamSetHiddenInput to create input hidden fields
 654  
             //render hidden field - todo: in here for backwards compatibility
 655  
             //String hiddenFieldName = HtmlRendererUtils.getHiddenCommandLinkFieldName(formInfo);
 656  
             //addHiddenCommandParameter(facesContext, nestingForm, hiddenFieldName);
 657  
 
 658  
         }
 659  0
         return onClick.toString();
 660  
     }
 661  
 
 662  
     private String getTarget(UIComponent component)
 663  
     {
 664  
         // for performance reason: double check for the target attribute
 665  
         String target;
 666  0
         if (component instanceof HtmlCommandLink)
 667  
         {
 668  0
             target = ((HtmlCommandLink) component).getTarget();
 669  
         }
 670  
         else
 671  
         {
 672  0
             target = (String) component.getAttributes().get(HTML.TARGET_ATTR);
 673  
         }
 674  0
         return target;
 675  
     }
 676  
 
 677  
     private StringBuilder addChildParameters(FacesContext context, UIComponent component, UIComponent nestingForm)
 678  
     {
 679  
         //add child parameters
 680  0
         StringBuilder params = new StringBuilder();
 681  0
         params.append("[");
 682  
         
 683  0
         List<UIComponent> childrenList = null;
 684  0
         if (getChildCount(component) > 0)
 685  
         {
 686  0
             childrenList = getChildren(component);
 687  
         }
 688  
         else
 689  
         {
 690  0
            childrenList = Collections.emptyList();
 691  
         }
 692  0
         List<UIParameter> validParams = HtmlRendererUtils.getValidUIParameterChildren(
 693  
                 context, childrenList, false, false);
 694  0
         for (int j = 0, size = validParams.size(); j < size; j++) 
 695  
         {
 696  0
             UIParameter param = validParams.get(j);
 697  0
             String name = param.getName();
 698  
 
 699  
             //Not necessary, since we are using oamSetHiddenInput to create hidden fields
 700  0
             if (MyfacesConfig.getCurrentInstance(context.getExternalContext()).isRenderHiddenFieldsForLinkParams())
 701  
             {
 702  0
                 addHiddenCommandParameter(context, nestingForm, name);
 703  
             }
 704  
 
 705  0
             Object value = param.getValue();
 706  
 
 707  
             //UIParameter is no ValueHolder, so no conversion possible - calling .toString on value....
 708  
             // MYFACES-1832 bad charset encoding for f:param
 709  
             // if HTMLEncoder.encode is called, then
 710  
             // when is called on writer.writeAttribute, encode method
 711  
             // is called again so we have a duplicated encode call.
 712  
             // MYFACES-2726 All '\' and "'" chars must be escaped 
 713  
             // because there will be inside "'" javascript quotes, 
 714  
             // otherwise the value will not correctly restored when
 715  
             // the command is post.
 716  
             //String strParamValue = value != null ? value.toString() : "";
 717  0
             String strParamValue = "";
 718  0
             if (value != null)
 719  
             {
 720  0
                 strParamValue = value.toString();
 721  0
                 StringBuilder buff = null;
 722  0
                 for (int i = 0; i < strParamValue.length(); i++)
 723  
                 {
 724  0
                     char c = strParamValue.charAt(i); 
 725  0
                     if (c == '\'' || c == '\\')
 726  
                     {
 727  0
                         if (buff == null)
 728  
                         {
 729  0
                             buff = new StringBuilder();
 730  0
                             buff.append(strParamValue.substring(0,i));
 731  
                         }
 732  0
                         buff.append('\\');
 733  0
                         buff.append(c);
 734  
                     }
 735  0
                     else if (buff != null)
 736  
                     {
 737  0
                         buff.append(c);
 738  
                     }
 739  
                 }
 740  0
                 if (buff != null)
 741  
                 {
 742  0
                     strParamValue = buff.toString();
 743  
                 }
 744  
             }
 745  
 
 746  0
             if (params.length() > 1) 
 747  
             {
 748  0
                 params.append(",");
 749  
             }
 750  
 
 751  0
             params.append("['");
 752  0
             params.append(name);
 753  0
             params.append("','");
 754  0
             params.append(strParamValue);
 755  0
             params.append("']");
 756  
         }
 757  0
         params.append("]");
 758  0
         return params;
 759  
     }
 760  
 
 761  
     /**
 762  
      * find nesting form<br />
 763  
      * need to be overrideable to deal with dummyForm stuff in tomahawk.
 764  
      */
 765  
     protected FormInfo findNestingForm(UIComponent uiComponent, FacesContext facesContext)
 766  
     {
 767  0
         return _ComponentUtils.findNestingForm(uiComponent, facesContext);
 768  
     }
 769  
 
 770  
     protected void addHiddenCommandParameter(
 771  
             FacesContext facesContext, UIComponent nestingForm, String hiddenFieldName)
 772  
     {
 773  0
         if (nestingForm != null)
 774  
         {
 775  0
             HtmlFormRendererBase.addHiddenCommandParameter(facesContext, nestingForm, hiddenFieldName);
 776  
         }
 777  0
     }
 778  
 
 779  
     private void addChildParametersToHref(FacesContext facesContext,
 780  
                                           UIComponent linkComponent,
 781  
                                           StringBuilder hrefBuf,
 782  
                                           boolean firstParameter,
 783  
                                           String charEncoding)
 784  
             throws IOException
 785  
     {
 786  0
         boolean strictXhtmlLinks
 787  
                 = MyfacesConfig.getCurrentInstance(facesContext.getExternalContext()).isStrictXhtmlLinks();
 788  0
         List<UIComponent> childrenList = null;
 789  0
         if (getChildCount(linkComponent) > 0)
 790  
         {
 791  0
             childrenList = getChildren(linkComponent);
 792  
         }
 793  
         else
 794  
         {
 795  0
            childrenList = Collections.emptyList();
 796  
         }
 797  0
         List<UIParameter> validParams = HtmlRendererUtils.getValidUIParameterChildren(
 798  
                 facesContext, childrenList, false, false);
 799  
         
 800  0
         for (int i = 0, size = validParams.size(); i < size; i++)
 801  
         {
 802  0
             UIParameter param = validParams.get(i);
 803  0
             String name = param.getName();
 804  0
             Object value = param.getValue();
 805  0
             addParameterToHref(name, value, hrefBuf, firstParameter, charEncoding, strictXhtmlLinks);
 806  0
             firstParameter = false;
 807  
         }
 808  0
     }
 809  
 
 810  
     protected void renderOutputLinkStart(FacesContext facesContext, UIOutput output)
 811  
             throws IOException
 812  
     {
 813  0
         ResponseWriter writer = facesContext.getResponseWriter();
 814  0
         Map<String, List<ClientBehavior>> behaviors = null;
 815  
 
 816  0
         if (HtmlRendererUtils.isDisabled(output))
 817  
         {
 818  0
             writer.startElement(HTML.SPAN_ELEM, output);
 819  0
             if (output instanceof ClientBehaviorHolder)
 820  
             {
 821  0
                 behaviors = ((ClientBehaviorHolder) output).getClientBehaviors();
 822  0
                 if (!behaviors.isEmpty())
 823  
                 {
 824  0
                     HtmlRendererUtils.writeIdAndName(writer, output, facesContext);
 825  
                 }
 826  
                 else
 827  
                 {
 828  0
                     HtmlRendererUtils.writeIdIfNecessary(writer, output, facesContext);
 829  
                 }
 830  0
                 long commonPropertiesMarked = 0L;
 831  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 832  
                 {
 833  0
                     commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(output);
 834  
                 }
 835  
 
 836  0
                 if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 837  
                 {
 838  0
                     CommonPropertyUtils.renderEventProperties(writer, 
 839  
                             commonPropertiesMarked, output);
 840  0
                     CommonPropertyUtils.renderFocusBlurEventProperties(writer,
 841  
                             commonPropertiesMarked, output);
 842  
                 }
 843  
                 else
 844  
                 {
 845  0
                     if (isCommonEventsOptimizationEnabled(facesContext))
 846  
                     {
 847  0
                         Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(output);
 848  0
                         CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
 849  
                                 commonPropertiesMarked, commonEventsMarked, output, behaviors);
 850  0
                         CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 851  
                             facesContext, writer, commonPropertiesMarked, commonEventsMarked, output, behaviors);
 852  0
                     }
 853  
                     else
 854  
                     {
 855  0
                         HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, output, behaviors);
 856  0
                         HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 857  
                                 facesContext, writer, output, behaviors);
 858  
                     }
 859  
                 }
 860  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 861  
                 {
 862  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesDisabledWithoutEvents(writer, 
 863  
                             commonPropertiesMarked, output);
 864  
                 }
 865  
                 else
 866  
                 {
 867  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, output, 
 868  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_DISABLED_WITHOUT_EVENTS);
 869  
                 }
 870  0
             }
 871  
             else
 872  
             {
 873  0
                 HtmlRendererUtils.writeIdIfNecessary(writer, output, facesContext);
 874  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 875  
                 {
 876  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesDisabled(writer, 
 877  
                             CommonPropertyUtils.getCommonPropertiesMarked(output), output);
 878  
                 }
 879  
                 else
 880  
                 {
 881  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, output, HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_DISABLED);
 882  
                 }
 883  
             }
 884  
         }
 885  
         else
 886  
         { 
 887  
             //calculate href
 888  0
             String href = org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue(facesContext, output);
 889  
             
 890  
             //check if there is an anchor # in it
 891  0
             int index = href.indexOf('#');
 892  0
             String anchorString = null;
 893  0
             boolean isAnchorInHref = (index > -1);
 894  0
             if (isAnchorInHref)
 895  
             {
 896  
                 // remove anchor element and add it again after the parameter are encoded
 897  0
                 anchorString = href.substring(index,href.length());
 898  0
                 href = href.substring(0,index);
 899  
             }
 900  0
             if (getChildCount(output) > 0)
 901  
             {
 902  0
                 StringBuilder hrefBuf = new StringBuilder(href);
 903  0
                 addChildParametersToHref(facesContext, output, hrefBuf,
 904  
                                      (href.indexOf('?') == -1), //first url parameter?
 905  
                                      writer.getCharacterEncoding());
 906  0
                 href = hrefBuf.toString();
 907  
             }
 908  
             // check for the fragement attribute
 909  0
             String fragmentAttr = null;
 910  0
             if (output instanceof HtmlOutputLink)
 911  
             {
 912  0
                 fragmentAttr = ((HtmlOutputLink) output).getFragment();
 913  
             }
 914  
             else
 915  
             {
 916  0
                 fragmentAttr = (String) output.getAttributes().get(JSFAttr.FRAGMENT_ATTR);
 917  
             }
 918  0
             if (fragmentAttr != null && !"".equals(fragmentAttr)) 
 919  
             {
 920  0
                 href += "#" + fragmentAttr;
 921  
             }
 922  0
             else if (isAnchorInHref)
 923  
             {
 924  0
                 href += anchorString;
 925  
             }
 926  0
             href = facesContext.getExternalContext().encodeResourceURL(href);    //TODO: or encodeActionURL ?
 927  
 
 928  
             //write anchor
 929  0
             writer.startElement(HTML.ANCHOR_ELEM, output);
 930  0
             writer.writeURIAttribute(HTML.HREF_ATTR, href, null);
 931  0
             if (output instanceof ClientBehaviorHolder)
 932  
             {
 933  0
                 behaviors = ((ClientBehaviorHolder) output).getClientBehaviors();
 934  0
                 if (!behaviors.isEmpty())
 935  
                 {
 936  0
                     HtmlRendererUtils.writeIdAndName(writer, output, facesContext);
 937  
                 }
 938  
                 else
 939  
                 {
 940  0
                     HtmlRendererUtils.writeIdAndNameIfNecessary(writer, output, facesContext);
 941  
                 }
 942  0
                 long commonPropertiesMarked = 0L;
 943  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 944  
                 {
 945  0
                     commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(output);
 946  
                 }
 947  0
                 if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 948  
                 {
 949  0
                     CommonPropertyUtils.renderEventProperties(writer, 
 950  
                             commonPropertiesMarked, output);
 951  0
                     CommonPropertyUtils.renderFocusBlurEventProperties(writer,
 952  
                             commonPropertiesMarked, output);
 953  
                 }
 954  
                 else
 955  
                 {
 956  0
                     if (isCommonEventsOptimizationEnabled(facesContext))
 957  
                     {
 958  0
                         Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(output);
 959  0
                         CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
 960  
                                 commonPropertiesMarked, commonEventsMarked, output, behaviors);
 961  0
                         CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 962  
                             facesContext, writer, commonPropertiesMarked, commonEventsMarked, output, behaviors);
 963  0
                     }
 964  
                     else
 965  
                     {
 966  0
                         HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, output, behaviors);
 967  0
                         HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 968  
                                 facesContext, writer, output, behaviors);
 969  
                     }
 970  
                 }
 971  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 972  
                 {
 973  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesWithoutEvents(writer, 
 974  
                             commonPropertiesMarked, output);
 975  
                 }
 976  
                 else
 977  
                 {
 978  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, output, 
 979  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
 980  
                 }
 981  0
             }
 982  
             else
 983  
             {
 984  0
                 HtmlRendererUtils.writeIdAndNameIfNecessary(writer, output, facesContext);
 985  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 986  
                 {
 987  0
                     CommonPropertyUtils.renderAnchorPassthroughProperties(writer, 
 988  
                             CommonPropertyUtils.getCommonPropertiesMarked(output), output);
 989  
                 }
 990  
                 else
 991  
                 {
 992  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, output, HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES);
 993  
                 }
 994  
             }
 995  0
             writer.flush();
 996  
         }
 997  0
     }
 998  
     
 999  
     protected void renderOutcomeLinkStart(FacesContext facesContext, UIOutcomeTarget output)
 1000  
             throws IOException
 1001  
     {
 1002  0
         ResponseWriter writer = facesContext.getResponseWriter();
 1003  0
         Map<String, List<ClientBehavior>> behaviors = null;
 1004  
         
 1005  
         //calculate href
 1006  0
         String targetHref = HtmlRendererUtils.getOutcomeTargetHref(facesContext, output);
 1007  
         
 1008  0
         if (HtmlRendererUtils.isDisabled(output) || targetHref == null)
 1009  
         {
 1010  
             //output.getAttributes().put(END_LINK_OUTCOME_AS_SPAN, Boolean.TRUE);
 1011  
             //Note one h:link cannot have a nested h:link as a child, so it is safe
 1012  
             //to just put this flag on FacesContext attribute map
 1013  0
             facesContext.getAttributes().put(END_LINK_OUTCOME_AS_SPAN, Boolean.TRUE);
 1014  0
             writer.startElement(HTML.SPAN_ELEM, output);
 1015  0
             if (output instanceof ClientBehaviorHolder)
 1016  
             {
 1017  0
                 behaviors = ((ClientBehaviorHolder) output).getClientBehaviors();
 1018  0
                 if (!behaviors.isEmpty())
 1019  
                 {
 1020  0
                     HtmlRendererUtils.writeIdAndName(writer, output, facesContext);
 1021  
                 }
 1022  
                 else
 1023  
                 {
 1024  0
                     HtmlRendererUtils.writeIdIfNecessary(writer, output, facesContext);
 1025  
                 }
 1026  0
                 long commonPropertiesMarked = 0L;
 1027  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 1028  
                 {
 1029  0
                     commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(output);
 1030  
                 }
 1031  0
                 if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 1032  
                 {
 1033  0
                     CommonPropertyUtils.renderEventProperties(writer, 
 1034  
                             commonPropertiesMarked, output);
 1035  0
                     CommonPropertyUtils.renderFocusBlurEventProperties(writer,
 1036  
                             commonPropertiesMarked, output);
 1037  
                 }
 1038  
                 else
 1039  
                 {
 1040  0
                     if (isCommonEventsOptimizationEnabled(facesContext))
 1041  
                     {
 1042  0
                         Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(output);
 1043  0
                         CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
 1044  
                                 commonPropertiesMarked, commonEventsMarked, output, behaviors);
 1045  0
                         CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 1046  
                             facesContext, writer, commonPropertiesMarked, commonEventsMarked, output, behaviors);
 1047  0
                     }
 1048  
                     else
 1049  
                     {
 1050  0
                         HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, output, behaviors);
 1051  0
                         HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 1052  
                                 facesContext, writer, output, behaviors);
 1053  
                     }
 1054  
                 }
 1055  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 1056  
                 {
 1057  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesDisabledWithoutEvents(writer, 
 1058  
                             commonPropertiesMarked, output);
 1059  
                 }
 1060  
                 else
 1061  
                 {
 1062  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, output, 
 1063  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_DISABLED_WITHOUT_EVENTS);
 1064  
                 }
 1065  0
             }
 1066  
             else
 1067  
             {
 1068  0
                 HtmlRendererUtils.writeIdIfNecessary(writer, output, facesContext);
 1069  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 1070  
                 {
 1071  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesDisabled(writer, 
 1072  
                             CommonPropertyUtils.getCommonPropertiesMarked(output), output);
 1073  
                 }
 1074  
                 else
 1075  
                 {
 1076  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, output, HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_DISABLED);
 1077  
                 }
 1078  
             }
 1079  
 
 1080  0
             Object value = output.getValue();
 1081  
 
 1082  0
             if(value != null)
 1083  
             {
 1084  0
                 writer.writeText(value.toString(), JSFAttr.VALUE_ATTR);
 1085  
             }
 1086  0
         }
 1087  
         else
 1088  
         {
 1089  
             //write anchor
 1090  0
             writer.startElement(HTML.ANCHOR_ELEM, output);
 1091  0
             writer.writeURIAttribute(HTML.HREF_ATTR, targetHref, null);
 1092  0
             if (output instanceof ClientBehaviorHolder)
 1093  
             {
 1094  0
                 behaviors = ((ClientBehaviorHolder) output).getClientBehaviors();
 1095  0
                 if (!behaviors.isEmpty())
 1096  
                 {
 1097  0
                     HtmlRendererUtils.writeIdAndName(writer, output, facesContext);
 1098  
                 }
 1099  
                 else
 1100  
                 {
 1101  0
                     HtmlRendererUtils.writeIdAndNameIfNecessary(writer, output, facesContext);
 1102  
                 }
 1103  0
                 long commonPropertiesMarked = 0L;
 1104  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 1105  
                 {
 1106  0
                     commonPropertiesMarked = CommonPropertyUtils.getCommonPropertiesMarked(output);
 1107  
                 }
 1108  0
                 if (behaviors.isEmpty() && isCommonPropertiesOptimizationEnabled(facesContext))
 1109  
                 {
 1110  0
                     CommonPropertyUtils.renderEventProperties(writer, 
 1111  
                             commonPropertiesMarked, output);
 1112  0
                     CommonPropertyUtils.renderFocusBlurEventProperties(writer,
 1113  
                             commonPropertiesMarked, output);
 1114  
                 }
 1115  
                 else
 1116  
                 {
 1117  0
                     if (isCommonEventsOptimizationEnabled(facesContext))
 1118  
                     {
 1119  0
                         Long commonEventsMarked = CommonEventUtils.getCommonEventsMarked(output);
 1120  0
                         CommonEventUtils.renderBehaviorizedEventHandlers(facesContext, writer, 
 1121  
                                 commonPropertiesMarked, commonEventsMarked, output, behaviors);
 1122  0
                         CommonEventUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 1123  
                             facesContext, writer, commonPropertiesMarked, commonEventsMarked, output, behaviors);
 1124  0
                     }
 1125  
                     else
 1126  
                     {
 1127  0
                         HtmlRendererUtils.renderBehaviorizedEventHandlers(facesContext, writer, output, behaviors);
 1128  0
                         HtmlRendererUtils.renderBehaviorizedFieldEventHandlersWithoutOnchangeAndOnselect(
 1129  
                                 facesContext, writer, output, behaviors);
 1130  
                     }
 1131  
                 }
 1132  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 1133  
                 {
 1134  0
                     CommonPropertyUtils.renderAnchorPassthroughPropertiesWithoutEvents(writer, 
 1135  
                             commonPropertiesMarked, output);
 1136  
                 }
 1137  
                 else
 1138  
                 {
 1139  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, output, 
 1140  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES_WITHOUT_EVENTS);
 1141  
                 }
 1142  0
             }
 1143  
             else
 1144  
             {
 1145  0
                 HtmlRendererUtils.writeIdAndNameIfNecessary(writer, output, facesContext);
 1146  0
                 if (isCommonPropertiesOptimizationEnabled(facesContext))
 1147  
                 {
 1148  0
                     CommonPropertyUtils.renderAnchorPassthroughProperties(writer, 
 1149  
                             CommonPropertyUtils.getCommonPropertiesMarked(output), output);
 1150  
                 }
 1151  
                 else
 1152  
                 {
 1153  0
                     HtmlRendererUtils.renderHTMLAttributes(writer, output, 
 1154  
                             HTML.ANCHOR_PASSTHROUGH_ATTRIBUTES);
 1155  
                 }
 1156  
             }
 1157  
 
 1158  0
             writer.flush();
 1159  
         }
 1160  0
     }
 1161  
 
 1162  
     private static void addParameterToHref(String name,
 1163  
                                            Object value,
 1164  
                                            StringBuilder hrefBuf,
 1165  
                                            boolean firstParameter,
 1166  
                                            String charEncoding,
 1167  
                                            boolean strictXhtmlLinks) throws UnsupportedEncodingException
 1168  
     {
 1169  0
         if (name == null)
 1170  
         {
 1171  0
             throw new IllegalArgumentException("Unnamed parameter value not allowed within command link.");
 1172  
         }
 1173  
 
 1174  0
         if (firstParameter)
 1175  
         {
 1176  0
             hrefBuf.append('?');
 1177  
         }
 1178  
         else
 1179  
         {
 1180  0
             if (strictXhtmlLinks)
 1181  
             {
 1182  0
                 hrefBuf.append("&amp;");
 1183  
             }
 1184  
             else
 1185  
             {
 1186  0
                 hrefBuf.append('&');
 1187  
             }
 1188  
         }
 1189  
 
 1190  0
         hrefBuf.append(URLEncoder.encode(name, charEncoding));
 1191  0
         hrefBuf.append('=');
 1192  0
         if (value != null)
 1193  
         {
 1194  
             //UIParameter is no ConvertibleValueHolder, so no conversion possible
 1195  0
             hrefBuf.append(URLEncoder.encode(value.toString(), charEncoding));
 1196  
         }
 1197  0
     }
 1198  
 
 1199  
     protected void renderOutcomeLinkEnd(FacesContext facesContext, UIComponent component)
 1200  
             throws IOException
 1201  
     {
 1202  0
         ResponseWriter writer = facesContext.getResponseWriter();
 1203  
         
 1204  0
         if (HtmlRendererUtils.isDisabled(component) || Boolean.TRUE.equals(
 1205  
                 facesContext.getAttributes().get(END_LINK_OUTCOME_AS_SPAN)))
 1206  
         {
 1207  0
             writer.endElement(HTML.SPAN_ELEM);
 1208  0
             facesContext.getAttributes().put(END_LINK_OUTCOME_AS_SPAN, Boolean.FALSE);
 1209  
         }
 1210  
         else
 1211  
         {
 1212  0
             writer.writeText (org.apache.myfaces.shared.renderkit.RendererUtils.getStringValue
 1213  
                  (facesContext, component), null);
 1214  0
             writer.endElement(HTML.ANCHOR_ELEM);
 1215  
         }
 1216  0
     }
 1217  
     
 1218  
     protected void renderOutputLinkEnd(FacesContext facesContext, UIComponent component)
 1219  
             throws IOException
 1220  
     {
 1221  0
         ResponseWriter writer = facesContext.getResponseWriter();
 1222  
 
 1223  0
         if (HtmlRendererUtils.isDisabled(component))
 1224  
         {
 1225  0
             writer.endElement(HTML.SPAN_ELEM);
 1226  
         }
 1227  
         else
 1228  
         {
 1229  
             // force separate end tag
 1230  0
             writer.writeText("", null);
 1231  0
             writer.endElement(HTML.ANCHOR_ELEM);
 1232  
         }
 1233  0
     }
 1234  
 
 1235  
     protected void renderCommandLinkEnd(FacesContext facesContext, UIComponent component)
 1236  
             throws IOException
 1237  
     {
 1238  0
         FormInfo formInfo = findNestingForm(component, facesContext);
 1239  
         
 1240  0
         ResponseWriter writer = facesContext.getResponseWriter();
 1241  0
         if (HtmlRendererUtils.isDisabled(component) || formInfo == null)
 1242  
         {
 1243  
 
 1244  0
             writer.endElement(HTML.SPAN_ELEM);
 1245  
         }
 1246  
         else
 1247  
         {
 1248  0
             writer.writeText("", null);
 1249  0
             writer.endElement(HTML.ANCHOR_ELEM);
 1250  
         }
 1251  0
     }
 1252  
 }