You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Gurps <g...@gurpal.co.uk> on 2006/12/05 22:57:01 UTC

table row class value dependent on iterated object


I have a for loop like so:

	<component id="albums" type="For">
		<binding name="source" value="albums" />
		<binding name="value" value="album" />
		<binding name="element" value="literal:tr" />
		<binding name="class" value="beans.evenOdd.rowClass" />
	</component>

and a bean declaration

<bean name="evenOdd" class="mypackage.EvenOdd" />

My .CSS file contains a tr.even, tr.odd, tr.newalbum, etc......

how do i (re)write the EvenOdd class such that i can highlight a row based
on one of the fields in the "album" class?

It's almost like i need to set a value inside the evenOdd class such that
when the loop calls getRowClass() it is derived from the object being
iterated on (album.status). It is the status that i wish to show?

I have seen the source to the standard EvenOdd but how do I pass in a value
to it?
-- 
View this message in context: http://www.nabble.com/table-row-class-value-dependent-on-iterated-object-tf2764675.html#a7709035
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: table row class value dependent on iterated object

Posted by Barry Books <tr...@gmail.com>.
I have this bean which takes an object and a primary key and returns
even/odd and selected. The ognl to call it is below

public class EvenOddSelected {
        private boolean even = true;

        public String getNext(MillId object, MillId selected) {
                String result = even ? "even" : "odd";

                if ( selected != null &&
object.getMillId().longValue() == selected.getMillId().longValue() ) {
                        result = result + " selected";
                }
                even = !even;
                return result;
        }

}


 rowsClass="ognl:beans.evenOddSelected.getNext(components.Groups.tableRow,key)"

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: table row class value dependent on iterated object

Posted by Gurps <g...@gurpal.co.uk>.
Ok i get it. I ended up doing:

<binding name="class" value="ognl:(album.status == 'New Album') ?
'newalbumclass' : 'someotherclass" />

but how could i put the expression into say a bean or class ? ie. if i
wanted the logic in java and not in the .page file?

Thanks


Jessek wrote:
> 
> You could just use the standard tapestry EventOdd bean plus a little ognl:
> 
> <binding name="class" value="ognl:beans.evenOdd.next +
> (album.isSelected ? ' selected' : '')" />
> 
> Something like that anyway..
> 
> On 12/5/06, Gurps <g...@gurpal.co.uk> wrote:
>>
>>
>> I have a for loop like so:
>>
>>         <component id="albums" type="For">
>>                 <binding name="source" value="albums" />
>>                 <binding name="value" value="album" />
>>                 <binding name="element" value="literal:tr" />
>>                 <binding name="class" value="beans.evenOdd.rowClass" />
>>         </component>
>>
>> and a bean declaration
>>
>> <bean name="evenOdd" class="mypackage.EvenOdd" />
>>
>> My .CSS file contains a tr.even, tr.odd, tr.newalbum, etc......
>>
>> how do i (re)write the EvenOdd class such that i can highlight a row
>> based
>> on one of the fields in the "album" class?
>>
>> It's almost like i need to set a value inside the evenOdd class such that
>> when the loop calls getRowClass() it is derived from the object being
>> iterated on (album.status). It is the status that i wish to show?
>>
>> I have seen the source to the standard EvenOdd but how do I pass in a
>> value
>> to it?
>> --
>> View this message in context:
>> http://www.nabble.com/table-row-class-value-dependent-on-iterated-object-tf2764675.html#a7709035
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
> 
> 
> -- 
> Jesse Kuhnert
> Tapestry/Dojo team member/developer
> 
> Open source based consulting work centered around
> dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/table-row-class-value-dependent-on-iterated-object-tf2764675.html#a7709445
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: table row class value dependent on iterated object

Posted by Jesse Kuhnert <jk...@gmail.com>.
You could just use the standard tapestry EventOdd bean plus a little ognl:

<binding name="class" value="ognl:beans.evenOdd.next +
(album.isSelected ? ' selected' : '')" />

Something like that anyway..

On 12/5/06, Gurps <g...@gurpal.co.uk> wrote:
>
>
> I have a for loop like so:
>
>         <component id="albums" type="For">
>                 <binding name="source" value="albums" />
>                 <binding name="value" value="album" />
>                 <binding name="element" value="literal:tr" />
>                 <binding name="class" value="beans.evenOdd.rowClass" />
>         </component>
>
> and a bean declaration
>
> <bean name="evenOdd" class="mypackage.EvenOdd" />
>
> My .CSS file contains a tr.even, tr.odd, tr.newalbum, etc......
>
> how do i (re)write the EvenOdd class such that i can highlight a row based
> on one of the fields in the "album" class?
>
> It's almost like i need to set a value inside the evenOdd class such that
> when the loop calls getRowClass() it is derived from the object being
> iterated on (album.status). It is the status that i wish to show?
>
> I have seen the source to the standard EvenOdd but how do I pass in a value
> to it?
> --
> View this message in context: http://www.nabble.com/table-row-class-value-dependent-on-iterated-object-tf2764675.html#a7709035
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org