Hi Ken,
Thanks for the examples. I now have a working page (and I found an
unrelated bug where I'm not setting the properties on every including page)!
Regards,
Mike
---
Ken Paulsen wrote:
> Hi Mike, see comments below...
>
> Mike Wright wrote:
>
>> Hi Ken,
>>
>> Thanks for fix the <!if> problem. I've made some progress:
>>
>>> <!if #{sessionScope.hasTypeColumn}>
>>> "<br />has type
>>> </!if>
>>> "<br/>else
>>> <!if !#{sessionScope.hasTypeColumn}>
>>> "<br />has no type
>>> </!if>
>>
>>
>> produces:
>>
>>> has type
>>> else
>>
>>
>> on the page after the variable is set to $boolean{true}, and produces:
>>
>>> else
>>> has no type
>>
>>
>> on the pages when the variable is set to $boolean{false}. Good so far.
>>
>>
>> However, when I try to do a string comparison, strange things
>> happen. I've set a table type on three top-level pages, e.g.
>>
>>> setSessionAttribute(key="sharedTableType", value="deployments")
>>
>>
>> (or "bindingsEngines" or "libraries"), but when I try to check this
>> value:
>>
>>> <!if #{sessionScope.sharedTableType} == "deployments" >
>>> "<br />TBD call listServiceAssemblies("domain")
>>> </!if>
>>
>>
>> I get nothing as if this always evaluates to false. If I add "<br
>> />#{sessionScope.sharedTableType}" I get the expected String
>> displayed (it is set).
>> BTW, originally I tried a single "=" as you described in a previous
>> e-mail, but that didn't work (I expect that this was a
>> typo like the </if> typos, where only </!if> is expected). This is
>> why running examples are much better than
>> (untestable, typo-prone) e-mails. Anyway, at some point, some
>> variation I tried resulted in a:
>
> A single '=' is correct (my current parsing is limited to single
> character operators). See attached example.
>
> This example shows the use of '&' (logical AND), '!' (logical NOT),
> and '=' (String equals). If you run it, you can follow the messages
> on the screen to see the 3 different 'if' branches.
>
>>> com.sun.el.parser.ParseException: Encountered "=" at line 1, column 32.
>>> Was expecting one of:
>>> "}"
>>
>>
>> ...
>>
>>> "=="
>>
>>
>> ...
>>
>> so I switched to using "==" (or is there some other syntax I should
>> be using)?
>>
>> . If I try something like this (moving the closing curly brace
>> outside the comparison):
>>
>>> <!if #{sessionScope.sharedTableType == "deployments"} >
>>> "<br />TBD call listServiceAssemblies("domain")
>>> </!if>
>>
>>
>> Depending on the variable's contents, I get all sorts of information
>> on the screen, that looks like javascript generated for the woodstock
>> table component
>> used above the <!if> in the .jsf file, or I get the rest of the page
>> truncated and the server.log shows:
>
> The #{...} is standard EL syntax. It must follow EL rules.
>
>>> java.uti.regex.PatternSyntaxException:
>>> Illegal repitition near index 0
>>> #{sessionScope.sharedTableType
>>> ^
>>
>>
>> Trying to reverse engineer the <!if> expression syntax is taking up
>> too much time. Can you please provide some more detailed examples or
>> tests showing the syntax for <!if> expressions? It would be very
>> helpful to commit some samples to the jsftemplating project. I would
>> do it, if I had any working examples.
>
> The Strings / boolean variables can be whatever you want using #{} or
> ${} expressions. The operators follow the example I have attached and
> the (undecipherable) email messages. Here are some more boolean
> equation examples (see also moreIfs.jsf, attached):
>
> true
> !false
> foo=foo
> 33<100
> 1111\>9
> 13%5 = 3
> 13%5 = 3
> (13%5 \> 1) | false
> !(13%5 < 1) & true
>
> These all evaluate to "true".
>
> Feel free to post these! ;)
>
> Ken
>
>>
>> Regards,
>> Mike
>>
>>
>>
>------------------------------------------------------------------------
>
><sun:page>
> <sun:html>
> <sun:head id="head" />
> <sun:body>
> <sun:form id="form">
> "<p> </p>
> <!if $attribute{in} & ! ($attribute{in} = abc) >
> "<b>You typed: #{in}, try typing: abc</b>
> </if>
> <!if !$attribute{in}>
> "<b>Type something and click 'Go!'</b>
> </if>
> <!if $attribute{in}=abc>
> "<b>Congratulations! You did it!</b>
> </if>
>
> "<br /><br />
> <sun:textField id="in" value="#{requestScope.in}" />
>
> "<br /><br />
> <sun:hyperlink text="Go!" />
> </sun:form>
> </sun:body>
> </sun:html>
> </sun:page>
>
>
>------------------------------------------------------------------------
>
><sun:page>
> <sun:html>
> <sun:head id="head" />
> <sun:body>
> <sun:form id="form">
> "<br /><br />
>
> <!if true>
> "true<br />
> </if>
>
> <!if !false>
> "!false<br />
> </if>
>
> <!if (true & (!(true & false) | (!true & false))) | false>
> "(true & (!(true & false) | (!true & false))) | false<br />
> </if>
>
> <!if foo=foo>
> "foo=foo<br />
> </if>
>
> <!if 33<100>
> "33<100<br />
> </if>
>
> # NOTE: \ is required before '>' so if isn't terminated early
> <!if 1111\>9>
> "1111>9<br />
> </if>
>
> <!if 13%5 = 3>
> "13%5 = 3<br />
> </if>
>
> <!if 13%5 = 3>
> "13%5 = 3<br />
> </if>
>
> <!if (13%5 \> 1) | false>
> "(13%5 > 1) | false<br />
> </if>
>
> <!if !(13%5 < 1) & true>
> "!(13%5 < 1) & true<br />
> </if>
>
> </sun:form>
> </sun:body>
> </sun:html>
> </sun:page>
>
>