0

I am in a situation where the "class" attribute of a div tag should be dependent on the value of a java binding. This can be easily done by moving the associated logic to the java class, but at this moment we are not allowed to change anything at the Java component.

I am trying out the following to resolve the problem (using WOOGNL):

<div class="<wo:WOConditional condition = \"[cssClassDecider]\">classToUse</wo:WOConditiona>" > 
HTML Static Content
</div>

As it can be seen, i am trying to use value of "cssClassDecider" to set the class.

Can anybody tell if any has solved a similar problem or one is available at WO.

Arnab
  • 1,308
  • 1
  • 13
  • 18
  • Maybe you can somehow reuse this: https://code.google.com/p/getobjects/source/browse/core/trunk/org/getobjects/appserver/elements/WOHTMLElementAttributes.java. In GETobjects this is builtin, eg Customers – hnh Jul 24 '15 at 00:28

1 Answers1

0

It's not clear to me whether cssClassDecider is providing the string content for the class attribute, or a boolean to drive a conditional. In any case, the usual pattern would be:

<wo:WOGenericContainer elementName="div" class="$methodReturningClassNames">
  ...
</wo:WOGenericContainer>

If cssClassDecider returns a conditional, you could do something like this:

<wo:WOConditional condition="$cssClassDecider">
  <div class="classWhenTrue">
    ...
  </div>
</wo:WOConditional>
<wo:WOConditional condition="$cssClassDecider" negate="$true">
  <div class="classWhenFalse">
    ...
  </div>
</wo:WOConditional>

If neither of those solve your problem, provide some more information.

Paul A. Hoadley
  • 1,518
  • 1
  • 13
  • 17
  • cssClassDecider has to return the boolean for conditional. Thanks for the answer, it works for the solution. However, for a more generic problem, is it possible in WebObjects to embed a WO Element (e.g. WOConditional) inside an HTML element (as a value to one of HTML attribute)? – Arnab Jul 28 '15 at 22:36
  • The short answer is I don't know, though the template parser will let you get away with quite a bit of nastiness, so you could just try it out and see. It's not something I would recommend: there will always be a more conventional way to express what you need to do. If you need more help with this, post a new question and I'll take a look. – Paul A. Hoadley Jul 29 '15 at 11:10