Should c:if be used with facelets?

View: New views
3 Messages — Rating Filter:   Alert me  

Should c:if be used with facelets?

by Thai :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
I read at different places that c:if should be best avoided when we use JSF (including JSF 1.2). Is that right?

I'd like to create a custom facelets component, e.g. called Box.tag.xhtml. So I write:

<ui:component>
  <c:if test="#{empty id}">
    <h:panelGroup layout="block"><ui:insert/></h:panelGroup>
  </c:if>

  <c:if test="#{not empty id}">
    <h:panelGroup layout="block" id="#{id}"><ui:insert/></h:panelGroup>
  </c:if>
</ui:component>

Is that correct?

Is there anyway to avoid that c:if?

Thank you.


Re: Should c:if be used with facelets?

by Stephen Friedrich-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Here's what I am using:
    <h:panelGroup layout="block" id="#{empty id ? facesContext.viewRoot.createUniqueId() : id}">
That exact syntax does not work in plain JSF EL, but only in the enhanced
version that comes with the Seam framework.
You could write an EL function to do the same.

However for simple kinds of tests like this I never had problems when
using c:if.
When I did have problems was in scenarios like
- in first request component A is rendered
- in postback component A is not rendered (because inside a c:if that now
   evaluates to false), but another component B (of the same type) was rendered


Thai Dang Vu wrote:

> I read at different places that c:if should be best avoided when we use
> JSF (including JSF 1.2). Is that right?
>
> I'd like to create a custom facelets component, e.g. called
> Box.tag.xhtml. So I write:
>
> <ui:component>
>   <c:if test="#{empty id}">
>     <h:panelGroup layout="block"><ui:insert/></h:panelGroup>
>   </c:if>
>
>   <c:if test="#{not empty id}">
>     <h:panelGroup layout="block" id="#{id}"><ui:insert/></h:panelGroup>
>   </c:if>
> </ui:component>
>
> Is that correct?
>
> Is there anyway to avoid that c:if?
>
> Thank you.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Should c:if be used with facelets?

by Joel Weight :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

In the case you give, you could use a ui:fragment and have the test in the rendered attribute.  I try to avoid c:if in general, but I'm a relative n00b when it comes to facelets.

<ui:component>
 <ui:fragment rendered="#{empty id}">
   <h:panelGroup layout="block"><ui:insert/></
h:panelGroup>
 </ui:fragment>

 <ui:fragment rendered="#{not empty id}">
   <h:panelGroup layout="block" id="#{id}"><ui:insert/></h:panelGroup>
 </ui:fragment>
</ui:component>


Joel


On Thu, Jan 29, 2009 at 5:57 PM, Stephen Friedrich <facelets@...> wrote:
Here's what I am using:
  <h:panelGroup layout="block" id="#{empty id ? facesContext.viewRoot.createUniqueId() : id}">
That exact syntax does not work in plain JSF EL, but only in the enhanced
version that comes with the Seam framework.
You could write an EL function to do the same.

However for simple kinds of tests like this I never had problems when
using c:if.
When I did have problems was in scenarios like
- in first request component A is rendered
- in postback component A is not rendered (because inside a c:if that now
 evaluates to false), but another component B (of the same type) was rendered



Thai Dang Vu wrote:
I read at different places that c:if should be best avoided when we use JSF (including JSF 1.2). Is that right?

I'd like to create a custom facelets component, e.g. called Box.tag.xhtml. So I write:

<ui:component>
 <c:if test="#{empty id}">
   <h:panelGroup layout="block"><ui:insert/></h:panelGroup>
 </c:if>

 <c:if test="#{not empty id}">
   <h:panelGroup layout="block" id="#{id}"><ui:insert/></h:panelGroup>
 </c:if>
</ui:component>

Is that correct?

Is there anyway to avoid that c:if?

Thank you.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...