Struts2 Checkboxlist

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Struts2 Checkboxlist

Prasanth-2
Hi,

I am using a checkboxlist on a jsp page which corresponds to a ArrayList in the form class, which is used to store form data from a multi page wizard. I am using scope interceptor to store the form
class in session so that the data persists as the user navigates the wizard. When the user selects some check boxes it is correctly populated in the form class but if the user navigates back in the
wizard and unchecks the check box (non of the check boxes selected) struts doesn't set the ArrayList to empty. It will still contain the old selection. What is the best way to solve this issue?

My Options:
1. Should I use Preparable and set this ArrayList to empty? Since this is a wizard (multiple pages submitting to the same action) have to make sure it is done only when submitting the page that have
these checkboxes.
2. Create two separate ArrayLists, one to get values from Struts and another to save the original selection and clear the first array list. Down side is I need to populate the list linked to the form
when user navigates back to that page.

Neither of them seem elegant. Is there a way to make struts set the ArrayList to empty when user doesn't select any check box?

Using Struts 2.3.35

Thanks,
Prasanth
Reply | Threaded
Open this post in threaded view
|

Re: Struts2 Checkboxlist

Arjuna Bandara
Hi,

As I understand, you need to modify previous Array before saving.

Have you tried Session variable ?

Regards

Arjuna

On Sat, 2 Feb 2019 3:18 am Prasanth, <[hidden email]> wrote:

> Hi,
>
> I am using a checkboxlist on a jsp page which corresponds to a ArrayList
> in the form class, which is used to store form data from a multi page
> wizard. I am using scope interceptor to store the form
> class in session so that the data persists as the user navigates the
> wizard. When the user selects some check boxes it is correctly populated in
> the form class but if the user navigates back in the
> wizard and unchecks the check box (non of the check boxes selected) struts
> doesn't set the ArrayList to empty. It will still contain the old
> selection. What is the best way to solve this issue?
>
> My Options:
> 1. Should I use Preparable and set this ArrayList to empty? Since this is
> a wizard (multiple pages submitting to the same action) have to make sure
> it is done only when submitting the page that have
> these checkboxes.
> 2. Create two separate ArrayLists, one to get values from Struts and
> another to save the original selection and clear the first array list. Down
> side is I need to populate the list linked to the form
> when user navigates back to that page.
>
> Neither of them seem elegant. Is there a way to make struts set the
> ArrayList to empty when user doesn't select any check box?
>
> Using Struts 2.3.35
>
> Thanks,
> Prasanth
>
Reply | Threaded
Open this post in threaded view
|

Re: Struts2 Checkboxlist

Prasanth-2
The data class holding the array is in session, done using the scope interceptor.

Thanks
Prasanth

On February 1, 2019 9:30:30 PM CST, Arjuna Bandara <[hidden email]> wrote:

>Hi,
>
>As I understand, you need to modify previous Array before saving.
>
>Have you tried Session variable ?
>
>Regards
>
>Arjuna
>
>On Sat, 2 Feb 2019 3:18 am Prasanth, <[hidden email]> wrote:
>
>> Hi,
>>
>> I am using a checkboxlist on a jsp page which corresponds to a
>ArrayList
>> in the form class, which is used to store form data from a multi page
>> wizard. I am using scope interceptor to store the form
>> class in session so that the data persists as the user navigates the
>> wizard. When the user selects some check boxes it is correctly
>populated in
>> the form class but if the user navigates back in the
>> wizard and unchecks the check box (non of the check boxes selected)
>struts
>> doesn't set the ArrayList to empty. It will still contain the old
>> selection. What is the best way to solve this issue?
>>
>> My Options:
>> 1. Should I use Preparable and set this ArrayList to empty? Since
>this is
>> a wizard (multiple pages submitting to the same action) have to make
>sure
>> it is done only when submitting the page that have
>> these checkboxes.
>> 2. Create two separate ArrayLists, one to get values from Struts and
>> another to save the original selection and clear the first array
>list. Down
>> side is I need to populate the list linked to the form
>> when user navigates back to that page.
>>
>> Neither of them seem elegant. Is there a way to make struts set the
>> ArrayList to empty when user doesn't select any check box?
>>
>> Using Struts 2.3.35
>>
>> Thanks,
>> Prasanth
>>
Reply | Threaded
Open this post in threaded view
|

RE: Struts2 Checkboxlist

Yasser Zamani-2
In reply to this post by Prasanth-2
Hi Prasanth,

AFAIK this tag is like this:

<s:checkboxlist name="foo" list="bar" value="baz"/>

It calls getBar method of your action or finds bar in value stack to find out what to display. Same for baz to find out which to be selected. Then it calls yourAction.setFoo to post selected items. i.e. it is up to you what you do with it in setFoo method. Normally you should clear baz and fill it with them again to update selected items.

Thanks for using Struts!

Kind Regards.

>-----Original Message-----
>From: Prasanth <[hidden email]>
>Sent: Saturday, February 2, 2019 1:08 AM
>To: [hidden email]
>Subject: Struts2 Checkboxlist
>
>Hi,
>
>I am using a checkboxlist on a jsp page which corresponds to a ArrayList in the
>form class, which is used to store form data from a multi page wizard. I am using
>scope interceptor to store the form class in session so that the data persists as
>the user navigates the wizard. When the user selects some check boxes it is
>correctly populated in the form class but if the user navigates back in the wizard
>and unchecks the check box (non of the check boxes selected) struts doesn't set
>the ArrayList to empty. It will still contain the old selection. What is the best way
>to solve this issue?
>
>My Options:
>1. Should I use Preparable and set this ArrayList to empty? Since this is a wizard
>(multiple pages submitting to the same action) have to make sure it is done only
>when submitting the page that have these checkboxes.
>2. Create two separate ArrayLists, one to get values from Struts and another to
>save the original selection and clear the first array list. Down side is I need to
>populate the list linked to the form when user navigates back to that page.
>
>Neither of them seem elegant. Is there a way to make struts set the ArrayList to
>empty when user doesn't select any check box?
>
>Using Struts 2.3.35
>
>Thanks,
>Prasanth

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

RE: Struts2 Checkboxlist

Prasanth Pasala
Hi Yasser,

When none of the checkboxes is selected the setFoo is not getting called.

Thanks
Prasanth

On February 2, 2019 8:02:07 AM CST, Yasser Zamani <[hidden email]> wrote:

>Hi Prasanth,
>
>AFAIK this tag is like this:
>
><s:checkboxlist name="foo" list="bar" value="baz"/>
>
>It calls getBar method of your action or finds bar in value stack to
>find out what to display. Same for baz to find out which to be
>selected. Then it calls yourAction.setFoo to post selected items. i.e.
>it is up to you what you do with it in setFoo method. Normally you
>should clear baz and fill it with them again to update selected items.
>
>Thanks for using Struts!
>
>Kind Regards.
>
>>-----Original Message-----
>>From: Prasanth <[hidden email]>
>>Sent: Saturday, February 2, 2019 1:08 AM
>>To: [hidden email]
>>Subject: Struts2 Checkboxlist
>>
>>Hi,
>>
>>I am using a checkboxlist on a jsp page which corresponds to a
>ArrayList in the
>>form class, which is used to store form data from a multi page wizard.
>I am using
>>scope interceptor to store the form class in session so that the data
>persists as
>>the user navigates the wizard. When the user selects some check boxes
>it is
>>correctly populated in the form class but if the user navigates back
>in the wizard
>>and unchecks the check box (non of the check boxes selected) struts
>doesn't set
>>the ArrayList to empty. It will still contain the old selection. What
>is the best way
>>to solve this issue?
>>
>>My Options:
>>1. Should I use Preparable and set this ArrayList to empty? Since this
>is a wizard
>>(multiple pages submitting to the same action) have to make sure it is
>done only
>>when submitting the page that have these checkboxes.
>>2. Create two separate ArrayLists, one to get values from Struts and
>another to
>>save the original selection and clear the first array list. Down side
>is I need to
>>populate the list linked to the form when user navigates back to that
>page.
>>
>>Neither of them seem elegant. Is there a way to make struts set the
>ArrayList to
>>empty when user doesn't select any check box?
>>
>>Using Struts 2.3.35
>>
>>Thanks,
>>Prasanth
>
>---------------------------------------------------------------------
>To unsubscribe, e-m

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Reply | Threaded
Open this post in threaded view
|

Re: Struts2 Checkboxlist

Prasanth Pasala
Is that how Struts2 is expected to work? Meaning setFoo would not be called if non of the Foo checkboxes are selected? I know that is how Struts1 worked.

Thanks,
Prasanth

On 2/2/19 7:08 PM, Prasanth Pasala wrote:

> Hi Yasser,
>
> When none of the checkboxes is selected the setFoo is not getting called.
>
> Thanks
> Prasanth
>
> On February 2, 2019 8:02:07 AM CST, Yasser Zamani <[hidden email]> wrote:
>> Hi Prasanth,
>>
>> AFAIK this tag is like this:
>>
>> <s:checkboxlist name="foo" list="bar" value="baz"/>
>>
>> It calls getBar method of your action or finds bar in value stack to
>> find out what to display. Same for baz to find out which to be
>> selected. Then it calls yourAction.setFoo to post selected items. i.e.
>> it is up to you what you do with it in setFoo method. Normally you
>> should clear baz and fill it with them again to update selected items.
>>
>> Thanks for using Struts!
>>
>> Kind Regards.
>>
>>> -----Original Message-----
>>> From: Prasanth <[hidden email]>
>>> Sent: Saturday, February 2, 2019 1:08 AM
>>> To: [hidden email]
>>> Subject: Struts2 Checkboxlist
>>>
>>> Hi,
>>>
>>> I am using a checkboxlist on a jsp page which corresponds to a
>> ArrayList in the
>>> form class, which is used to store form data from a multi page wizard.
>> I am using
>>> scope interceptor to store the form class in session so that the data
>> persists as
>>> the user navigates the wizard. When the user selects some check boxes
>> it is
>>> correctly populated in the form class but if the user navigates back
>> in the wizard
>>> and unchecks the check box (non of the check boxes selected) struts
>> doesn't set
>>> the ArrayList to empty. It will still contain the old selection. What
>> is the best way
>>> to solve this issue?
>>>
>>> My Options:
>>> 1. Should I use Preparable and set this ArrayList to empty? Since this
>> is a wizard
>>> (multiple pages submitting to the same action) have to make sure it is
>> done only
>>> when submitting the page that have these checkboxes.
>>> 2. Create two separate ArrayLists, one to get values from Struts and
>> another to
>>> save the original selection and clear the first array list. Down side
>> is I need to
>>> populate the list linked to the form when user navigates back to that
>> page.
>>> Neither of them seem elegant. Is there a way to make struts set the
>> ArrayList to
>>> empty when user doesn't select any check box?
>>>
>>> Using Struts 2.3.35
>>>
>>> Thanks,
>>> Prasanth
>> ---------------------------------------------------------------------
>> To unsubscribe, e-m

Reply | Threaded
Open this post in threaded view
|

RE: Struts2 Checkboxlist

Paul Zepernick
Yes, setFoo is only called if the checkbox is checked.  However, Struts 2 does have a checkbox interceptor: https://struts.apache.org/core-developers/checkbox-interceptor.html

This interceptor defaults checkbox Boolean's to False if the box is not checked.  This is part of the default interceptor stack.

Paul

-----Original Message-----
From: Prasanth Pasala <[hidden email]>
Sent: Monday, February 4, 2019 5:21 PM
To: [hidden email]
Subject: Re: Struts2 Checkboxlist

NOTICE: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.

Is that how Struts2 is expected to work? Meaning setFoo would not be called if non of the Foo checkboxes are selected? I know that is how Struts1 worked.

Thanks,
Prasanth

On 2/2/19 7:08 PM, Prasanth Pasala wrote:

> Hi Yasser,
>
> When none of the checkboxes is selected the setFoo is not getting called.
>
> Thanks
> Prasanth
>
> On February 2, 2019 8:02:07 AM CST, Yasser Zamani <[hidden email]> wrote:
>> Hi Prasanth,
>>
>> AFAIK this tag is like this:
>>
>> <s:checkboxlist name="foo" list="bar" value="baz"/>
>>
>> It calls getBar method of your action or finds bar in value stack to
>> find out what to display. Same for baz to find out which to be
>> selected. Then it calls yourAction.setFoo to post selected items. i.e.
>> it is up to you what you do with it in setFoo method. Normally you
>> should clear baz and fill it with them again to update selected items.
>>
>> Thanks for using Struts!
>>
>> Kind Regards.
>>
>>> -----Original Message-----
>>> From: Prasanth <[hidden email]>
>>> Sent: Saturday, February 2, 2019 1:08 AM
>>> To: [hidden email]
>>> Subject: Struts2 Checkboxlist
>>>
>>> Hi,
>>>
>>> I am using a checkboxlist on a jsp page which corresponds to a
>> ArrayList in the
>>> form class, which is used to store form data from a multi page wizard.
>> I am using
>>> scope interceptor to store the form class in session so that the
>>> data
>> persists as
>>> the user navigates the wizard. When the user selects some check
>>> boxes
>> it is
>>> correctly populated in the form class but if the user navigates back
>> in the wizard
>>> and unchecks the check box (non of the check boxes selected) struts
>> doesn't set
>>> the ArrayList to empty. It will still contain the old selection.
>>> What
>> is the best way
>>> to solve this issue?
>>>
>>> My Options:
>>> 1. Should I use Preparable and set this ArrayList to empty? Since
>>> this
>> is a wizard
>>> (multiple pages submitting to the same action) have to make sure it
>>> is
>> done only
>>> when submitting the page that have these checkboxes.
>>> 2. Create two separate ArrayLists, one to get values from Struts and
>> another to
>>> save the original selection and clear the first array list. Down
>>> side
>> is I need to
>>> populate the list linked to the form when user navigates back to
>>> that
>> page.
>>> Neither of them seem elegant. Is there a way to make struts set the
>> ArrayList to
>>> empty when user doesn't select any check box?
>>>
>>> Using Struts 2.3.35
>>>
>>> Thanks,
>>> Prasanth
>> ---------------------------------------------------------------------
>> To unsubscribe, e-m

Disclaimer: This communication and any files transmitted with it may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this communication in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Struts2 Checkboxlist

Prasanth Pasala
I am using the defaultStack but the ArrayList used for the checkboxes is of type Long. If we change it to ArrayList of Boolean would the interceptor set the values to false? Or is this only applicable
if you have individual checkboxes rather than checkboxlist?

Thanks,
Prasanth

On 2/4/19 4:29 PM, Paul Zepernick wrote:

> Yes, setFoo is only called if the checkbox is checked.  However, Struts 2 does have a checkbox interceptor: https://struts.apache.org/core-developers/checkbox-interceptor.html
>
> This interceptor defaults checkbox Boolean's to False if the box is not checked.  This is part of the default interceptor stack.
>
> Paul
>
> -----Original Message-----
> From: Prasanth Pasala <[hidden email]>
> Sent: Monday, February 4, 2019 5:21 PM
> To: [hidden email]
> Subject: Re: Struts2 Checkboxlist
>
> NOTICE: This email originated from outside of the organization. Do not click links or open attachments unless you recognize the sender and know the content is safe.
>
> Is that how Struts2 is expected to work? Meaning setFoo would not be called if non of the Foo checkboxes are selected? I know that is how Struts1 worked.
>
> Thanks,
> Prasanth
>
> On 2/2/19 7:08 PM, Prasanth Pasala wrote:
>> Hi Yasser,
>>
>> When none of the checkboxes is selected the setFoo is not getting called.
>>
>> Thanks
>> Prasanth
>>
>> On February 2, 2019 8:02:07 AM CST, Yasser Zamani <[hidden email]> wrote:
>>> Hi Prasanth,
>>>
>>> AFAIK this tag is like this:
>>>
>>> <s:checkboxlist name="foo" list="bar" value="baz"/>
>>>
>>> It calls getBar method of your action or finds bar in value stack to
>>> find out what to display. Same for baz to find out which to be
>>> selected. Then it calls yourAction.setFoo to post selected items. i.e.
>>> it is up to you what you do with it in setFoo method. Normally you
>>> should clear baz and fill it with them again to update selected items.
>>>
>>> Thanks for using Struts!
>>>
>>> Kind Regards.
>>>
>>>> -----Original Message-----
>>>> From: Prasanth <[hidden email]>
>>>> Sent: Saturday, February 2, 2019 1:08 AM
>>>> To: [hidden email]
>>>> Subject: Struts2 Checkboxlist
>>>>
>>>> Hi,
>>>>
>>>> I am using a checkboxlist on a jsp page which corresponds to a
>>> ArrayList in the
>>>> form class, which is used to store form data from a multi page wizard.
>>> I am using
>>>> scope interceptor to store the form class in session so that the
>>>> data
>>> persists as
>>>> the user navigates the wizard. When the user selects some check
>>>> boxes
>>> it is
>>>> correctly populated in the form class but if the user navigates back
>>> in the wizard
>>>> and unchecks the check box (non of the check boxes selected) struts
>>> doesn't set
>>>> the ArrayList to empty. It will still contain the old selection.
>>>> What
>>> is the best way
>>>> to solve this issue?
>>>>
>>>> My Options:
>>>> 1. Should I use Preparable and set this ArrayList to empty? Since
>>>> this
>>> is a wizard
>>>> (multiple pages submitting to the same action) have to make sure it
>>>> is
>>> done only
>>>> when submitting the page that have these checkboxes.
>>>> 2. Create two separate ArrayLists, one to get values from Struts and
>>> another to
>>>> save the original selection and clear the first array list. Down
>>>> side
>>> is I need to
>>>> populate the list linked to the form when user navigates back to
>>>> that
>>> page.
>>>> Neither of them seem elegant. Is there a way to make struts set the
>>> ArrayList to
>>>> empty when user doesn't select any check box?
>>>>
>>>> Using Struts 2.3.35
>>>>
>>>> Thanks,
>>>> Prasanth
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-m
> Disclaimer: This communication and any files transmitted with it may contain information that is privileged, confidential and/or exempt from disclosure under applicable law. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution, or use of the information contained herein (including any reliance thereon) is strictly prohibited. If you received this communication in error, please immediately contact the sender and destroy the material in its entirety, whether in electronic or hard copy format. Thank you.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

Reply | Threaded
Open this post in threaded view
|

RE: Struts2 Checkboxlist

Yasser Zamani-2
Hi Prasanth,

Yes, I think. Now I can recall a long discussion about this at [1]. i.e. you also can keep array list of long but override the interceptor like below [2]:

<action name="ListConverterTest" class="com.afs.ListConverterTestAction">
<interceptor-ref name="defaultStack">
<param name="checkbox.uncheckedValue">-1</param>
</interceptor-ref>

Kind Regards.

[1] https://github.com/apache/struts/pull/169
[2] https://github.com/apache/struts/pull/169#issuecomment-352999309


>-----Original Message-----
>From: Prasanth Pasala <[hidden email]>
>Sent: Tuesday, February 5, 2019 3:26 AM
>To: [hidden email]
>Subject: Re: Struts2 Checkboxlist
>
>I am using the defaultStack but the ArrayList used for the checkboxes is of type
>Long. If we change it to ArrayList of Boolean would the interceptor set the values
>to false? Or is this only applicable if you have individual checkboxes rather than
>checkboxlist?
>
>Thanks,
>Prasanth
>
>On 2/4/19 4:29 PM, Paul Zepernick wrote:
>> Yes, setFoo is only called if the checkbox is checked.  However,
>> Struts 2 does have a checkbox interceptor:
>> https://struts.apache.org/core-developers/checkbox-interceptor.html
>>
>> This interceptor defaults checkbox Boolean's to False if the box is not checked.
>This is part of the default interceptor stack.
>>
>> Paul
>>
>> -----Original Message-----
>> From: Prasanth Pasala <[hidden email]>
>> Sent: Monday, February 4, 2019 5:21 PM
>> To: [hidden email]
>> Subject: Re: Struts2 Checkboxlist
>>
>> NOTICE: This email originated from outside of the organization. Do not click
>links or open attachments unless you recognize the sender and know the content
>is safe.
>>
>> Is that how Struts2 is expected to work? Meaning setFoo would not be called if
>non of the Foo checkboxes are selected? I know that is how Struts1 worked.
>>
>> Thanks,
>> Prasanth
>>
>> On 2/2/19 7:08 PM, Prasanth Pasala wrote:
>>> Hi Yasser,
>>>
>>> When none of the checkboxes is selected the setFoo is not getting called.
>>>
>>> Thanks
>>> Prasanth
>>>
>>> On February 2, 2019 8:02:07 AM CST, Yasser Zamani
><[hidden email]> wrote:
>>>> Hi Prasanth,
>>>>
>>>> AFAIK this tag is like this:
>>>>
>>>> <s:checkboxlist name="foo" list="bar" value="baz"/>
>>>>
>>>> It calls getBar method of your action or finds bar in value stack to
>>>> find out what to display. Same for baz to find out which to be
>>>> selected. Then it calls yourAction.setFoo to post selected items. i.e.
>>>> it is up to you what you do with it in setFoo method. Normally you
>>>> should clear baz and fill it with them again to update selected items.
>>>>
>>>> Thanks for using Struts!
>>>>
>>>> Kind Regards.
>>>>
>>>>> -----Original Message-----
>>>>> From: Prasanth <[hidden email]>
>>>>> Sent: Saturday, February 2, 2019 1:08 AM
>>>>> To: [hidden email]
>>>>> Subject: Struts2 Checkboxlist
>>>>>
>>>>> Hi,
>>>>>
>>>>> I am using a checkboxlist on a jsp page which corresponds to a
>>>> ArrayList in the
>>>>> form class, which is used to store form data from a multi page wizard.
>>>> I am using
>>>>> scope interceptor to store the form class in session so that the
>>>>> data
>>>> persists as
>>>>> the user navigates the wizard. When the user selects some check
>>>>> boxes
>>>> it is
>>>>> correctly populated in the form class but if the user navigates
>>>>> back
>>>> in the wizard
>>>>> and unchecks the check box (non of the check boxes selected) struts
>>>> doesn't set
>>>>> the ArrayList to empty. It will still contain the old selection.
>>>>> What
>>>> is the best way
>>>>> to solve this issue?
>>>>>
>>>>> My Options:
>>>>> 1. Should I use Preparable and set this ArrayList to empty? Since
>>>>> this
>>>> is a wizard
>>>>> (multiple pages submitting to the same action) have to make sure it
>>>>> is
>>>> done only
>>>>> when submitting the page that have these checkboxes.
>>>>> 2. Create two separate ArrayLists, one to get values from Struts
>>>>> and
>>>> another to
>>>>> save the original selection and clear the first array list. Down
>>>>> side
>>>> is I need to
>>>>> populate the list linked to the form when user navigates back to
>>>>> that
>>>> page.
>>>>> Neither of them seem elegant. Is there a way to make struts set the
>>>> ArrayList to
>>>>> empty when user doesn't select any check box?
>>>>>
>>>>> Using Struts 2.3.35
>>>>>
>>>>> Thanks,
>>>>> Prasanth
>>>> --------------------------------------------------------------------
>>>> -
>>>> To unsubscribe, e-m
>> Disclaimer: This communication and any files transmitted with it may contain
>information that is privileged, confidential and/or exempt from disclosure under
>applicable law. If you are not the intended recipient, you are hereby notified that
>any disclosure, copying, distribution, or use of the information contained herein
>(including any reliance thereon) is strictly prohibited. If you received this
>communication in error, please immediately contact the sender and destroy the
>material in its entirety, whether in electronic or hard copy format. Thank you.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Struts2 Checkboxlist

Prasanth Pasala
Hi Yasser,

Even after having the param the ArrayList<Long> was not populated with -1 for unchecked checkboxes. The ArrayList<Long> is in form. The set method in the form is not getting called when I don't check
any of the checkboxes. I am using a checkboxlist rather than individual checkboxes.

            <interceptor-ref name="scope">
                <param name="key"></param>
                <param name="session">form</param>
            </interceptor-ref>    
            <interceptor-ref name="defaultStack">     
                <param name="checkbox.uncheckedValue">-1</param>
            </interceptor-ref>


Thanks,
Prasanth

On 2/5/19 5:43 AM, Yasser Zamani wrote:

> Hi Prasanth,
>
> Yes, I think. Now I can recall a long discussion about this at [1]. i.e. you also can keep array list of long but override the interceptor like below [2]:
>
> <action name="ListConverterTest" class="com.afs.ListConverterTestAction">
> <interceptor-ref name="defaultStack">
> <param name="checkbox.uncheckedValue">-1</param>
> </interceptor-ref>
>
> Kind Regards.
>
> [1] https://github.com/apache/struts/pull/169
> [2] https://github.com/apache/struts/pull/169#issuecomment-352999309
>
>
>> -----Original Message-----
>> From: Prasanth Pasala <[hidden email]>
>> Sent: Tuesday, February 5, 2019 3:26 AM
>> To: [hidden email]
>> Subject: Re: Struts2 Checkboxlist
>>
>> I am using the defaultStack but the ArrayList used for the checkboxes is of type
>> Long. If we change it to ArrayList of Boolean would the interceptor set the values
>> to false? Or is this only applicable if you have individual checkboxes rather than
>> checkboxlist?
>>
>> Thanks,
>> Prasanth
>>
>> On 2/4/19 4:29 PM, Paul Zepernick wrote:
>>> Yes, setFoo is only called if the checkbox is checked.  However,
>>> Struts 2 does have a checkbox interceptor:
>>> https://struts.apache.org/core-developers/checkbox-interceptor.html
>>>
>>> This interceptor defaults checkbox Boolean's to False if the box is not checked.
>> This is part of the default interceptor stack.
>>> Paul
>>>
>>> -----Original Message-----
>>> From: Prasanth Pasala <[hidden email]>
>>> Sent: Monday, February 4, 2019 5:21 PM
>>> To: [hidden email]
>>> Subject: Re: Struts2 Checkboxlist
>>>
>>> NOTICE: This email originated from outside of the organization. Do not click
>> links or open attachments unless you recognize the sender and know the content
>> is safe.
>>> Is that how Struts2 is expected to work? Meaning setFoo would not be called if
>> non of the Foo checkboxes are selected? I know that is how Struts1 worked.
>>> Thanks,
>>> Prasanth
>>>
>>> On 2/2/19 7:08 PM, Prasanth Pasala wrote:
>>>> Hi Yasser,
>>>>
>>>> When none of the checkboxes is selected the setFoo is not getting called.
>>>>
>>>> Thanks
>>>> Prasanth
>>>>
>>>> On February 2, 2019 8:02:07 AM CST, Yasser Zamani
>> <[hidden email]> wrote:
>>>>> Hi Prasanth,
>>>>>
>>>>> AFAIK this tag is like this:
>>>>>
>>>>> <s:checkboxlist name="foo" list="bar" value="baz"/>
>>>>>
>>>>> It calls getBar method of your action or finds bar in value stack to
>>>>> find out what to display. Same for baz to find out which to be
>>>>> selected. Then it calls yourAction.setFoo to post selected items. i.e.
>>>>> it is up to you what you do with it in setFoo method. Normally you
>>>>> should clear baz and fill it with them again to update selected items.
>>>>>
>>>>> Thanks for using Struts!
>>>>>
>>>>> Kind Regards.
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Prasanth <[hidden email]>
>>>>>> Sent: Saturday, February 2, 2019 1:08 AM
>>>>>> To: [hidden email]
>>>>>> Subject: Struts2 Checkboxlist
>>>>>>
>>>>>> Hi,
>>>>>>
>>>>>> I am using a checkboxlist on a jsp page which corresponds to a
>>>>> ArrayList in the
>>>>>> form class, which is used to store form data from a multi page wizard.
>>>>> I am using
>>>>>> scope interceptor to store the form class in session so that the
>>>>>> data
>>>>> persists as
>>>>>> the user navigates the wizard. When the user selects some check
>>>>>> boxes
>>>>> it is
>>>>>> correctly populated in the form class but if the user navigates
>>>>>> back
>>>>> in the wizard
>>>>>> and unchecks the check box (non of the check boxes selected) struts
>>>>> doesn't set
>>>>>> the ArrayList to empty. It will still contain the old selection.
>>>>>> What
>>>>> is the best way
>>>>>> to solve this issue?
>>>>>>
>>>>>> My Options:
>>>>>> 1. Should I use Preparable and set this ArrayList to empty? Since
>>>>>> this
>>>>> is a wizard
>>>>>> (multiple pages submitting to the same action) have to make sure it
>>>>>> is
>>>>> done only
>>>>>> when submitting the page that have these checkboxes.
>>>>>> 2. Create two separate ArrayLists, one to get values from Struts
>>>>>> and
>>>>> another to
>>>>>> save the original selection and clear the first array list. Down
>>>>>> side
>>>>> is I need to
>>>>>> populate the list linked to the form when user navigates back to
>>>>>> that
>>>>> page.
>>>>>> Neither of them seem elegant. Is there a way to make struts set the
>>>>> ArrayList to
>>>>>> empty when user doesn't select any check box?
>>>>>>
>>>>>> Using Struts 2.3.35
>>>>>>
>>>>>> Thanks,
>>>>>> Prasanth
>>>>> --------------------------------------------------------------------
>>>>> -
>>>>> To unsubscribe, e-m
>>> Disclaimer: This communication and any files transmitted with it may contain
>> information that is privileged, confidential and/or exempt from disclosure under
>> applicable law. If you are not the intended recipient, you are hereby notified that
>> any disclosure, copying, distribution, or use of the information contained herein
>> (including any reliance thereon) is strictly prohibited. If you received this
>> communication in error, please immediately contact the sender and destroy the
>> material in its entirety, whether in electronic or hard copy format. Thank you.
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

Reply | Threaded
Open this post in threaded view
|

RE: Struts2 Checkboxlist

Yasser Zamani-2
Ach! Sorry, you're right. For checkbox list it's MultiselectInterceptor class which handles this and here it works with following config:

        List<Long> selectedLongs= new ArrayList<>();
        public List<Long> getLongs(){
                List<Long> longs= new ArrayList<>();
                longs.add(0L);
                longs.add(1L);
                return longs;
        }
        public void setSelectedLongs(List<Long> selectedLongs){
                this.selectedLongs = selectedLongs;
        }
        public List<Long> getSelectedLongs(){
                return selectedLongs;
        }

                                <s:checkboxlist
                                                tooltip="longs test"
                                                label="Longs Test"
                                                list="longs"
                                                name="selectedLongs"
                                value="selectedLongs"/>

        <action name="exampleSubmit" class="org.apache.struts2.showcase.UITagExample" method="doSubmit">
        <result>/WEB-INF/tags/ui/exampleSubmited.jsp</result>
        <result name="input">/WEB-INF/tags/ui/example.jsp</result>
        </action>


When I post an empty form, MultiselectInterceptor adds an empty string for selectedLongs http param, then Struts internal conversion converts it to an empty instance of List<Long>, then setSelectedLongs will be called here with it.

Regards.

>-----Original Message-----
>From: Prasanth Pasala <[hidden email]>
>Sent: Wednesday, February 6, 2019 12:30 AM
>To: [hidden email]
>Subject: Re: Struts2 Checkboxlist
>
>Hi Yasser,
>
>Even after having the param the ArrayList<Long> was not populated with -1 for
>unchecked checkboxes. The ArrayList<Long> is in form. The set method in the
>form is not getting called when I don't check any of the checkboxes. I am using a
>checkboxlist rather than individual checkboxes.
>
>            <interceptor-ref name="scope">
>                <param name="key"></param>
>                <param name="session">form</param>
>            </interceptor-ref>
>            <interceptor-ref name="defaultStack">
>                <param name="checkbox.uncheckedValue">-1</param>
>            </interceptor-ref>
>
>
>Thanks,
>Prasanth
>
>On 2/5/19 5:43 AM, Yasser Zamani wrote:
>> Hi Prasanth,
>>
>> Yes, I think. Now I can recall a long discussion about this at [1]. i.e. you also can
>keep array list of long but override the interceptor like below [2]:
>>
>> <action name="ListConverterTest"
>> class="com.afs.ListConverterTestAction">
>> <interceptor-ref name="defaultStack">
>> <param name="checkbox.uncheckedValue">-1</param>
>> </interceptor-ref>
>>
>> Kind Regards.
>>
>> [1] https://github.com/apache/struts/pull/169
>> [2] https://github.com/apache/struts/pull/169#issuecomment-352999309
>>
>>
>>> -----Original Message-----
>>> From: Prasanth Pasala <[hidden email]>
>>> Sent: Tuesday, February 5, 2019 3:26 AM
>>> To: [hidden email]
>>> Subject: Re: Struts2 Checkboxlist
>>>
>>> I am using the defaultStack but the ArrayList used for the checkboxes
>>> is of type Long. If we change it to ArrayList of Boolean would the
>>> interceptor set the values to false? Or is this only applicable if
>>> you have individual checkboxes rather than checkboxlist?
>>>
>>> Thanks,
>>> Prasanth
>>>
>>> On 2/4/19 4:29 PM, Paul Zepernick wrote:
>>>> Yes, setFoo is only called if the checkbox is checked.  However,
>>>> Struts 2 does have a checkbox interceptor:
>>>> https://struts.apache.org/core-developers/checkbox-interceptor.html
>>>>
>>>> This interceptor defaults checkbox Boolean's to False if the box is not
>checked.
>>> This is part of the default interceptor stack.
>>>> Paul
>>>>
>>>> -----Original Message-----
>>>> From: Prasanth Pasala <[hidden email]>
>>>> Sent: Monday, February 4, 2019 5:21 PM
>>>> To: [hidden email]
>>>> Subject: Re: Struts2 Checkboxlist
>>>>
>>>> NOTICE: This email originated from outside of the organization. Do
>>>> not click
>>> links or open attachments unless you recognize the sender and know
>>> the content is safe.
>>>> Is that how Struts2 is expected to work? Meaning setFoo would not be
>>>> called if
>>> non of the Foo checkboxes are selected? I know that is how Struts1 worked.
>>>> Thanks,
>>>> Prasanth
>>>>
>>>> On 2/2/19 7:08 PM, Prasanth Pasala wrote:
>>>>> Hi Yasser,
>>>>>
>>>>> When none of the checkboxes is selected the setFoo is not getting called.
>>>>>
>>>>> Thanks
>>>>> Prasanth
>>>>>
>>>>> On February 2, 2019 8:02:07 AM CST, Yasser Zamani
>>> <[hidden email]> wrote:
>>>>>> Hi Prasanth,
>>>>>>
>>>>>> AFAIK this tag is like this:
>>>>>>
>>>>>> <s:checkboxlist name="foo" list="bar" value="baz"/>
>>>>>>
>>>>>> It calls getBar method of your action or finds bar in value stack
>>>>>> to find out what to display. Same for baz to find out which to be
>>>>>> selected. Then it calls yourAction.setFoo to post selected items. i.e.
>>>>>> it is up to you what you do with it in setFoo method. Normally you
>>>>>> should clear baz and fill it with them again to update selected items.
>>>>>>
>>>>>> Thanks for using Struts!
>>>>>>
>>>>>> Kind Regards.
>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Prasanth <[hidden email]>
>>>>>>> Sent: Saturday, February 2, 2019 1:08 AM
>>>>>>> To: [hidden email]
>>>>>>> Subject: Struts2 Checkboxlist
>>>>>>>
>>>>>>> Hi,
>>>>>>>
>>>>>>> I am using a checkboxlist on a jsp page which corresponds to a
>>>>>> ArrayList in the
>>>>>>> form class, which is used to store form data from a multi page wizard.
>>>>>> I am using
>>>>>>> scope interceptor to store the form class in session so that the
>>>>>>> data
>>>>>> persists as
>>>>>>> the user navigates the wizard. When the user selects some check
>>>>>>> boxes
>>>>>> it is
>>>>>>> correctly populated in the form class but if the user navigates
>>>>>>> back
>>>>>> in the wizard
>>>>>>> and unchecks the check box (non of the check boxes selected)
>>>>>>> struts
>>>>>> doesn't set
>>>>>>> the ArrayList to empty. It will still contain the old selection.
>>>>>>> What
>>>>>> is the best way
>>>>>>> to solve this issue?
>>>>>>>
>>>>>>> My Options:
>>>>>>> 1. Should I use Preparable and set this ArrayList to empty? Since
>>>>>>> this
>>>>>> is a wizard
>>>>>>> (multiple pages submitting to the same action) have to make sure
>>>>>>> it is
>>>>>> done only
>>>>>>> when submitting the page that have these checkboxes.
>>>>>>> 2. Create two separate ArrayLists, one to get values from Struts
>>>>>>> and
>>>>>> another to
>>>>>>> save the original selection and clear the first array list. Down
>>>>>>> side
>>>>>> is I need to
>>>>>>> populate the list linked to the form when user navigates back to
>>>>>>> that
>>>>>> page.
>>>>>>> Neither of them seem elegant. Is there a way to make struts set
>>>>>>> the
>>>>>> ArrayList to
>>>>>>> empty when user doesn't select any check box?
>>>>>>>
>>>>>>> Using Struts 2.3.35
>>>>>>>
>>>>>>> Thanks,
>>>>>>> Prasanth
>>>>>> ------------------------------------------------------------------
>>>>>> --
>>>>>> -
>>>>>> To unsubscribe, e-m
>>>> Disclaimer: This communication and any files transmitted with it may
>>>> contain
>>> information that is privileged, confidential and/or exempt from
>>> disclosure under applicable law. If you are not the intended
>>> recipient, you are hereby notified that any disclosure, copying,
>>> distribution, or use of the information contained herein (including
>>> any reliance thereon) is strictly prohibited. If you received this
>>> communication in error, please immediately contact the sender and destroy
>the material in its entirety, whether in electronic or hard copy format. Thank you.
>>>> --------------------------------------------------------------------
>>>> - To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Struts2 Checkboxlist

Prasanth Pasala
So there is no need to add MultiselectInterceptor in the action definition?

Below is the checkboxlist in the jsp. accountNames map is in the account to provide the list values and names.

<s:checkboxlist name="form.account" list="accountNames" listKey="%{key}" listValue="%{value}" theme="tpg" ></s:checkboxlist>

Thanks,
Prasanth

On 2/6/19 8:53 AM, Yasser Zamani wrote:

> Ach! Sorry, you're right. For checkbox list it's MultiselectInterceptor class which handles this and here it works with following config:
>
> List<Long> selectedLongs= new ArrayList<>();
> public List<Long> getLongs(){
> List<Long> longs= new ArrayList<>();
> longs.add(0L);
> longs.add(1L);
> return longs;
> }
> public void setSelectedLongs(List<Long> selectedLongs){
> this.selectedLongs = selectedLongs;
> }
> public List<Long> getSelectedLongs(){
> return selectedLongs;
> }
>
> <s:checkboxlist
> tooltip="longs test"
> label="Longs Test"
> list="longs"
> name="selectedLongs"
> value="selectedLongs"/>
>
>         <action name="exampleSubmit" class="org.apache.struts2.showcase.UITagExample" method="doSubmit">
>         <result>/WEB-INF/tags/ui/exampleSubmited.jsp</result>
>         <result name="input">/WEB-INF/tags/ui/example.jsp</result>
>         </action>
>
>
> When I post an empty form, MultiselectInterceptor adds an empty string for selectedLongs http param, then Struts internal conversion converts it to an empty instance of List<Long>, then setSelectedLongs will be called here with it.
>
> Regards.
>
>> -----Original Message-----
>> From: Prasanth Pasala <[hidden email]>
>> Sent: Wednesday, February 6, 2019 12:30 AM
>> To: [hidden email]
>> Subject: Re: Struts2 Checkboxlist
>>
>> Hi Yasser,
>>
>> Even after having the param the ArrayList<Long> was not populated with -1 for
>> unchecked checkboxes. The ArrayList<Long> is in form. The set method in the
>> form is not getting called when I don't check any of the checkboxes. I am using a
>> checkboxlist rather than individual checkboxes.
>>
>>             <interceptor-ref name="scope">
>>                 <param name="key"></param>
>>                 <param name="session">form</param>
>>             </interceptor-ref>
>>             <interceptor-ref name="defaultStack">
>>                 <param name="checkbox.uncheckedValue">-1</param>
>>             </interceptor-ref>
>>
>>
>> Thanks,
>> Prasanth
>>
>> On 2/5/19 5:43 AM, Yasser Zamani wrote:
>>> Hi Prasanth,
>>>
>>> Yes, I think. Now I can recall a long discussion about this at [1]. i.e. you also can
>> keep array list of long but override the interceptor like below [2]:
>>> <action name="ListConverterTest"
>>> class="com.afs.ListConverterTestAction">
>>> <interceptor-ref name="defaultStack">
>>> <param name="checkbox.uncheckedValue">-1</param>
>>> </interceptor-ref>
>>>
>>> Kind Regards.
>>>
>>> [1] https://github.com/apache/struts/pull/169
>>> [2] https://github.com/apache/struts/pull/169#issuecomment-352999309
>>>
>>>
>>>> -----Original Message-----
>>>> From: Prasanth Pasala <[hidden email]>
>>>> Sent: Tuesday, February 5, 2019 3:26 AM
>>>> To: [hidden email]
>>>> Subject: Re: Struts2 Checkboxlist
>>>>
>>>> I am using the defaultStack but the ArrayList used for the checkboxes
>>>> is of type Long. If we change it to ArrayList of Boolean would the
>>>> interceptor set the values to false? Or is this only applicable if
>>>> you have individual checkboxes rather than checkboxlist?
>>>>
>>>> Thanks,
>>>> Prasanth
>>>>
>>>> On 2/4/19 4:29 PM, Paul Zepernick wrote:
>>>>> Yes, setFoo is only called if the checkbox is checked.  However,
>>>>> Struts 2 does have a checkbox interceptor:
>>>>> https://struts.apache.org/core-developers/checkbox-interceptor.html
>>>>>
>>>>> This interceptor defaults checkbox Boolean's to False if the box is not
>> checked.
>>>> This is part of the default interceptor stack.
>>>>> Paul
>>>>>
>>>>> -----Original Message-----
>>>>> From: Prasanth Pasala <[hidden email]>
>>>>> Sent: Monday, February 4, 2019 5:21 PM
>>>>> To: [hidden email]
>>>>> Subject: Re: Struts2 Checkboxlist
>>>>>
>>>>> NOTICE: This email originated from outside of the organization. Do
>>>>> not click
>>>> links or open attachments unless you recognize the sender and know
>>>> the content is safe.
>>>>> Is that how Struts2 is expected to work? Meaning setFoo would not be
>>>>> called if
>>>> non of the Foo checkboxes are selected? I know that is how Struts1 worked.
>>>>> Thanks,
>>>>> Prasanth
>>>>>
>>>>> On 2/2/19 7:08 PM, Prasanth Pasala wrote:
>>>>>> Hi Yasser,
>>>>>>
>>>>>> When none of the checkboxes is selected the setFoo is not getting called.
>>>>>>
>>>>>> Thanks
>>>>>> Prasanth
>>>>>>
>>>>>> On February 2, 2019 8:02:07 AM CST, Yasser Zamani
>>>> <[hidden email]> wrote:
>>>>>>> Hi Prasanth,
>>>>>>>
>>>>>>> AFAIK this tag is like this:
>>>>>>>
>>>>>>> <s:checkboxlist name="foo" list="bar" value="baz"/>
>>>>>>>
>>>>>>> It calls getBar method of your action or finds bar in value stack
>>>>>>> to find out what to display. Same for baz to find out which to be
>>>>>>> selected. Then it calls yourAction.setFoo to post selected items. i.e.
>>>>>>> it is up to you what you do with it in setFoo method. Normally you
>>>>>>> should clear baz and fill it with them again to update selected items.
>>>>>>>
>>>>>>> Thanks for using Struts!
>>>>>>>
>>>>>>> Kind Regards.
>>>>>>>
>>>>>>>> -----Original Message-----
>>>>>>>> From: Prasanth <[hidden email]>
>>>>>>>> Sent: Saturday, February 2, 2019 1:08 AM
>>>>>>>> To: [hidden email]
>>>>>>>> Subject: Struts2 Checkboxlist
>>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I am using a checkboxlist on a jsp page which corresponds to a
>>>>>>> ArrayList in the
>>>>>>>> form class, which is used to store form data from a multi page wizard.
>>>>>>> I am using
>>>>>>>> scope interceptor to store the form class in session so that the
>>>>>>>> data
>>>>>>> persists as
>>>>>>>> the user navigates the wizard. When the user selects some check
>>>>>>>> boxes
>>>>>>> it is
>>>>>>>> correctly populated in the form class but if the user navigates
>>>>>>>> back
>>>>>>> in the wizard
>>>>>>>> and unchecks the check box (non of the check boxes selected)
>>>>>>>> struts
>>>>>>> doesn't set
>>>>>>>> the ArrayList to empty. It will still contain the old selection.
>>>>>>>> What
>>>>>>> is the best way
>>>>>>>> to solve this issue?
>>>>>>>>
>>>>>>>> My Options:
>>>>>>>> 1. Should I use Preparable and set this ArrayList to empty? Since
>>>>>>>> this
>>>>>>> is a wizard
>>>>>>>> (multiple pages submitting to the same action) have to make sure
>>>>>>>> it is
>>>>>>> done only
>>>>>>>> when submitting the page that have these checkboxes.
>>>>>>>> 2. Create two separate ArrayLists, one to get values from Struts
>>>>>>>> and
>>>>>>> another to
>>>>>>>> save the original selection and clear the first array list. Down
>>>>>>>> side
>>>>>>> is I need to
>>>>>>>> populate the list linked to the form when user navigates back to
>>>>>>>> that
>>>>>>> page.
>>>>>>>> Neither of them seem elegant. Is there a way to make struts set
>>>>>>>> the
>>>>>>> ArrayList to
>>>>>>>> empty when user doesn't select any check box?
>>>>>>>>
>>>>>>>> Using Struts 2.3.35
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Prasanth
>>>>>>> ------------------------------------------------------------------
>>>>>>> --
>>>>>>> -
>>>>>>> To unsubscribe, e-m
>>>>> Disclaimer: This communication and any files transmitted with it may
>>>>> contain
>>>> information that is privileged, confidential and/or exempt from
>>>> disclosure under applicable law. If you are not the intended
>>>> recipient, you are hereby notified that any disclosure, copying,
>>>> distribution, or use of the information contained herein (including
>>>> any reliance thereon) is strictly prohibited. If you received this
>>>> communication in error, please immediately contact the sender and destroy
>> the material in its entirety, whether in electronic or hard copy format. Thank you.
>>>>> --------------------------------------------------------------------
>>>>> - To unsubscribe, e-mail: [hidden email]
>>>>> For additional commands, e-mail: [hidden email]
>>>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [hidden email]
>>> For additional commands, e-mail: [hidden email]
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>

Reply | Threaded
Open this post in threaded view
|

Re: Struts2 Checkboxlist

Prasanth Pasala
I think the issue I am having is due to the theme, I had old checkboxlist.ftl code. Once it is updated to the latest code it is working well. The only change I make in it is show each checkbox in a
separate line.

Appreciate all the help.

Thanks,
Prasanth

On 2/6/19 9:31 AM, Prasanth Pasala wrote:

> So there is no need to add MultiselectInterceptor in the action definition?
>
> Below is the checkboxlist in the jsp. accountNames map is in the account to provide the list values and names.
>
> <s:checkboxlist name="form.account" list="accountNames" listKey="%{key}" listValue="%{value}" theme="tpg" ></s:checkboxlist>
>
> Thanks,
> Prasanth
>
> On 2/6/19 8:53 AM, Yasser Zamani wrote:
>> Ach! Sorry, you're right. For checkbox list it's MultiselectInterceptor class which handles this and here it works with following config:
>>
>> List<Long> selectedLongs= new ArrayList<>();
>> public List<Long> getLongs(){
>> List<Long> longs= new ArrayList<>();
>> longs.add(0L);
>> longs.add(1L);
>> return longs;
>> }
>> public void setSelectedLongs(List<Long> selectedLongs){
>> this.selectedLongs = selectedLongs;
>> }
>> public List<Long> getSelectedLongs(){
>> return selectedLongs;
>> }
>>
>> <s:checkboxlist
>> tooltip="longs test"
>> label="Longs Test"
>> list="longs"
>> name="selectedLongs"
>> value="selectedLongs"/>
>>
>>         <action name="exampleSubmit" class="org.apache.struts2.showcase.UITagExample" method="doSubmit">
>>         <result>/WEB-INF/tags/ui/exampleSubmited.jsp</result>
>>         <result name="input">/WEB-INF/tags/ui/example.jsp</result>
>>         </action>
>>
>>
>> When I post an empty form, MultiselectInterceptor adds an empty string for selectedLongs http param, then Struts internal conversion converts it to an empty instance of List<Long>, then setSelectedLongs will be called here with it.
>>
>> Regards.
>>
>>> -----Original Message-----
>>> From: Prasanth Pasala <[hidden email]>
>>> Sent: Wednesday, February 6, 2019 12:30 AM
>>> To: [hidden email]
>>> Subject: Re: Struts2 Checkboxlist
>>>
>>> Hi Yasser,
>>>
>>> Even after having the param the ArrayList<Long> was not populated with -1 for
>>> unchecked checkboxes. The ArrayList<Long> is in form. The set method in the
>>> form is not getting called when I don't check any of the checkboxes. I am using a
>>> checkboxlist rather than individual checkboxes.
>>>
>>>             <interceptor-ref name="scope">
>>>                 <param name="key"></param>
>>>                 <param name="session">form</param>
>>>             </interceptor-ref>
>>>             <interceptor-ref name="defaultStack">
>>>                 <param name="checkbox.uncheckedValue">-1</param>
>>>             </interceptor-ref>
>>>
>>>
>>> Thanks,
>>> Prasanth
>>>
>>> On 2/5/19 5:43 AM, Yasser Zamani wrote:
>>>> Hi Prasanth,
>>>>
>>>> Yes, I think. Now I can recall a long discussion about this at [1]. i.e. you also can
>>> keep array list of long but override the interceptor like below [2]:
>>>> <action name="ListConverterTest"
>>>> class="com.afs.ListConverterTestAction">
>>>> <interceptor-ref name="defaultStack">
>>>> <param name="checkbox.uncheckedValue">-1</param>
>>>> </interceptor-ref>
>>>>
>>>> Kind Regards.
>>>>
>>>> [1] https://github.com/apache/struts/pull/169
>>>> [2] https://github.com/apache/struts/pull/169#issuecomment-352999309
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Prasanth Pasala <[hidden email]>
>>>>> Sent: Tuesday, February 5, 2019 3:26 AM
>>>>> To: [hidden email]
>>>>> Subject: Re: Struts2 Checkboxlist
>>>>>
>>>>> I am using the defaultStack but the ArrayList used for the checkboxes
>>>>> is of type Long. If we change it to ArrayList of Boolean would the
>>>>> interceptor set the values to false? Or is this only applicable if
>>>>> you have individual checkboxes rather than checkboxlist?
>>>>>
>>>>> Thanks,
>>>>> Prasanth
>>>>>
>>>>> On 2/4/19 4:29 PM, Paul Zepernick wrote:
>>>>>> Yes, setFoo is only called if the checkbox is checked.  However,
>>>>>> Struts 2 does have a checkbox interceptor:
>>>>>> https://struts.apache.org/core-developers/checkbox-interceptor.html
>>>>>>
>>>>>> This interceptor defaults checkbox Boolean's to False if the box is not
>>> checked.
>>>>> This is part of the default interceptor stack.
>>>>>> Paul
>>>>>>
>>>>>> -----Original Message-----
>>>>>> From: Prasanth Pasala <[hidden email]>
>>>>>> Sent: Monday, February 4, 2019 5:21 PM
>>>>>> To: [hidden email]
>>>>>> Subject: Re: Struts2 Checkboxlist
>>>>>>
>>>>>> NOTICE: This email originated from outside of the organization. Do
>>>>>> not click
>>>>> links or open attachments unless you recognize the sender and know
>>>>> the content is safe.
>>>>>> Is that how Struts2 is expected to work? Meaning setFoo would not be
>>>>>> called if
>>>>> non of the Foo checkboxes are selected? I know that is how Struts1 worked.
>>>>>> Thanks,
>>>>>> Prasanth
>>>>>>
>>>>>> On 2/2/19 7:08 PM, Prasanth Pasala wrote:
>>>>>>> Hi Yasser,
>>>>>>>
>>>>>>> When none of the checkboxes is selected the setFoo is not getting called.
>>>>>>>
>>>>>>> Thanks
>>>>>>> Prasanth
>>>>>>>
>>>>>>> On February 2, 2019 8:02:07 AM CST, Yasser Zamani
>>>>> <[hidden email]> wrote:
>>>>>>>> Hi Prasanth,
>>>>>>>>
>>>>>>>> AFAIK this tag is like this:
>>>>>>>>
>>>>>>>> <s:checkboxlist name="foo" list="bar" value="baz"/>
>>>>>>>>
>>>>>>>> It calls getBar method of your action or finds bar in value stack
>>>>>>>> to find out what to display. Same for baz to find out which to be
>>>>>>>> selected. Then it calls yourAction.setFoo to post selected items. i.e.
>>>>>>>> it is up to you what you do with it in setFoo method. Normally you
>>>>>>>> should clear baz and fill it with them again to update selected items.
>>>>>>>>
>>>>>>>> Thanks for using Struts!
>>>>>>>>
>>>>>>>> Kind Regards.
>>>>>>>>
>>>>>>>>> -----Original Message-----
>>>>>>>>> From: Prasanth <[hidden email]>
>>>>>>>>> Sent: Saturday, February 2, 2019 1:08 AM
>>>>>>>>> To: [hidden email]
>>>>>>>>> Subject: Struts2 Checkboxlist
>>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I am using a checkboxlist on a jsp page which corresponds to a
>>>>>>>> ArrayList in the
>>>>>>>>> form class, which is used to store form data from a multi page wizard.
>>>>>>>> I am using
>>>>>>>>> scope interceptor to store the form class in session so that the
>>>>>>>>> data
>>>>>>>> persists as
>>>>>>>>> the user navigates the wizard. When the user selects some check
>>>>>>>>> boxes
>>>>>>>> it is
>>>>>>>>> correctly populated in the form class but if the user navigates
>>>>>>>>> back
>>>>>>>> in the wizard
>>>>>>>>> and unchecks the check box (non of the check boxes selected)
>>>>>>>>> struts
>>>>>>>> doesn't set
>>>>>>>>> the ArrayList to empty. It will still contain the old selection.
>>>>>>>>> What
>>>>>>>> is the best way
>>>>>>>>> to solve this issue?
>>>>>>>>>
>>>>>>>>> My Options:
>>>>>>>>> 1. Should I use Preparable and set this ArrayList to empty? Since
>>>>>>>>> this
>>>>>>>> is a wizard
>>>>>>>>> (multiple pages submitting to the same action) have to make sure
>>>>>>>>> it is
>>>>>>>> done only
>>>>>>>>> when submitting the page that have these checkboxes.
>>>>>>>>> 2. Create two separate ArrayLists, one to get values from Struts
>>>>>>>>> and
>>>>>>>> another to
>>>>>>>>> save the original selection and clear the first array list. Down
>>>>>>>>> side
>>>>>>>> is I need to
>>>>>>>>> populate the list linked to the form when user navigates back to
>>>>>>>>> that
>>>>>>>> page.
>>>>>>>>> Neither of them seem elegant. Is there a way to make struts set
>>>>>>>>> the
>>>>>>>> ArrayList to
>>>>>>>>> empty when user doesn't select any check box?
>>>>>>>>>
>>>>>>>>> Using Struts 2.3.35
>>>>>>>>>
>>>>>>>>> Thanks,
>>>>>>>>> Prasanth
>>>>>>>> ------------------------------------------------------------------
>>>>>>>> --
>>>>>>>> -
>>>>>>>> To unsubscribe, e-m
>>>>>> Disclaimer: This communication and any files transmitted with it may
>>>>>> contain
>>>>> information that is privileged, confidential and/or exempt from
>>>>> disclosure under applicable law. If you are not the intended
>>>>> recipient, you are hereby notified that any disclosure, copying,
>>>>> distribution, or use of the information contained herein (including
>>>>> any reliance thereon) is strictly prohibited. If you received this
>>>>> communication in error, please immediately contact the sender and destroy
>>> the material in its entirety, whether in electronic or hard copy format. Thank you.
>>>>>> --------------------------------------------------------------------
>>>>>> - To unsubscribe, e-mail: [hidden email]
>>>>>> For additional commands, e-mail: [hidden email]
>>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [hidden email]
>>>> For additional commands, e-mail: [hidden email]
>>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [hidden email]
>> For additional commands, e-mail: [hidden email]
>>
>