You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Magnus Sandberg <ma...@devdep.com> on 2006/12/08 10:06:53 UTC

Rendered is called in un-rendered subtree

I'm having some issues where rendered is called for components in an
unrendered subtree (ie the component already has a parent where
rendered=false).

After some looking I found this thread:

http://www.mail-archive.com/users@myfaces.apache.org/msg24702.html

The thread includes an solution, but as the writer points out: the
solution is not elegant and requires a lot of extra code.

Is there any new info on this?

Should rendered really be evaluated in if the component is already
unrendered by a parent?

/Magnus


Re: Rendered is called in un-rendered subtree

Posted by Andrew Robinson <an...@gmail.com>.
The problem stems from the fact that the rendered flag is just a
boolean property, it is not special in any way. By way of standards
and the framework, it is up to the renderer to check this flag to see
if they should render their code.

What is interesting, is this has to be checked in all three render
methods (encodeBegin, encodeChildren and encodeEnd).

You will also notice that not all renderers handle the encoding of
children. This means that typically a parent element actually renders
their children for them. As a result, despite the fact that the
encodeBegin and encodeEnd are not processed do to the rendered check,
the children are still are encoded.

The fix? Override the renderer, and make sure the children are only
rendered if the parent component is rendered.

The other alternative, is to put your components in an group panel.
This does render the children only if the group is rendered
(getRendersChildren returns true). This code can be found in
"HtmlGroupRendererBase.java"

Odd yes that the children of a non-rendered component are encoded, but
the specification doesn't say that this is wrong. Renderers of
components can do whatever they want with the rendered flag.

-Andrew

On 12/8/06, Magnus Sandberg <ma...@devdep.com> wrote:
> I'm having some issues where rendered is called for components in an
> unrendered subtree (ie the component already has a parent where
> rendered=false).
>
> After some looking I found this thread:
>
> http://www.mail-archive.com/users@myfaces.apache.org/msg24702.html
>
> The thread includes an solution, but as the writer points out: the
> solution is not elegant and requires a lot of extra code.
>
> Is there any new info on this?
>
> Should rendered really be evaluated in if the component is already
> unrendered by a parent?
>
> /Magnus
>
>