You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Engelhart <me...@mac.com> on 2004/11/12 22:51:13 UTC

Conditional style attributes

Hi -

I have a page where i have to display 2 different types of domain 
objects that need different "style" attributes in their output 
depending on what type of object I'm currently iterating on (I iterate 
over an aggreate List of data objects that can one of 2 types mixed 
up).    So as a simple example  type A has a style="color:red" and type 
B has a style="color:blue".

I'm not sure of the best way to handle this in Tapestry.  I realize I 
could just wrap the whole jwcid in a conditional for one object and 
then an inverted conditional for the other but that seems a bit clunky.

Thanks
Mike


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


Re: Conditional style attributes

Posted by Markus Wiederkehr <ma...@gmail.com>.
You could use an OGNL expression to retrieve the value of the style
attribute from your Java class.

Markus


On Fri, 12 Nov 2004 15:51:13 -0600, Michael Engelhart
<me...@mac.com> wrote:
> Hi -
> 
> I have a page where i have to display 2 different types of domain
> objects that need different "style" attributes in their output
> depending on what type of object I'm currently iterating on (I iterate
> over an aggreate List of data objects that can one of 2 types mixed
> up).    So as a simple example  type A has a style="color:red" and type
> B has a style="color:blue".
> 
> I'm not sure of the best way to handle this in Tapestry.  I realize I
> could just wrap the whole jwcid in a conditional for one object and
> then an inverted conditional for the other but that seems a bit clunky.
> 
> Thanks
> Mike
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
>

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


Re: Conditional style attributes

Posted by Michael Engelhart <me...@mac.com>.
On Nov 15, 2004, at 8:45 AM, Christian.Haselbach@tngtech.com wrote:

> Quoting Andy Pahne <ap...@der-die-das.org>:
>> try something like
>>
>> <span ...
>>   class="ognl: (someObject instanceof SomeClass ) ?  'green' :
>> 'blue')"></span>
>>
>
> Well, it would be more object oriented (and therefore, cleaner) if
> these objects would implement the same interface or have the same
> super class with the method "getStyleClass" which provides the
> needed information. I.e., you can then do something like the following:
>
> <span class="ognl:someObject.styleClass"> ... </span>
>
> Ciao Christian

But then you're mixing presentation and data which is not a good idea 
from an OO perspective (or rather from any perspective).

I went with the <span jwcid="@Any" style="ognl:'text-transform:' + 
(isObjectA ? 'none' : 'capitalize')"></span>

which worked great.  I hadn't come across @Any until it was pointed out 
to me the other day.

Thanks
Mike


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


Re: Conditional style attributes

Posted by Ch...@tngtech.com.
Quoting Andy Pahne <ap...@der-die-das.org>:
> try something like
>
> <span ...
>   class="ognl: (someObject instanceof SomeClass ) ?  'green' :
> 'blue')"></span>
>

Well, it would be more object oriented (and therefore, cleaner) if
these objects would implement the same interface or have the same
super class with the method "getStyleClass" which provides the
needed information. I.e., you can then do something like the following:

<span class="ognl:someObject.styleClass"> ... </span>

Ciao Christian

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


Re: Conditional style attributes

Posted by Andy Pahne <ap...@der-die-das.org>.

try something like

<span ...
  class="ognl: (someObject instanceof SomeClass ) ?  'green' : 
'blue')"></span>

andy


Michael Engelhart wrote:
> Hi -
> 
> I have a page where i have to display 2 different types of domain 
> objects that need different "style" attributes in their output depending 
> on what type of object I'm currently iterating on (I iterate over an 
> aggreate List of data objects that can one of 2 types mixed up).    So 
> as a simple example  type A has a style="color:red" and type B has a 
> style="color:blue".
> 
> I'm not sure of the best way to handle this in Tapestry.  I realize I 
> could just wrap the whole jwcid in a conditional for one object and then 
> an inverted conditional for the other but that seems a bit clunky.
> 
> Thanks
> Mike
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 


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


Re: Conditional style attributes

Posted by Michael Engelhart <me...@mac.com>.
aha - thanks for the quick replies - that works perfectly.

mike
On Nov 12, 2004, at 4:24 PM, Paul Ferraro wrote:

> Since the HTML for displaying these 2 objects differs by only a single 
> attribute, it's probably easiest to place the conditional logic within 
> an ognl expression:
> e.g.
>
> <span jwcid="@Any" style="ognl:'color:' + (typeA ? 'red' : 
> 'blue')">...</span>
>
> public boolean isTypeA()
> {
>    return TypeA.class.isInstance(this.getObject());
> }
>
> Paul
>
> Michael Engelhart wrote:
>
>> Hi -
>>
>> I have a page where i have to display 2 different types of domain 
>> objects that need different "style" attributes in their output 
>> depending on what type of object I'm currently iterating on (I 
>> iterate over an aggreate List of data objects that can one of 2 types 
>> mixed up).    So as a simple example  type A has a style="color:red" 
>> and type B has a style="color:blue".
>>
>> I'm not sure of the best way to handle this in Tapestry.  I realize I 
>> could just wrap the whole jwcid in a conditional for one object and 
>> then an inverted conditional for the other but that seems a bit 
>> clunky.
>>
>> Thanks
>> Mike
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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


Re: Conditional style attributes

Posted by Paul Ferraro <pm...@columbia.edu>.
Since the HTML for displaying these 2 objects differs by only a single 
attribute, it's probably easiest to place the conditional logic within 
an ognl expression:
e.g.

<span jwcid="@Any" style="ognl:'color:' + (typeA ? 'red' : 
'blue')">...</span>

public boolean isTypeA()
{
    return TypeA.class.isInstance(this.getObject());
}

Paul

Michael Engelhart wrote:

> Hi -
>
> I have a page where i have to display 2 different types of domain 
> objects that need different "style" attributes in their output 
> depending on what type of object I'm currently iterating on (I iterate 
> over an aggreate List of data objects that can one of 2 types mixed 
> up).    So as a simple example  type A has a style="color:red" and 
> type B has a style="color:blue".
>
> I'm not sure of the best way to handle this in Tapestry.  I realize I 
> could just wrap the whole jwcid in a conditional for one object and 
> then an inverted conditional for the other but that seems a bit clunky.
>
> Thanks
> Mike
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


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