struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Walid Ghafir (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (WW-4036) With javatemplate, dynamic attribute value evaluates to expression text if null
Date Thu, 04 Apr 2013 00:43:15 GMT

     [ https://issues.apache.org/jira/browse/WW-4036?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Walid Ghafir updated WW-4036:
-----------------------------

    Description: 
When using javatemplate plugin, if a dynamic attribute has an expression value that evaluates
to null, the full expression text is displayed instead of just an empty string.

Example: 
{code:html}
<s:textfield placeholder="%{null}" name="%{null}"/> 
{code}
will output
{code:html}
<input type="text" placeholder="%{null}" name=""/> 
{code}
in the HTML.

By debugging, I found it comes from AbstractUITag.setDynamicAttribute():
{code:java}
dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()),
value)));
{code}

That problem does not occur with FTL themes as dynamic-attributes.ftl uses TextParseUtil.translateVariables()
which does what the doc says ("If an item cannot be found on the stack (null is returned),
then the entire variable %\{...\} is not displayed, just as if the item was on the stack but
returned an empty string.").

*Suggested fix #1*

Change org.apache.struts2.views.java.simple.DynamicAttributesHandler.start() so that it does
the same than dynamic-attributes.ftl:
{code:java|title=DynamicAttributesHandler.java}
    @Override
    public void start(String name, Attributes a) throws IOException {
	Map<String, String> dynamicAttributes = (Map<String, String>) context.getParameters().get("dynamicAttributes");
	for (String key : dynamicAttributes.keySet())
		a.put(key, TextParseUtil.translateVariables(dynamicAttributes.get(key), context.getStack()));
        super.start(name, a);
    }
{code}

*Suggested fix #2*

Or change org.apache.struts2.views.jsp.ui.AbstractUITag.setDynamicAttribute() so that it returns
an empty string if the expression evaluates to null:
{code:java|title=AbstractUITag.java}
    public void setDynamicAttribute(String uri, String localName, Object value) throws JspException
{
        if (ComponentUtils.altSyntax(getStack()) && ComponentUtils.isExpression(value))
{
            dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()),
"")));
        } else {
            dynamicAttributes.put(localName, value);
        }
    }
{code}
(but I have no idea on the possible side effects it could produce).


  was:
When using javatemplate plugin, if a dynamic attribute has an expression value that evaluates
to null, the full expression text is displayed instead of just an empty string.

Example: 
{code:html}
<s:textfield placeholder="%{null}" name="%{null}"/> 
{code}
will output
{code:html}
<input type="text" placeholder="%{null}" name=""/> 
{code}
in the HTML.

By debugging, I found it comes from AbstractUITag.setDynamicAttribute():
{code:java}
dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()),
value)));
{code}

That problem does not occur with FTL themes as dynamic-attributes.flt uses TextParseUtil.translateVariables()
which does what the doc says ("If an item cannot be found on the stack (null is returned),
then the entire variable %\{...\} is not displayed, just as if the item was on the stack but
returned an empty string.").

*Suggested fix #1*

Change org.apache.struts2.views.java.simple.DynamicAttributesHandler.start() so that it does
the same than dynamic-attributes.flt:
{code:java|title=DynamicAttributesHandler.java}
    @Override
    public void start(String name, Attributes a) throws IOException {
	Map<String, String> dynamicAttributes = (Map<String, String>) context.getParameters().get("dynamicAttributes");
	for (String key : dynamicAttributes.keySet())
		a.put(key, TextParseUtil.translateVariables(dynamicAttributes.get(key), context.getStack()));
        super.start(name, a);
    }
{code}

*Suggested fix #2*

Or change org.apache.struts2.views.jsp.ui.AbstractUITag.setDynamicAttribute() so that it returns
an empty string if the expression evaluates to null:
{code:java|title=AbstractUITag.java}
    public void setDynamicAttribute(String uri, String localName, Object value) throws JspException
{
        if (ComponentUtils.altSyntax(getStack()) && ComponentUtils.isExpression(value))
{
            dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()),
"")));
        } else {
            dynamicAttributes.put(localName, value);
        }
    }
{code}
(but I have no idea on the possible side effects it could produce).


    
> With javatemplate, dynamic attribute value evaluates to expression text if null
> -------------------------------------------------------------------------------
>
>                 Key: WW-4036
>                 URL: https://issues.apache.org/jira/browse/WW-4036
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Java Templates
>    Affects Versions: 2.3.12
>            Reporter: Walid Ghafir
>         Attachments: placeholder.zip
>
>
> When using javatemplate plugin, if a dynamic attribute has an expression value that evaluates
to null, the full expression text is displayed instead of just an empty string.
> Example: 
> {code:html}
> <s:textfield placeholder="%{null}" name="%{null}"/> 
> {code}
> will output
> {code:html}
> <input type="text" placeholder="%{null}" name=""/> 
> {code}
> in the HTML.
> By debugging, I found it comes from AbstractUITag.setDynamicAttribute():
> {code:java}
> dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()),
value)));
> {code}
> That problem does not occur with FTL themes as dynamic-attributes.ftl uses TextParseUtil.translateVariables()
which does what the doc says ("If an item cannot be found on the stack (null is returned),
then the entire variable %\{...\} is not displayed, just as if the item was on the stack but
returned an empty string.").
> *Suggested fix #1*
> Change org.apache.struts2.views.java.simple.DynamicAttributesHandler.start() so that
it does the same than dynamic-attributes.ftl:
> {code:java|title=DynamicAttributesHandler.java}
>     @Override
>     public void start(String name, Attributes a) throws IOException {
> 	Map<String, String> dynamicAttributes = (Map<String, String>) context.getParameters().get("dynamicAttributes");
> 	for (String key : dynamicAttributes.keySet())
> 		a.put(key, TextParseUtil.translateVariables(dynamicAttributes.get(key), context.getStack()));
>         super.start(name, a);
>     }
> {code}
> *Suggested fix #2*
> Or change org.apache.struts2.views.jsp.ui.AbstractUITag.setDynamicAttribute() so that
it returns an empty string if the expression evaluates to null:
> {code:java|title=AbstractUITag.java}
>     public void setDynamicAttribute(String uri, String localName, Object value) throws
JspException {
>         if (ComponentUtils.altSyntax(getStack()) && ComponentUtils.isExpression(value))
{
>             dynamicAttributes.put(localName, String.valueOf(ObjectUtils.defaultIfNull(findValue(value.toString()),
"")));
>         } else {
>             dynamicAttributes.put(localName, value);
>         }
>     }
> {code}
> (but I have no idea on the possible side effects it could produce).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message