You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Andrew Robinson <an...@gmail.com> on 2008/12/23 17:26:19 UTC

Re: Quite advanced JSF problem

This is the wrong mailing list for this question, it is not regarding
myfaces development. I am posting this reply on the users list, all
further replies should go there.

I don't think that you solution is a valid one. It is not valid to
locate a component in more than one location of one component tree. I
think this may be a "safer" solution, but still a hack:

First create a custom root component that does not render anything,
just make sure it is at the root, under the UIViewRoot (or you can
subclass UIViewRoot if you want). Then in that component, during the
phase methods (processDecodes, processValidators, etc.), check to see
if the request is an AJAX request.

Then using invokeOnComponent, find the target of your action. Move the
children into a temporary list if you want to avoid process its
children, invoke the lifecycle method on that component, then restore
the children.

Another safer method would be to use sub forms to limit the scope of the action.

-Andrew

On Tue, Dec 23, 2008 at 3:39 AM, gibiman <vi...@gmail.com> wrote:
>
> Hi ,
> I'm trying to develop custom AJAX components, and i'm facing some problems
> on the JSF technology architecture . Pay attention ;) :
>
> An action on the page launches an XMLHttpRequest to a certain URL ( .jsf
> suffix). My aim is to have the JSF engine process only a certain part of the
> JSF tree , that is the part which contains the children of the component
> that launched the request ( for example a tabPanel component generates an
> ajax request , and only that certain tabPanel needs to be processed by the
> JSF engine ) .
> My aproach on the problem was to build a listener which would :
>
> after RESTORE_VIEW(1)
>
> 1. Fetch the UIComponent which launched the request
> 2. Create a new UIViewRoot and set the new UIViewRoot to the facesContext
> 3. Add the UICompononet fetched at step 1 as child to the UIviewRoot
> 4. Invoke action specific behavior of the component -  is ok to ignore this
> part
>
>
> The thing is that new UIViewRoot will get populated - by that i mean all the
> previous children erased - on renderResponse phase with the JSP tags (
> naturally because the engine would return the corresponding viewId ) . If I
> were to set an invalid viewId , e.g. a page that would not exist, than it
> would return a 404 page not found response.
> What are your opinions on my approach , and what alternate suggestions do
> you have ?
> Victor
> --
> View this message in context: http://www.nabble.com/Quite-advanced-JSF-problem-tp21142256p21142256.html
> Sent from the My Faces - Dev mailing list archive at Nabble.com.
>
>

Re: Quite advanced JSF problem

Posted by Adam Nichols <mr...@gmail.com>.
Or DWR (http://directwebremoting.org/).  I've personally used this with 
myFaces, so I know it works.

--Adam

Matt.Rossner-prest@sanofi-aventis.com wrote:
> Have you considered using Ajax4JSF? It kind of already does what you're trying to do. It may save you a lot of time. I'm currently using it with MyFaces and it works pretty well. 
> 
> -----Original Message-----
> From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com] 
> Sent: mardi 23 décembre 2008 17:26
> To: MyFaces Development; MyFaces Discussion
> Subject: Re: Quite advanced JSF problem
> 
> This is the wrong mailing list for this question, it is not regarding
> myfaces development. I am posting this reply on the users list, all
> further replies should go there.
> 
> I don't think that you solution is a valid one. It is not valid to
> locate a component in more than one location of one component tree. I
> think this may be a "safer" solution, but still a hack:
> 
> First create a custom root component that does not render anything,
> just make sure it is at the root, under the UIViewRoot (or you can
> subclass UIViewRoot if you want). Then in that component, during the
> phase methods (processDecodes, processValidators, etc.), check to see
> if the request is an AJAX request.
> 
> Then using invokeOnComponent, find the target of your action. Move the
> children into a temporary list if you want to avoid process its
> children, invoke the lifecycle method on that component, then restore
> the children.
> 
> Another safer method would be to use sub forms to limit the scope of the action.
> 
> -Andrew
> 
> On Tue, Dec 23, 2008 at 3:39 AM, gibiman <vi...@gmail.com> wrote:
>> Hi ,
>> I'm trying to develop custom AJAX components, and i'm facing some problems
>> on the JSF technology architecture . Pay attention ;) :
>>
>> An action on the page launches an XMLHttpRequest to a certain URL ( .jsf
>> suffix). My aim is to have the JSF engine process only a certain part of the
>> JSF tree , that is the part which contains the children of the component
>> that launched the request ( for example a tabPanel component generates an
>> ajax request , and only that certain tabPanel needs to be processed by the
>> JSF engine ) .
>> My aproach on the problem was to build a listener which would :
>>
>> after RESTORE_VIEW(1)
>>
>> 1. Fetch the UIComponent which launched the request
>> 2. Create a new UIViewRoot and set the new UIViewRoot to the facesContext
>> 3. Add the UICompononet fetched at step 1 as child to the UIviewRoot
>> 4. Invoke action specific behavior of the component -  is ok to ignore this
>> part
>>
>>
>> The thing is that new UIViewRoot will get populated - by that i mean all the
>> previous children erased - on renderResponse phase with the JSP tags (
>> naturally because the engine would return the corresponding viewId ) . If I
>> were to set an invalid viewId , e.g. a page that would not exist, than it
>> would return a 404 page not found response.
>> What are your opinions on my approach , and what alternate suggestions do
>> you have ?
>> Victor
>> --
>> View this message in context: http://www.nabble.com/Quite-advanced-JSF-problem-tp21142256p21142256.html
>> Sent from the My Faces - Dev mailing list archive at Nabble.com.
>>
>>
> 

RE: Quite advanced JSF problem

Posted by Ma...@sanofi-aventis.com.
Have you considered using Ajax4JSF? It kind of already does what you're trying to do. It may save you a lot of time. I'm currently using it with MyFaces and it works pretty well. 

-----Original Message-----
From: Andrew Robinson [mailto:andrew.rw.robinson@gmail.com] 
Sent: mardi 23 décembre 2008 17:26
To: MyFaces Development; MyFaces Discussion
Subject: Re: Quite advanced JSF problem

This is the wrong mailing list for this question, it is not regarding
myfaces development. I am posting this reply on the users list, all
further replies should go there.

I don't think that you solution is a valid one. It is not valid to
locate a component in more than one location of one component tree. I
think this may be a "safer" solution, but still a hack:

First create a custom root component that does not render anything,
just make sure it is at the root, under the UIViewRoot (or you can
subclass UIViewRoot if you want). Then in that component, during the
phase methods (processDecodes, processValidators, etc.), check to see
if the request is an AJAX request.

Then using invokeOnComponent, find the target of your action. Move the
children into a temporary list if you want to avoid process its
children, invoke the lifecycle method on that component, then restore
the children.

Another safer method would be to use sub forms to limit the scope of the action.

-Andrew

On Tue, Dec 23, 2008 at 3:39 AM, gibiman <vi...@gmail.com> wrote:
>
> Hi ,
> I'm trying to develop custom AJAX components, and i'm facing some problems
> on the JSF technology architecture . Pay attention ;) :
>
> An action on the page launches an XMLHttpRequest to a certain URL ( .jsf
> suffix). My aim is to have the JSF engine process only a certain part of the
> JSF tree , that is the part which contains the children of the component
> that launched the request ( for example a tabPanel component generates an
> ajax request , and only that certain tabPanel needs to be processed by the
> JSF engine ) .
> My aproach on the problem was to build a listener which would :
>
> after RESTORE_VIEW(1)
>
> 1. Fetch the UIComponent which launched the request
> 2. Create a new UIViewRoot and set the new UIViewRoot to the facesContext
> 3. Add the UICompononet fetched at step 1 as child to the UIviewRoot
> 4. Invoke action specific behavior of the component -  is ok to ignore this
> part
>
>
> The thing is that new UIViewRoot will get populated - by that i mean all the
> previous children erased - on renderResponse phase with the JSP tags (
> naturally because the engine would return the corresponding viewId ) . If I
> were to set an invalid viewId , e.g. a page that would not exist, than it
> would return a 404 page not found response.
> What are your opinions on my approach , and what alternate suggestions do
> you have ?
> Victor
> --
> View this message in context: http://www.nabble.com/Quite-advanced-JSF-problem-tp21142256p21142256.html
> Sent from the My Faces - Dev mailing list archive at Nabble.com.
>
>