Re: Problem with webobject attributes in WOBuilder
Re: Problem with webobject attributes in WOBuilder
- Subject: Re: Problem with webobject attributes in WOBuilder
- From: David Masters <email@hidden>
- Date: Wed, 14 Jun 2006 22:56:11 +0100
John,
On 14 Jun 2006, at 12:54, John Stewart wrote:
If I create a ul wrapper "styleContainer" as below, I'd like to
include the "open" or "closed" styles, as well as a common "clear"
style.
The output would be of the form:
<!-- isOpen = true: -->
<ul class="clear open">
<li>...</li>
</ul>
<!-- isOpen = false: -->
<ul class="clear closed">
<li>...</li>
</ul>
One approach (as I think David LeBer mentioned) is to avoid the use
of conditionals in the WOComponent with the use of
WOGenericContainers, and a method in the .java file to return the
class name as a String. For example, create a generic container with
the element name of 'ul' and bind its (css) class to the method.
In .html:
<webobject name="Generic1">
...list repetition goes here...
</webobject>
In .wod:
Generic1: WOGenericContainer
{
elementName = "ul";
class = classForList;
}
In .java:
public String classForList()
{
return ...test... ? "clear open" : "clear closed";
}
This technique avoids the fragile editing problem in WOBuilder that
you mentioned, and keeps the WOComponent relatively clean and tidy -
no nested conditionals, for example.
To further complicate things, what if I want more than 2 alternative
styles, e.g. fed by an integer instead of a boolean?
The method can be easily extended to cope with any number of tests
and styles - I personally find it easier to cope with the logic in
the .java file than with nested WOConditionals in the .html file.
Or is this one of WO's limitations where I have to include style names
in the Java code?
As others have mentioned, only if you think this is a limitation :-).
Personally I don't think there's anything wrong with the .java file
returning the css class name - I think of the .wo and .java files as
acting as controller/view classes.
Another technique we often use - particularly for cases where the
style is dependent on some attribute, such as a status flag, of an
item - is to return a class name based on an internal typecode.
For example, if we have a 'New' status option, in the database we
have a column for typecode, which in this case might be 'new'. These
typecodes never change, whereas the descriptive title might; and
they're always lowercase, with no spaces to avoid problems later on.
Then a classForItem method can simply return something like:
return "list_item_" + item.typecode();
We then have css styles for "list_item_new", "list_item_old", and so
on. Makes it trivial to, say, color code items in a list based on the
status of that item; avoids having any conditionals in the .java
file; and if there is a new status option added to the database there
are no changes required in the .java code: only the addition of a new
style in the .css file with the appropriate list_item_ name.
Hope this helps!
David
David Masters, Software Imagineer
email@hidden
Web: http://www.pyrusmalus.com Tel: +44 141 427 9649 Fax: +44
141 427 1740
P y r u s M a l u s | d e s i g n | d e v e l o p | d e l
i v e r | c o n s u l t | t r a i n | s u p p o r t |
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden