Issue Details (XML | Word | Printable)

Key: WW-1310
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: tm_jee
Reporter: tm_jee
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Struts 2

radiomap.ftl does not honour Boolean keys.

Created: 10/May/06 12:55 PM   Updated: 10/May/06 08:42 PM
Return to search
Component/s: Plugin - Tags
Affects Version/s: WW 2.2.2
Fix Version/s: 2.0.0


 Description  « Hide
Below is Jay email in SAF mailing list about this issue :-

----- Original Message ----
From: Jay H. Hartley <jay.hartley@modius.com>
To: dev@struts.apache.org
Sent: Wednesday, 10 May, 2006 7:46:39 AM
Subject: WW radiomap.ftl bug

I think I've found a bug in the WebWork 2.2.2 template 'radiomap.ftl' in the
simple theme. I have only just joined this list, so forgive me if this is
not going to be used in Struts Action 2.0, or there's a better place to post
this. A proposed patch is included at the end of this message.

The 'radiomap' template doesn't work if the provided list uses Boolean keys.
The 'select' template handles it, but radiomap doesn't. Just FYI, we chose a
radio control for this instead of a checkbox just because of the annoying
parameter-is-null-if-not-checked behavior. I know there are other ways to
address it with a checkbox, but... I'm not using them. Probably why this bug
never came up before, so maybe only I care.

JSP page:

<%@ taglib prefix="ww" uri="/webwork"%>
<ww:set name="enable_options"
    value="#{true: getText('option.enabled'), false:
getText('option.disabled')}"/>
<ww:form name="myForm" id="myForm" action="saveLdapConfig" method="post">
    <ww:radio name="enabled"
        label="%{getText('prompt.enabled')}"
        list="#enable_options"
        />
    ...
</ww:form>

=====================
Results in the following error message:

FreeMarker template error!

Error on line 12, column 79 in template/simple/radiomap.ftl
Expecting a string, date or number here, Expression itemKey is instead a
freemarker.ext.beans.BooleanModel
The problematic instruction:
----------
==&gt; ${itemKey?html} [on line 12, column 77 in
template/simple/radiomap.ftl]
in user-directive ww.iterator [on line 1, column 1 in
template/simple/radiomap.ftl]
in include "/${parameters.templateDir}/simple/radiomap.ftl" [on line 3,
column 1 in template/xhtml/radiomap.ftl]
----------

======================
I can provide the full Java stack trace, if anybody cares, but in looking at
'select.ftl', I think I found the solution.

The select template creates a variable 'itemKeyStr' and uses that anywhere
the string value is used, instead of the 'itemKey' directly. Apparently the
expression ${itemKey?html} doesn't work when itemKey is a Boolean.

I've gotten the above JSP to work by overriding
/template/simple/radiomap.ftl with the text following my signature. Changed
lines are commented.

I'd appreciate any feedback. Please be kind; it's my first post to this
list. :-)

Jay H. Hartley, Ph.D.
Senior Software Engineer/Architect
Modius, Inc.

======================
<@ww.iterator value="parameters.list">
    <#if parameters.listKey?exists>
        <#assign itemKey = stack.findValue(parameters.listKey)/>
    <#else>
        <#assign itemKey = stack.findValue('top')/>
    </#if>
<#--
    Create new variable itemKeyStr, like in select.ftl
-->
    <#assign itemKeyStr = itemKey.toString() />
    <#if parameters.listValue?exists>
        <#assign itemValue = stack.findString(parameters.listValue)/>
    <#else>
        <#assign itemValue = stack.findString('top')/>
    </#if>
<#--
    Use itemKeyStr?html for output instead of itemKey?html
-->
<input type="radio" name="${parameters.name?html}"
id="${parameters.id?html}${itemKeyStr?html}"<#rt/>
<#if tag.contains(parameters.nameValue, itemKey)>
checked="checked"<#rt/>
</#if>
<#--
    Use itemKeyStr?html for output instead of itemKey?html
-->
<#if itemKey?exists>
value="${itemKeyStr?html}"<#rt/>
</#if>
<#if parameters.disabled?default(false)>
disabled="disabled"<#rt/>
</#if>
<#if parameters.tabindex?exists>
tabindex="${parameters.tabindex?html}"<#rt/>
</#if>
<#if parameters.cssClass?exists>
class="${parameters.cssClass?html}"<#rt/>
</#if>
<#if parameters.cssStyle?exists>
style="${parameters.cssStyle?html}"<#rt/>
</#if>
<#if parameters.title?exists>
title="${parameters.title?html}"<#rt/>
</#if>
<#include "/${parameters.templateDir}/simple/scripting-events.ftl" />
/><#rt/>
<#--
    Use itemKeyStr?html for output instead of itemKey?html
-->
<label for="${parameters.id?html}${itemKeyStr?html}"><#rt/>
    ${itemValue}<#t/>
</label>
</@ww.iterator>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org

 All   Comments   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
tm_jee made changes - 10/May/06 12:59 PM
Field Original Value New Value
Component/s Views [ 20003 ]
Repository Revision Date User Message
Struts #405758 Wed May 10 13:34:28 UTC 2006 tmjee WW-1310
Files Changed
ADD /struts/action2/trunk/core/src/test/resources/org/apache/struts/action2/views/jsp/ui/Radio-3.txt
MODIFY /struts/action2/trunk/core/src/main/resources/template/simple/radiomap.ftl
MODIFY /struts/action2/trunk/core/src/test/java/org/apache/struts/action2/views/jsp/ui/RadioTest.java

tm_jee added a comment - 10/May/06 08:36 PM
fixed. changes are at :-

Sending src/main/resources/template/simple/radiomap.ftl
Sending src/test/java/org/apache/struts/action2/views/jsp/ui/RadioTest.java
Adding src/test/resources/org/apache/struts/action2/views/jsp/ui/Radio-3.txt

changed

<#if parameters.listKey?exists>
        <#assign itemKey = stack.findValue(parameters.listKey)/>
    <#else>
        <#assign itemKey = stack.findValue('top')/>
    </#if>

to

<#if parameters.listKey?exists>
        <#assign itemKey = stack.findString(parameters.listKey)/>
    <#else>
        <#assign itemKey = stack.findString('top')/>
    </#if>

such that Boolean etc. will be treadted as string

tm_jee made changes - 10/May/06 08:42 PM
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Don Brown made changes - 08/Jan/07 06:21 PM
Workflow jira [ 38365 ] Struts [ 40402 ]
Jeff Turner made changes - 09/Aug/07 07:17 AM
Workflow Struts [ 40402 ] Struts - editable closed status [ 42359 ]
Antonio Petrelli made changes - 08/Jan/09 08:57 AM
Workflow Struts - editable closed status [ 42359 ] Struts - editable closed status (temporary) [ 47164 ]
Antonio Petrelli made changes - 08/Jan/09 09:05 AM
Workflow Struts - editable closed status (temporary) [ 47164 ] Struts - editable closed status [ 50445 ]