[ 
https://issues.apache.org/jira/browse/MYFACES-1897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12621596#action_12621596
 ] 

Leonardo Uribe commented on MYFACES-1897:
-----------------------------------------

Hi

This issue has been more difficult that it seems at start.

So UISelectItem has a jsp property name as "escape", but on the component class 
is "itemEscape". In that case the patch is necessary for now (I also committed 
the correction on the annotation, but in the future this part should be 
generated).

I'll commit a modified solution of your patch, because there still some 
objections:

1. javax.faces.model.SelectItem was a new addition on 1.2 (escape property). 
The documentation says that in any constructor with params without escape 
defined, this property should be initialized by default as true. It has sense, 
but right now myfaces core is doing the opposite, so this should be corrected. 
The issue was never noted because there exists a code like this:

                if (component instanceof EscapeCapable)
                {
                    escape = ((EscapeCapable)component).isEscape();
                }
                else
                {
                    escape = RendererUtils.getBooleanAttribute(component, 
JSFAttr.ESCAPE_ATTR,
                                                               true); //default 
is to escape
                }

The else part of the if makes escape everything by default. 

2. There are tomahawk components that use the method:

    public static void renderSelectOptions(FacesContext context,
                                           UIComponent component, Converter 
converter, Set lookupSet,
                                           List selectItemList) throws 
IOException {

This method contains the previous discussed code. All tomahawk components that 
use this method implements EscapeCapable interface (and has an escape property 
for the whole component by default true). But the changes must be done 
remaining compatibility with this property. Just do this:

                    escape = RendererUtils.getBooleanAttribute(component, 
JSFAttr.ESCAPE_ATTR,
                                                               false);

does not solve the problem, because if escape="false" for some tomahawk 
component, by default on SelectItem is true, so the result (do not escape 
anything) is not get.

In conclusion the solution should be something like this:

                boolean escape;
                if (component instanceof EscapeCapable)
                {
                    escape = ((EscapeCapable)component).isEscape();
                    
                    // Preserve tomahawk semantic. If escape=false
                    // all items should be non escaped. If escape
                    // is true check if selectItem.isEscape() is
                    // true and do it.
                    // This is done for remain compatibility.
                    if (escape && selectItem.isEscape())
                    {
                        writer.writeText(selectItem.getLabel(), null);
                    } else
                    {
                        writer.write(selectItem.getLabel());
                    }
                }
                else
                {
                    escape = RendererUtils.getBooleanAttribute(component, 
JSFAttr.ESCAPE_ATTR,
                                                               false);
                    //default is to escape
                    //In JSF 1.2, when a SelectItem is created by default 
                    //selectItem.isEscape() returns true (this property
                    //is not available on JSF 1.1).
                    //so, if we found a escape property on the component
                    //set to true, escape every item, but if not
                    //check if isEscape() = true first.
                    if (escape || selectItem.isEscape())
                    {
                        writer.writeText(selectItem.getLabel(), null);
                    } else
                    {
                        writer.write(selectItem.getLabel());
                    }
                }

I'll commit this solution and close this issue right now. But I cannot commit 
tomahawk patch (it is correct but It is necessary to  create another issue on 
tomahawk project with a reference to this issue). Please create it and I'll 
commit the patch.

> escape value of a selectItem is never evaluated
> -----------------------------------------------
>
>                 Key: MYFACES-1897
>                 URL: https://issues.apache.org/jira/browse/MYFACES-1897
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: JSR-252
>    Affects Versions: 1.2.3
>            Reporter: Jörg Rothbarth
>            Assignee: Leonardo Uribe
>         Attachments: myfaces-1897-part1.patch, myfaces-1897-part2.patch, 
> SelectItemEscapeBean.java, selectOneManyEscape-simple.jsp, 
> selectOneManyEscape.jsp, tomahawk12-HtmlCheckboxRenderer.patch, 
> tomahawk12-HtmlRadioRenderer.patch
>
>
> The escape Attribute of a selectItem Component is not evaluated inside a 
> selectOneRadio component.
> The selectItem Component has a escape member, but the member is never used. 
> To fix the problem i've done this:
> HtmlRadioRendererBase.renderGroupOrItemRadio() Line ~199 :
> // label element after the input
> boolean componentDisabled = isDisabled(facesContext, selectOne);
> boolean disabled = (componentDisabled || itemDisabled);
> boolean escape = selectItem.isEscape();
> HtmlRendererUtils.renderLabel(writer, selectOne, itemId,
>                 selectItem.getLabel(), disabled,escape);
> HtmlRendererUtils.renderLabel() Line ~1352:
> public static void renderLabel(ResponseWriter writer, UIComponent    
>     component, String forClientId,String labelValue, boolean    
>                 disabled) throws IOException {
> renderLabel(writer, component, forClientId, labelValue, disabled, true);
> }
> /**
>  * Renders a label HTML element
>  */
> public static void renderLabel(ResponseWriter writer, UIComponent
>             component, String forClientId,String labelValue,         boolean 
> disabled, boolean escape) throws IOException {
> ...
> if ((labelValue != null) && (labelValue.length() > 0)) {
>     writer.write(HTML.NBSP_ENTITY);
>     if (escape) {
>         writer.writeText(labelValue, null);
>     } else {
>         writer.write(labelValue);
>     }
> }
> ... 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to