Hi Mike,
The attached message was recently sent out re: <if>. Try: <!if true>
and <!if false>. You can also use the following operators:
= // String comarison (actually uses "left.matches(right)" so
regexp may work)
| // Logical OR
& // Logical AND
! // NOT
< // Less Than
> // Greater than
& // Modulus
And of course, you can use ()'s to override the order of operations.
See PermissionChecker.java for more info...
Ken
Mike Wright wrote:
> Hi Ken,
>
> I'm having trouble with <!if>, are there any examples or tests that
> demonstrate how to use it?
>
>
> Whne I tried this:
>
>> "<br />(before)
>> <!if $boolean{true} >
>> "<br />true!
>> </!if>
>> <!if $boolean{false} >
>> "<br />false ?
>> </!if>
>> <!if $boolean{true} != $boolean{false} >
>> "<br />true does not equal false
>> </!if>
>> <!if $boolean{true} == $boolean{false} >
>> "<br />true equals false?!
>> </!if>
>> "<br />(afer)
>>
>
> I get this:
>
>> (before)
>> true!
>> true does not equal false
>> true equals false?!
>> (after)
>
> So why does the false expression evaluate to true?
>
>
> Also, if I try this:
>
>> <!if #{sessionScope["hasMetadataComponentTypeBreadcrumb"]} >
>> "<br />conditional breadcrumb link rendered=true
>> </!if>
>
> I get a traceback, about an element not being closed. If I try adding
> quotes, I get an expression that always evaluates to true.
>
>
> I've tried various other things, none of which have allowed me to
> conditionally wrap a set of elements. I grep'ed the admin-gui code
> and couldn't find any examples of using <!if>.
>
>
> Can you give concrete examples of how I can check a session variable
> for a true or false value in <!if>?
>
>
> In the meantime, I will use the two panelGroups with rendered
> attribute (complimentary) boolean expressions.
>
> Regards,
> Mike
> ---
>
>
>
> Ken Paulsen wrote:
>
>>
>> Hi Mike,
>>
>> For conditionally rendering components you can do anything you can w/
>> vanilla JSF (i.e. rendered="false"... although you may need to do
>> $boolean{false} to properly convert it).
>>
>> You can also use the <if> component to use a boolean expression to
>> determine if its children should be rendered. However, if poorly
>> written components do not render all their children, or expect only
>> children of a particular type... they may not properly work with the
>> <if> component. (BTW, the if can be used as a regular component or
>> via special syntax: <!if [boolean expression]> [conditionally
>> rendered children] </if>).
>>
>> Looking at the Breadcrumbs source code (the source I have is old...
>> so perhaps its been fixed), it appears that:
>>
>> 1) They only allow Hyperlink components (bad)
>>
>> 2) They do not respect "rendered=false" components (bad)
>>
>> The code iterates over all children, casts each one unnecessarily to
>> a Hyperlink (it does use the "text" property, but could just as
>> easily use the "real" "value" property and do so via the attribute
>> map). It then unconditionally renders each one (which may be hidden,
>> so it won't show up) and immediately places the separator (also
>> unconditionally).
>>
>> So what you are attempting to do will not work because of the way the
>> component was written. You should file a bug against the component
>> and hope that it has already been fixed or that it will soon.
>>
>> Good luck!
>>
>> Ken
>>
>> Mike Wright wrote:
>>
>>> I'm trying to get the displayed breadcrumbs to accurately show the
>>> path I followed to get to a (shared) page, but in order to support
>>> the maximum number of links in the breadcrumbs, I see a problem when
>>> the path requires fewer links. e.g.
>>>
>>> > good: Application Server > Integration Applications > JBI
>>> Components > Libraries > placeholder SL > jbi.xml
>>> > bad: Application Server > Integration Applications > JBI
>>> Deployments > > placeholder SA > jbi.xml
>>> > s/b: Application Server > Integration Applications > JBI
>>> Deployments > placeholder SA > jbi.xml
>>>
>>> I include a .jsf page from four other .jsf pages, with breadcrumbs
>>> in the included file. The "including" .jsf files set the text/link
>>> values for the variable breadcrumbs. I've tried also setting a
>>> boolean in the "including" .jsf files to use with a rendered
>>> attribute on the not-always-needed breadcrumb hyperlink and I've
>>> tried setting the text/link values to empty string when they are not
>>> needed, but I end up with an extra ">" separator. (I've tried
>>> various things for the argument of the rendered attribute; it
>>> appears that these don't evaluate to false?)
>>>
>>> What's the recommended jsftemplating "best practice" for expressing
>>> a variable number of conditionally rendered subelements?
>>>
>>> Is there a documented expression language that I can use and any
>>> example?
>>>
>>> Regards,
>>> Mike
>>
attached mail follows:
Hi Anissa,
I may support this the way you listed below, however, the support
doesn't exist right now. (FYI, the basic support for this in handlers
is there as handlers can be hierarchical and conditionally execute
"child" handlers... but the syntax is not robust enough to create this
use case.)
There is "if" support a the "(Layout)Component" level, however. This
allows you to make conditional areas of a page. Something like:
<if $attribute{"version"}=EE>
"This is the EE Version
</if>
<if !($attribute{"version"}=EE)>
"This is the PE Version
</if>
I'd like to expand this to support "else" and to expand this to
handlers... please file an enhancement request on issue tracker if you
can. In the mean time, I hope the above syntax will support what you need.
Thanks!
Ken
Anissa Lam wrote:
> Hi Ken,
>
> I want to know if 'if' is supported in jsftemplating. If so, can
> you show us the syntax on how to use it ?
>
> Specificially, i am looking for something like this:
>
> <event>
> <! beforeEncode
> *if ( $attribute{"version"} == "EE") *{
> println(value="this is EE version");
> } ???? Can i use else here ?
> *if ($attribute{"version"} != "EE") *{
> println(value=" This is NOT EE version");
> }
> />
> </event>
>
> thanks
> Anissa
>