List Info

Thread: Tag vs. component with facelets




Tag vs. component with facelets
user name
2007-10-04 06:27:38
Hi,
 
I have a little problem with runtime vs build-time tags:
 
I have a component page categories.xhtml containing the snippet:

 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; < c:if test ="#{not empty ajaxScope}" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  < tc:attribute

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   name ="renderedPartially"

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   value ="#{ajaxScope}&quot; />

 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; </c:if >

 



included by a page as follows:

 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; < ui:include src ="/contract/categories.xhtml" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  < ui:param

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; name ="ajaxScope"

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; value =":page:mainInfoTabPanel&quot; />

 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; </ui:include >

 


The c:if evaluates correctly at build time and adds the attribute to its parent. But it seems tc:attribute evaluates at runtime: it finds null.
 
Having two varibales one runtime and one build time with the same value is a little barbar.
 
Anyone knows how to resolve this? Any idea is welcome.
 
Regards,
Zied
Re: Tag vs. component with facelets
country flaguser name
Germany
2007-10-04 08:48:11
Hello Zied,

maybe two Commands with the rendered attribute would be a
better choice.

Regards

Bernd



Zied Hamdi wrote:
> Hi,
> 
> I have a little problem with runtime vs build-time
tags:
> 
> I have a component page categories.xhtml containing the
snippet:
> 
>                   <c:if test="#{not empty
ajaxScope}">
> 
>                         <tc:attribute
> 
>                             
name="renderedPartially"
> 
>                             
value="#" />
> 
>                   </c:if>
> 
> 
> 
> 
> included by a page as follows:
> 
>                              <ui:include
src="/contract/categories.xhtml">
> 
>                                    <ui:param
> 
>                                         
name="ajaxScope"
> 
>                                         
value=":page:mainInfoTabPanel" />
> 
>                              </ui:include>
> 
> 
> 
> The c:if evaluates correctly at build time and adds the
attribute to its
> parent. But it seems tc:attribute evaluates at runtime:
it finds null.
> 
> Having two varibales one runtime and one build time
with the same value is a
> little barbar.
> 
> Anyone knows how to resolve this? Any idea is welcome.
> 
> Regards,
> Zied
> 

Re: Tag vs. component with facelets
user name
2007-10-04 10:47:01
Hello Bernd how are you?
&nbsp;
Was I right when I said to Volker you're on holidays? If yes I hope it was memorable.
 
I can't figure out what you meant by two commands, did you mean applying the rendered attribute on the command instead of c:if and have two commands, my c:if is only a workaround the NullPointerException I have mentioned in the last mail?
to be more explicit : this is my case. The c:if can be removed, it is there only in the case the attribute ajaxScope is not specified.

< tc:tree

 &nbsp; &nbsp;  xmlns=" http://www.w3.org/1999/xhtml&quot;

 &nbsp; &nbsp;  xmlns:f=" http://java.sun.com/jsf/core&quot;

 &nbsp; &nbsp;  xmlns:h=" http://java.sun.com/jsf/html&quot;

 &nbsp; &nbsp;  xmlns:t=" http://myfaces.apache.org/tomahawk"

 &nbsp; &nbsp;  xmlns:tc=" http://myfaces.apache.org/tobago/component"

 &nbsp; &nbsp;  xmlns:tx=" http://myfaces.apache.org/tobago/extension"

 &nbsp; &nbsp;  xmlns:c=" http://java.sun.com/jstl/core"

 &nbsp; &nbsp;  id= "categoriesTree"

 &nbsp; &nbsp;  value ="#{contractCtrl.categoriesRoot}"

 &nbsp; &nbsp;  state ="#{contractCtrl.treeState}&quot;

 &nbsp; &nbsp;  showIcons ="true"

 &nbsp; &nbsp;  mutable ="true"

 &nbsp; &nbsp;  nameReference ="userObject.embedded.name" >

 &nbsp; &nbsp;  < f:actionListener type ="fr.into.services.controller.CategoryEditionListener" />

 &nbsp; &nbsp;  < f:facet name ="treeNodeCommand" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; < tc:command actionListener ="#{contractCtrl.selectCategory}" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   < c:if test ="#{not empty ajaxScope}" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  < tc:attribute

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   name ="renderedPartially"

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   value ="#{ajaxScope}&quot; />

 

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   </ c:if>

 &nbsp; &nbsp;   ; &nbsp; &nbsp; </ tc:command>

 &nbsp; &nbsp;  </ f:facet>

 

</ tc:tree>

 


 
2007/10/4, Bernd Bohmann < bernd.bohmannatanion.com">bernd.bohmannatanion.com>:
Hello Zied,

maybe two Commands with the rendered attribute would be a better choice.

Regards

Bernd



Zied Hamdi wrote:
>; Hi,
>
&gt; I have a little problem with runtime vs build-time tags:
>
> I have a component page categories.xhtml containing the snippet:
&gt;
>&nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp;  <c:if test=";#{not empty ajaxScope}">
>
>&nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;  <tc:attribute
>
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; name="renderedPartially"
>
>  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp;value=&quot;#{ajaxScope}"; />
>
  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; </c:if&gt;
>
&gt;
>
>;
> included by a page as follows:
&gt;
>&nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;<ui:include src="/contract/categories.xhtml"&gt;
>
> &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; <ui:param
>
>  ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; name="ajaxScope&quot;
>
&gt; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ;value=&quot;:page:mainInfoTabPanel" />
&gt;
>&nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp; </ui:include>
&gt;
>
>;
> The c:if evaluates correctly at build time and adds the attribute to its
> parent. But it seems tc:attribute evaluates at runtime: it finds null.
&gt;
> Having two varibales one runtime and one build time with the same value is a
> little barbar.
&gt;
> Anyone knows how to resolve this? Any idea is welcome.
&gt;
> Regards,
&gt; Zied
>;



--
Zied Hamdi
zatreex.sourceforge.net
Re: Tag vs. component with facelets
user name
2007-10-04 16:35:42
Hello Bernd,
 
I woke up thinking: it isn't possible!! I started my computer and this test : 
 
In fact, I know that facelet9;s c:if is Tag (compile time tag), and that <ui:out> is a Component (render time tag), and I already have (render time)Components that work with the ui:include/ui:param which are (compile time) Tags.
 
So I verified my example by trying to show the value of #{ajaxScope} in a tc:out. And it shows!!! even if embedded inside a c:if tag (as was the case with the tc:attribute). Then I added again the grey backgrounded code of the attribute, and I received the NullPointerException, so I think it's a bug, or there is a third phase type behind the compile and render phasis. (by render I mean runtime)
 

< tc:panel

 &nbsp; &nbsp;  xmlns=" http://www.w3.org/1999/xhtml&quot;

 &nbsp; &nbsp;  xmlns:f=" http://java.sun.com/jsf/core&quot;

 &nbsp; &nbsp;  xmlns:h=" http://java.sun.com/jsf/html&quot;

 &nbsp; &nbsp;  xmlns:t=" http://myfaces.apache.org/tomahawk"

 &nbsp; &nbsp;  xmlns:tc=" http://myfaces.apache.org/tobago/component"

 &nbsp; &nbsp;  xmlns:tx=" http://myfaces.apache.org/tobago/extension"

 &nbsp; &nbsp;  xmlns:c=" http://java.sun.com/jstl/core">

 &nbsp; &nbsp;  <f:facet name= "layout">

 &nbsp; &nbsp;   ; &nbsp; &nbsp; < tc:gridLayout rows ="fixed;*" />

 &nbsp; &nbsp;  </ f:facet>

 

 &nbsp; &nbsp;  < c:if test ="#{not empty ajaxScope}" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; < tc:out value ="scope:   #{ajaxScope}" ></tc:out >

 &nbsp; &nbsp;  </ c:if>

 

 &nbsp; &nbsp;  < tc:tree

 &nbsp; &nbsp;   ; &nbsp; &nbsp; id ="categoriesTree&quot;

 &nbsp; &nbsp;   ; &nbsp; &nbsp; value ="#{contractCtrl.categoriesRoot}"

 &nbsp; &nbsp;   ; &nbsp; &nbsp; state ="#{contractCtrl.treeState}&quot;

 &nbsp; &nbsp;   ; &nbsp; &nbsp; showIcons ="true"

 &nbsp; &nbsp;   ; &nbsp; &nbsp; mutable ="false"

 &nbsp; &nbsp;   ; &nbsp; &nbsp; nameReference ="userObject.embedded.name" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; < f:actionListener type ="fr.into.services.controller.CategoryEditionListener" />

 &nbsp; &nbsp;   ; &nbsp; &nbsp; < f:facet name ="treeNodeCommand" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   < tc:command actionListener ="#{contractCtrl.selectCategory}" >

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  < c:if test ="#{not empty ajaxScope}" >

 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; < tc:attribute

 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   name ="renderedPartially"

 &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   value ="#{ajaxScope}&quot; />

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   ; &nbsp; &nbsp;  </ c:if>

 &nbsp; &nbsp;   ; &nbsp; &nbsp; &nbsp; &nbsp;   </ tc:command>

 &nbsp; &nbsp;   ; &nbsp; &nbsp; </ f:facet>

 &nbsp; &nbsp;  </ tc:tree>

 

</ tc:panel>

 

Here's the exception. If you confirm it's a bug, let me know so i add an issue:
 

23:27:29,359 ERROR [STDERR] 4 oct. 2007 23:27:29 com.sun.facelets.FaceletViewHandler handleRenderException

GRAVE: Error Rendering View[/contract/contract.xhtml]

java.lang.NullPointerException

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.CommandRendererHelper.initOnclick(CommandRendererHelper.java :100)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.CommandRendererHelper.&lt;init>(CommandRendererHelper.java :61)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.TreeOldRenderer.getTreeNodeCommandVar( TreeOldRenderer.java:292)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.TreeOldRenderer.createJavascript( TreeOldRenderer.java:251)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.TreeOldRenderer.encodeEnd( TreeOldRenderer.java:202)

 &nbsp; &nbsp;  at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:84 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.encodeChildrenOfComponent( GridLayoutRenderer.java:379)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIGridLayout.encodeChildrenOfComponent(UIGridLayout.java :276)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren(UIPanelBase.java :43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:77 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.DefaultLayoutRenderer.encodeChildrenOfComponent( DefaultLayoutRenderer.java:47)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren(UIPanelBase.java :43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:77 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.DefaultLayoutRenderer.encodeChildrenOfComponent( DefaultLayoutRenderer.java:47)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren(UIPanelBase.java :43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:77 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.encodeChildrenOfComponent( GridLayoutRenderer.java:379)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIGridLayout.encodeChildrenOfComponent(UIGridLayout.java :276)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren(UIPanelBase.java :43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:77 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.encodeChildrenOfComponent( GridLayoutRenderer.java:379)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIGridLayout.encodeChildrenOfComponent(UIGridLayout.java :276)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren(UIPanelBase.java :43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:77 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.DefaultLayoutRenderer.encodeChildrenOfComponent( DefaultLayoutRenderer.java:47)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren(UIPanelBase.java :43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:77 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.encodeChildrenOfComponent( GridLayoutRenderer.java:379)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIGridLayout.encodeChildrenOfComponent(UIGridLayout.java :276)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren(UIPanelBase.java :43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:77 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.DefaultLayoutRenderer.encodeChildrenOfComponent( DefaultLayoutRenderer.java:47)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encodeChildren(RenderUtil.java :56)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.speyside.standard.tag.TabGroupRenderer.encodeContent( TabGroupRenderer.java:74)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.TabGroupRenderer.renderTabGroupView( TabGroupRenderer.java:342)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.TabGroupRenderer.encodeEnd( TabGroupRenderer.java:155)

 &nbsp; &nbsp;  at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UITabGroup.encodeEnd(UITabGroup.java:106 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:84 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.DefaultLayoutRenderer.encodeChildrenOfComponent( DefaultLayoutRenderer.java:47)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent(UILayout.java :71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren(UIPanelBase.java :43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode(RenderUtil.java:77 )

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.encodeChildrenOfComponent( GridLayoutRenderer.java:379)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent( UILayout.java:71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIGridLayout.encodeChildrenOfComponent (UIGridLayout.java:276)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren (UIPanelBase.java:43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode (RenderUtil.java:77)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.DefaultLayoutRenderer.encodeChildrenOfComponent (DefaultLayoutRenderer.java:47)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent (UILayout.java:71)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UIPanelBase.encodeChildren (UIPanelBase.java:43)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.RenderUtil.encode (RenderUtil.java:77)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.renderkit.html.scarborough.standard.tag.GridLayoutRenderer.encodeChildrenOfComponent (GridLayoutRenderer.java:379)

 &nbsp; &nbsp;  at org.apache.myfaces.tobago.component.UILayout.encodeChildrenOfComponent (UILayout.java:71)