[jira] [Commented] (WW-5145) Checkbox with multiple values do not default correctly

2022-10-14 Thread Lukasz Lenart (Jira)


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

Lukasz Lenart commented on WW-5145:
---

Checkbox tag was designed to work with {{Boolean}} so supporting 
{{List}}/{{Map}} can be a bit tricky. You can use 

{code:html}



{code}

which should do the trick.

Also you have a full control over the layout by overriding theme and you can 
just override one tag if you want.

> Checkbox with multiple values do not default correctly
> --
>
> Key: WW-5145
> URL: https://issues.apache.org/jira/browse/WW-5145
> Project: Struts 2
>  Issue Type: Bug
>  Components: Core Tags
>Affects Versions: 2.5.25
>Reporter: nikos dimitrakas
>Priority: Minor
>  Labels: checkbox
> Fix For: 6.1.0
>
>
> Using multiple s:checkbox (with the same name) together with a List (of 
> Integer or String, etc) does not preselect the right checkboxes. This 
> behaviour is inconsistent with all the other form components that get the 
> default values based on their name. I have constructed a simple example for 
> illustrating and testing. My actual case is more complex with dynamic data. 
> Action class:
> {code:java}
> public class TestAction extends ActionSupport {
>  private List number;
>  
> public List getNumber() {
>return number;
>   }
>  
> public void setNumber(List number) {
>this.number = number;
>  }
>  public String execute() {
>//Try with some default, empty list, null
>if (number == null) number = Collections.singletonList(2);
>return SUCCESS;
>   }
> }
> {code}
> JSP:
> {code:html}
> <%@ taglib prefix="s" uri="/struts-tags_rt" %>
> 
> 
> 
>  1 
>  2 
>  3 
>  4 
>  Push
> 
> 
> 
> {code}
> Action configuration:
> {code:xml}
> 
>   test.jsp
> 
> {code}
> One would expect that the checkboxes should be checked if the corresponding 
> value is in  the list. But instead all checkboxes get checked if the list is 
> not null (independent of its content). And all checkboxes are unchecked if 
> the list is null. Submitting the form after selecting some checkboxes does 
> send the values correctly to the action, but once again when rendering the 
> checkboxes, they all get checked if the list is not null.
> I can simply fix this by adding the value attribute with an expression to 
> each checkbox, but it feels like this should be the default behaviour:
> {code}
> 1 
> 2 
> 3 
> 4 
> {code}
> Another workaround is to use a Map and in that case all 
> checkboxes are checked and unchecked correctly, but it feels unnecessary 
> since every entry will always have value true and the only interesting part 
> of the map will be the keySet (which is essentially the list). But it is 
> interesting that the checkboxes behave as expected when using a Map, but not 
> when using a List.
> I am not really sure if this relates to WW-4865



--
This message was sent by Atlassian Jira
(v8.20.10#820010)


[jira] [Commented] (WW-5145) Checkbox with multiple values do not default correctly

2022-10-14 Thread nikos dimitrakas (Jira)


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

nikos dimitrakas commented on WW-5145:
--

Using s:checkboxlist does not give you the same freedom with layout. And even 
if s:checkboxlist would be an alternative in many cases, it does not motivate 
not fixing the behaviour of s:checkbox. The combination of "Won't fix" and Fix 
version "6.1.0" is a bit confusing.

> Checkbox with multiple values do not default correctly
> --
>
> Key: WW-5145
> URL: https://issues.apache.org/jira/browse/WW-5145
> Project: Struts 2
>  Issue Type: Bug
>  Components: Core Tags
>Affects Versions: 2.5.25
>Reporter: nikos dimitrakas
>Priority: Minor
>  Labels: checkbox
> Fix For: 6.1.0
>
>
> Using multiple s:checkbox (with the same name) together with a List (of 
> Integer or String, etc) does not preselect the right checkboxes. This 
> behaviour is inconsistent with all the other form components that get the 
> default values based on their name. I have constructed a simple example for 
> illustrating and testing. My actual case is more complex with dynamic data. 
> Action class:
> {code:java}
> public class TestAction extends ActionSupport {
>  private List number;
>  
> public List getNumber() {
>return number;
>   }
>  
> public void setNumber(List number) {
>this.number = number;
>  }
>  public String execute() {
>//Try with some default, empty list, null
>if (number == null) number = Collections.singletonList(2);
>return SUCCESS;
>   }
> }
> {code}
> JSP:
> {code:html}
> <%@ taglib prefix="s" uri="/struts-tags_rt" %>
> 
> 
> 
>  1 
>  2 
>  3 
>  4 
>  Push
> 
> 
> 
> {code}
> Action configuration:
> {code:xml}
> 
>   test.jsp
> 
> {code}
> One would expect that the checkboxes should be checked if the corresponding 
> value is in  the list. But instead all checkboxes get checked if the list is 
> not null (independent of its content). And all checkboxes are unchecked if 
> the list is null. Submitting the form after selecting some checkboxes does 
> send the values correctly to the action, but once again when rendering the 
> checkboxes, they all get checked if the list is not null.
> I can simply fix this by adding the value attribute with an expression to 
> each checkbox, but it feels like this should be the default behaviour:
> {code}
> 1 
> 2 
> 3 
> 4 
> {code}
> Another workaround is to use a Map and in that case all 
> checkboxes are checked and unchecked correctly, but it feels unnecessary 
> since every entry will always have value true and the only interesting part 
> of the map will be the keySet (which is essentially the list). But it is 
> interesting that the checkboxes behave as expected when using a Map, but not 
> when using a List.
> I am not really sure if this relates to WW-4865



--
This message was sent by Atlassian Jira
(v8.20.10#820010)