struts-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Lukasz Lenart (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (WW-1534) The value of checkbox getted in server-side is "false" when no any checkbox been selected.
Date Thu, 01 Jun 2017 06:07:04 GMT

    [ https://issues.apache.org/jira/browse/WW-1534?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16029600#comment-16029600
] 

Lukasz Lenart edited comment on WW-1534 at 6/1/17 6:06 AM:
-----------------------------------------------------------

No, this isn't solved by WW-2339. I guess the patch rev655721 mentioned in WW-2339 is now
the git commit 9a22985c1f6554b908df14e53cda32b41f1e33ec.

This patch does't distinguish between a single rendered checkbox with a certain name (often
used with boolean getter/setter in the action) and multiple rendered checkboxes with the same
name (often used with a list getter/setter (e.g. ids) in the action), but the latter actually
renders a single checkbox only.

This is the case if you e.g. iterate over a list and render a checkbox for every entry in
the list. If the list contains only a single entry, then you will get a single checkbox.

As a workaround a hidden div containing two additional checkboxes can be used to ensure that
there are more than one rendered checkboxes:

{code:html}
<div style="display:none;">
  <s:checkbox name="myIds" fieldValue="0" value="false"/>
  <s:checkbox name="myIds" fieldValue="0" value="false"/>
</div>
<s:iterator ...>
  <s:checkbox name="myIds" fieldValue="..." value="..."/>
</s:iterator>
{code}

I know that this is ugly, but I don't see a chance to get this distinguished in the interceptor.


was (Author: mars_pb):
No, this isn't solved by WW-2339. I guess the patch rev655721 mentioned in WW-2339 is now
the git commit 9a22985c1f6554b908df14e53cda32b41f1e33ec.

This patch does't distinguish between a single rendered checkbox with a certain name (often
used with boolean getter/setter in the action) and multiple rendered checkboxes with the same
name (often used with a list getter/setter (e.g. ids) in the action), but the latter actually
renders a single checkbox only.

This is the case if you e.g. iterate over a list and render a checkbox for every entry in
the list. If the list contains only a single entry, then you will get a single checkbox.

As a workaround a hidden div containing two additional checkboxes can be used to ensure that
there are more than one rendered checkboxes:

<div style="display:none;">
  <s:checkbox name="myIds" fieldValue="0" value="false"/>
  <s:checkbox name="myIds" fieldValue="0" value="false"/>
</div>
<s:iterator ...>
  <s:checkbox name="myIds" fieldValue="..." value="..."/>
</s:iterator>

I know that this is ugly, but I don't see a chance to get this distinguished in the interceptor.

> The value of checkbox getted in server-side is "false" when no any checkbox been selected.
> ------------------------------------------------------------------------------------------
>
>                 Key: WW-1534
>                 URL: https://issues.apache.org/jira/browse/WW-1534
>             Project: Struts 2
>          Issue Type: Improvement
>          Components: Value Stack
>    Affects Versions: 2.0.1
>         Environment: tomcat-5.5.20 / jdk1.5.0.08
>            Reporter: Ling Chang Ming
>             Fix For: 2.5.x
>
>
> jsp section:
> {code:xml}
> <s:iterator value="%{#request.rolePs.items}" id="role" status="status">
>    <tr >
>                 <td height="25" width="5%">
>                     <s:checkbox name="roleId" fieldValue="%{id}" theme="simple"/>
>                 </td>
>    </tr>
> ........
> </s:iterator>
> {code}
> action section:
> {code:java}
> ....
>        private String[] roleId;
> 	public String[] getRoleId() {
> 		return roleId;
> 	}
> 	public void setRoleId(String[] roleId) {
> 		this.roleId = roleId;
> 	}
> .....
> {code}
> the retrieved value of  "roleId" is {{false}}  when user doesn't select any checkbox
elements.  In my opinion, this case should returns null directly.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message