Nicklas, in the case of hiding a component, have you tried
setting the disabled or rendered attributes with EL? try
something like :
rendered="#{UserPermissionsBean.hasSomeAccessRight}"
---- Original message ----
>Date: Sun, 13 Nov 2005 08:51:43 +1300
>From: Simon Kitching <[EMAIL PROTECTED]>
>Subject: Re: Component manipulation in phase listener
>To: MyFaces Discussion <[email protected]>
>
>Nicklas Karlsson wrote:
>> Hello,
>>
>> I'm a JSF-noob(tm) and fresh convert from Struts so
there might be
>> something with the lifecycle I don't understund but...
>>
>> I'm trying to make a DB-configurable application using a
phase
>> listener that iterates over all the components in the tree
and applies
>> attributes, validators etc to them the id can be found in
a map of
>> description objects (or hide the component if the user
doesn't have
>> access to it)
>>
>> I can't however make the changes take effect when
running the page for
>> the first time. I attached the listener to all phases and
the debug code
>> shows that it is doing a setRendered(false) for a
component but it still
>> shows up! When I navigate back to the page the component
disappears.
>> Something with phases being skipped when there is nothing
to restore? If
>> so, is there a way to get around this (by using some
other "for every
>> page" method)?
>
>Are you using JSP with JSF?
>
>Assuming you are, the flow goes something like this:
>* request received from browser
>* "before restore view" phase listener executed
>* JSF detects that no component tree currently exists for
this view
>* "after restore view" phase listener executed
>* processing skips straight to the render phase (no
component tree
> exists, so there are no components that need to fetch
data from
> the posted request, and therefore no validation or model
update or
> value-change processing can possibly occur).
>* "before render" phase listener executed (still no
component tree)
>* the JSP page is executed. As each JSF tag is encountered, a
> component object is created, then its properties set,
then it is
> added to the view tree, and then that component is
immediately
> rendered.
>* "after render" phase listener executed.
>
>I therefore don't see any way your approach is going to
work; on first
>view of a page there is no phase where all the components
exist but they
>have not been rendered.
>
>You might be able to get this approach working with Facelets
instead of
>JSP; Facelets always ensures that even on the first view of
a page, the
>component tree is built first before rendering starts.
>
>I can't for the moment think of any alternate approach that
work work
>using JSP/JSF. You might want to check out the "role"
features of the
>tomahawk components, though: this allows components to be
disabled or
>not rendered depending upon whether a user is in a
certain "role".
>
>
>Regards,
>
>Simon
Dennis Byrne