You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by lbastil <ba...@gmx.de> on 2008/04/02 14:10:47 UTC

[S2] checkboxes in each row of table - set values in action

Hello,

I have the following problem:

in action i have a collection of class User
each class User have different attributes, one is: boolean permission

in JSP I use struts 2 iterator tag to iterate the User Objects.
For each User entry I create one row in table.
for displaying/changing the boolean permission value I use S2 checkbox tag

so far it works fine and show all data in collection of Users correct.

But how can I set changed checkbox values (the permission attribute) back to
action?

Any help appreciated, thank you.
basti 
-- 
View this message in context: http://www.nabble.com/-S2--checkboxes-in-each-row-of-table---set-values-in-action-tp16446895p16446895.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] checkboxes in each row of table - set values in action

Posted by Laurie Harper <la...@holoweb.net>.
lbastil wrote:
> Thank you for the help.
> But I could not get it to work.
> 
> Here is a code sample from the Action Class:
> 
> ....
> private Set<TraegerPermission> traegerPermissions;
> ....
> 
> The class TraegerPermissions itself have another collection:
> ....
> private Collection<EinrichtungPermission> einrichtungen;
> ....

And both TraegerPermission and EinrichtungPermission define the 
appropriate getter and setter methods for the id, number, name and 
writepermission properties?

> In jsp I have successful read access:
> ....
> <s:iterator value="traegerPermissions" id="item">
> [...]	
> 	<s:checkbox ... name="writepermission" ... value="%{writePermission}"/>
> 	[...]
> 	<s:iterator value="%{einrichtungen}">
> 	[...]
> 		<s:checkbox ... name="writePermission" ... value="%{writePermission}"/>

In neither case are you binding the checkbox input fields to the 
underlying model. You need to change the 'name' attributes to fully 
dereference the model property so Struts knows where to store the 
submitted values. Something like this (untested):

   <s:iterator value="traegerPermissions" index="i1">
     <s:checkbox name="traegerPermissions[i1.index]" .../>
     <s:iterator value="einrichtungen" index="i2">
       <s:checkbox 
name="traegerPermissions[i1.index].einrichtungen[i2.index]" .../>

Take a look at the various example applications, as the above may not be 
exactly right (that's just off the top of my head).

L.

> what shall I save in order to can write back changes in the Checkboxes
> to the model by struts2 out of box approach?
> 
> I tries several settings without success ...
> 
> thank you,
> Basti
> 
> 
> 
> Laurie Harper wrote:
>> Provided the checkbox is properly bound to the collection entry, yes. 
>> You need to specify the name of the s:checkbox (or any other input type) 
>> as userCollection[index].userProperty where 'userCollection' is the name 
>> of the Collection property on your action, index comes from the iterator 
>> and userProperty is the property to bind to.
>>
>> L.
>>
>> lbastil wrote:
>>> Thank you for reply!
>>>
>>> I just wonder:
>>>
>>> I understand it would work out of box for 1 User-Object, if I bound
>>> checkbox
>>> to permission property of this user.
>>> But I wonder it should work out of box if I use (as I described)
>>> Collection
>>> of Users in Action
>>> and on jsp side iterator tag, and checkbox tag within iterator is bound
>>> to
>>> permission properties of users in the iterated Collection.
>>>
>>> This does not matter, it should work the same as for single user object?
>>>
>>>
>>> Thank you,
>>> Basti
>>>
>>>
>>> Laurie Harper wrote:
>>>> lbastil wrote:
>>>>> Hello,
>>>>>
>>>>> I have the following problem:
>>>>>
>>>>> in action i have a collection of class User
>>>>> each class User have different attributes, one is: boolean permission
>>>>>
>>>>> in JSP I use struts 2 iterator tag to iterate the User Objects.
>>>>> For each User entry I create one row in table.
>>>>> for displaying/changing the boolean permission value I use S2 checkbox
>>>>> tag
>>>>>
>>>>> so far it works fine and show all data in collection of Users correct.
>>>>>
>>>>> But how can I set changed checkbox values (the permission attribute)
>>>>> back
>>>>> to
>>>>> action?
>>>> If your checkbox is bound the the permission property of the user, 
>>>> submitting the form should update the property. If that's not happening, 
>>>> you need to give more details: what your JSP code looks like, and the 
>>>> relevant bits of your action and User code, at least.
>>>>
>>>> L.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
> 


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


Re: [S2] checkboxes in each row of table - set values in action

Posted by lbastil <ba...@gmx.de>.
Thank you for the help.

But I could not get it to work.

Here is a code sample from the Action Class:

...
private Set<TraegerPermission> traegerPermissions;
...

The class TraegerPermissions itself have another collection:
...
private Collection<EinrichtungPermission> einrichtungen;
...

In jsp I have successful read access:
...
<s:iterator value="traegerPermissions" id="item">
					<tr id="row_<s:property value="id"/>">
						<td>	
							Träger - id <s:property value="%{#item.id}"/>
						</td>
						<td>
							<s:property value="%{number}" />
						</td>
						<td>
							<s:property value="%{name}" />
						</td>						
						<s:checkbox cssClass="chkbox" theme="eud_xhtml" name="writepermission"
id="%{'traeger_write_'+id}" value="%{writePermission}"/>
						<s:checkbox cssClass="chkbox" theme="eud_xhtml"
name="reportPermission" id="%{'traeger_report_'+id}"
value="%{reportPermission}"/>
					</tr>
					<s:iterator value="%{einrichtungen}">
					<tr id="row_<s:property value="id"/>">
						<td>	
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Einrichtung
						</td>
						<td>
							<s:property value="%{number}" />
						</td>
						<td>
							<s:property value="%{name}" />
						</td>
						<s:checkbox cssClass="chkbox" theme="eud_xhtml" name="writePermission"
id="%{'einrichtung_write_'+id}" value="%{writePermission}"/>
						<s:checkbox cssClass="chkbox" theme="eud_xhtml"
name="reportPermission" id="%{'einrichtung_report_'+id}"
value="%{reportPermission}"/>
...

what shall I save in order to can write back changes in the Checkboxes
to the model by struts2 out of box approach?

I tries several settings without success ...

thank you,
Basti



Laurie Harper wrote:
> 
> Provided the checkbox is properly bound to the collection entry, yes. 
> You need to specify the name of the s:checkbox (or any other input type) 
> as userCollection[index].userProperty where 'userCollection' is the name 
> of the Collection property on your action, index comes from the iterator 
> and userProperty is the property to bind to.
> 
> L.
> 
> lbastil wrote:
>> Thank you for reply!
>> 
>> I just wonder:
>> 
>> I understand it would work out of box for 1 User-Object, if I bound
>> checkbox
>> to permission property of this user.
>> But I wonder it should work out of box if I use (as I described)
>> Collection
>> of Users in Action
>> and on jsp side iterator tag, and checkbox tag within iterator is bound
>> to
>> permission properties of users in the iterated Collection.
>> 
>> This does not matter, it should work the same as for single user object?
>> 
>> 
>> Thank you,
>> Basti
>> 
>> 
>> Laurie Harper wrote:
>>> lbastil wrote:
>>>> Hello,
>>>>
>>>> I have the following problem:
>>>>
>>>> in action i have a collection of class User
>>>> each class User have different attributes, one is: boolean permission
>>>>
>>>> in JSP I use struts 2 iterator tag to iterate the User Objects.
>>>> For each User entry I create one row in table.
>>>> for displaying/changing the boolean permission value I use S2 checkbox
>>>> tag
>>>>
>>>> so far it works fine and show all data in collection of Users correct.
>>>>
>>>> But how can I set changed checkbox values (the permission attribute)
>>>> back
>>>> to
>>>> action?
>>> If your checkbox is bound the the permission property of the user, 
>>> submitting the form should update the property. If that's not happening, 
>>> you need to give more details: what your JSP code looks like, and the 
>>> relevant bits of your action and User code, at least.
>>>
>>> L.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--checkboxes-in-each-row-of-table---set-values-in-action-tp16446895p16537273.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] checkboxes in each row of table - set values in action

Posted by Laurie Harper <la...@holoweb.net>.
Provided the checkbox is properly bound to the collection entry, yes. 
You need to specify the name of the s:checkbox (or any other input type) 
as userCollection[index].userProperty where 'userCollection' is the name 
of the Collection property on your action, index comes from the iterator 
and userProperty is the property to bind to.

L.

lbastil wrote:
> Thank you for reply!
> 
> I just wonder:
> 
> I understand it would work out of box for 1 User-Object, if I bound checkbox
> to permission property of this user.
> But I wonder it should work out of box if I use (as I described) Collection
> of Users in Action
> and on jsp side iterator tag, and checkbox tag within iterator is bound to
> permission properties of users in the iterated Collection.
> 
> This does not matter, it should work the same as for single user object?
> 
> 
> Thank you,
> Basti
> 
> 
> Laurie Harper wrote:
>> lbastil wrote:
>>> Hello,
>>>
>>> I have the following problem:
>>>
>>> in action i have a collection of class User
>>> each class User have different attributes, one is: boolean permission
>>>
>>> in JSP I use struts 2 iterator tag to iterate the User Objects.
>>> For each User entry I create one row in table.
>>> for displaying/changing the boolean permission value I use S2 checkbox
>>> tag
>>>
>>> so far it works fine and show all data in collection of Users correct.
>>>
>>> But how can I set changed checkbox values (the permission attribute) back
>>> to
>>> action?
>> If your checkbox is bound the the permission property of the user, 
>> submitting the form should update the property. If that's not happening, 
>> you need to give more details: what your JSP code looks like, and the 
>> relevant bits of your action and User code, at least.
>>
>> L.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>>
> 


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


Re: [S2] checkboxes in each row of table - set values in action

Posted by lbastil <ba...@gmx.de>.
Thank you for reply!

I just wonder:

I understand it would work out of box for 1 User-Object, if I bound checkbox
to permission property of this user.
But I wonder it should work out of box if I use (as I described) Collection
of Users in Action
and on jsp side iterator tag, and checkbox tag within iterator is bound to
permission properties of users in the iterated Collection.

This does not matter, it should work the same as for single user object?


Thank you,
Basti


Laurie Harper wrote:
> 
> lbastil wrote:
>> Hello,
>> 
>> I have the following problem:
>> 
>> in action i have a collection of class User
>> each class User have different attributes, one is: boolean permission
>> 
>> in JSP I use struts 2 iterator tag to iterate the User Objects.
>> For each User entry I create one row in table.
>> for displaying/changing the boolean permission value I use S2 checkbox
>> tag
>> 
>> so far it works fine and show all data in collection of Users correct.
>> 
>> But how can I set changed checkbox values (the permission attribute) back
>> to
>> action?
> 
> If your checkbox is bound the the permission property of the user, 
> submitting the form should update the property. If that's not happening, 
> you need to give more details: what your JSP code looks like, and the 
> relevant bits of your action and User code, at least.
> 
> L.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--checkboxes-in-each-row-of-table---set-values-in-action-tp16446895p16467308.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: [S2] checkboxes in each row of table - set values in action

Posted by Laurie Harper <la...@holoweb.net>.
lbastil wrote:
> Hello,
> 
> I have the following problem:
> 
> in action i have a collection of class User
> each class User have different attributes, one is: boolean permission
> 
> in JSP I use struts 2 iterator tag to iterate the User Objects.
> For each User entry I create one row in table.
> for displaying/changing the boolean permission value I use S2 checkbox tag
> 
> so far it works fine and show all data in collection of Users correct.
> 
> But how can I set changed checkbox values (the permission attribute) back to
> action?

If your checkbox is bound the the permission property of the user, 
submitting the form should update the property. If that's not happening, 
you need to give more details: what your JSP code looks like, and the 
relevant bits of your action and User code, at least.

L.


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