You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by yuvalgo <yu...@gmail.com> on 2006/12/27 14:36:27 UTC

Failing to take control of navigation

Hi,
Im trying to take control of the navigation.
let me explain: 
I wish to have my own piece of code to parse the request URI and control the
navigation to the next JSF page.
This functionality is desired for accomplishing a permalinks scheme of some
sort.
For example

The link root/yuval/yuvals_stuff should cause the following to happen:

- I parse the request with a servlet filter and know that we need to load
some data for yuval.
- I use a ViewHandler to load the data (it delegates the call to some
service that gets the data from the database)
- I now forward the user to a known jsf page that is bounded with the
viehandler and presents yuval's stuff .

Actually, the first time i try to use the code, the navigation goes well.
But right after refresh or calling the same url again I get an exception.
The code and the exception are provided here:


Here is what i do inside a servlet filter (I also tried to put this code
inside the faces servlet, just for testing):

<code>
FacesContext fc = FacesUtils.getFacesContext(req, res);
			
String action = "#{viewPollViewHandler.go2}";
			
javax.faces.application.Application application = fc.getApplication();
MethodBinding mb =
application.createMethodBinding("#{viewPollViewHandler.go2}",null);
String outcome = (String)mb.invoke(fc, null);
			
String fromAction = mb.getExpressionString();
NavigationHandler navigationHandler = application.getNavigationHandler();
navigationHandler.handleNavigation(fc, fromAction, outcome);
String viewId = fc.getViewRoot().getViewId();
UIViewRoot view = fc.getApplication().getViewHandler().createView(fc,
viewId);
view.setViewId(viewId);
fc.setViewRoot(view);
        
fc.getExternalContext().dispatch(viewId);
fc.responseComplete();
</code>

Explanation:

First we try to get the FacesContext, using the current request and response
objects. Now we know what action we want to invoke on what ViewHandler, so
we go ahead and make a method binding for this method through the JSF
Application context. Now we invoke the method and get the outcome String
from it. Till now everything seems to work ok – we get the ViewHandler's
method invoked correctly and we get the proper outcome String from it.
This means the ViewHandler is now populated with our needed data, so all we
have left to do is go to the presentation page that uses this ViewHandler.
We use JSF's NavigationHandler to navigate as usual, giving it a
"fromAction" and an outcome. Now we want the name of the page for this
navigation, so we get the view id from the FacesContext. The view id is
correct and points to the next page as states in the faces-navigation.xml,
so we set it as the new view root and try to "dispatch()" (which is the same
as "forward()") to it.
The result seems sufficient, as we get to the next page and all the data is
presented correctly (sometimes, in IE only we experienced some javascript
errors that were unknown). The big problem occurs when trying to hit
"REFRESH" or clicking back and then trying the original href link again. We
suddenly get a NullPointerException that occurred in the "getValue()" method
of JSF's getValueBinding()".

Can anyone contribute?

Thank in advance!
Yuval.

-- 
View this message in context: http://www.nabble.com/Failing-to-take-control-of-navigation-tf2886114.html#a8062889
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Failing to take control of navigation

Posted by yuvalgo <yu...@gmail.com>.
Thank Volker. It works well.


yuvalgo wrote:
> 
> Hi Volker,
> Thanks for the reply. I will check it and get back to update.
> 
> Yuval.
> 
> 
> Volker Weber-4 wrote:
>> 
>> Hi,
>> 
>>> Can anyone think of another elegant way of implementing permalinks with
>>> jsf?
>> 
>> http://wiki.apache.org/myfaces/InvokingJsfPagesWithStandardUrls#head-6c1aaf488d48f938896da962aaa4361ec3ffaf70
>> 
>> Regards,
>>   volker
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Failing-to-take-control-of-navigation-tf2886114.html#a8253107
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Failing to take control of navigation

Posted by yuvalgo <yu...@gmail.com>.
Hi Volker,
Thanks for the reply. I will check it and get back to update.

Yuval.


Volker Weber-4 wrote:
> 
> Hi,
> 
>> Can anyone think of another elegant way of implementing permalinks with
>> jsf?
> 
> http://wiki.apache.org/myfaces/InvokingJsfPagesWithStandardUrls#head-6c1aaf488d48f938896da962aaa4361ec3ffaf70
> 
> Regards,
>   volker
> 
> 

-- 
View this message in context: http://www.nabble.com/Failing-to-take-control-of-navigation-tf2886114.html#a8107220
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Failing to take control of navigation

Posted by Volker Weber <we...@googlemail.com>.
Hi,

> Can anyone think of another elegant way of implementing permalinks with jsf?

http://wiki.apache.org/myfaces/InvokingJsfPagesWithStandardUrls#head-6c1aaf488d48f938896da962aaa4361ec3ffaf70

Regards,
  volker

Re: Failing to take control of navigation

Posted by Calvin Hill <ch...@gmail.com>.
Alright, I need to clear up issue with what I wrote below.  First, it  
is correct that Shale remoting will get you to a function on a  
managed bean from a get request.  Though, since it was not part of  
the lifecycle, there will not be a response and you will end up with  
a blank page (at least I did).  The email from Volker that gave the  
wiki link, that page has an example of getting the lifecycle and  
rendering the facesContext.  This is what I did so that response went  
to the correct view.  Sorry for any confusion.

Thanks,

Calvin Hill
return Programmer.someType()


On Dec 27, 2006, at 4:33 PM, Calvin Hill wrote:

> Ok, you are trying to do a request (some form of permanent link)  
> that will access another JSF page, right?  Of course, this link  
> could be from a static html page, too.  Well, we had the same  
> problem.  MyFaces has one way of doing it that is found on their  
> Wiki (can't find it) using a Servlet.  What we ended up doing is  
> using Shale remoting.  You will need to add shale-application,  
> shale-core, shale-remoting to your project.  Then open the web.xml  
> file and add the following to the filter section;
> 	<filter>
>         	<filter-name>shale</filter-name>
>         	<filter- 
> class>org.apache.shale.application.faces.ShaleApplicationFilter</ 
> filter-class>
>     	</filter>
>
>     	<filter-mapping>
>         	<filter-name>shale</filter-name>
>         	<url-pattern>*.jsf</url-pattern>
>     	</filter-mapping>
>
> Now add to the context-param section;
> 	<context-param>
>         	<param-name>
>             		org.apache.shale.remoting.DYNAMIC_RESOURCES
>         	</param-name>
>         	<param-value>
>             		/dynamic/ 
> *:org.apache.shale.remoting.impl.MethodBindingProcessor
>         	</param-value>
>     	</context-param>
>
> Now if you have a class called IceCream and it is in the faces- 
> config.xml file being managed as icecreamBean; then from the page  
> you want to add a permlink add "dynamic/icecreamBean/ 
> mixMe.jsf" (dynamic refers to what was added in the web.xml  
> file).   mixMe is a function within IceCream.  Now, I am just  
> learning Shale and have had help (lots).  So don't think that I  
> came up with this all on my own ;).   So now your function can do  
> what it needs and return an action that can be used for  
> navigation.  If this is not it, I do hope someone else is able to  
> assist.
>
> Calvin Hill
> return Programmer.someType()
>
>
>
>
> On Dec 27, 2006, at 1:25 PM, yuvalgo wrote:
>
>>
>> Hi Calvin,
>>
>> I am able to get to the filter again, but there is this myfaces
>> nullpointerexception problem.
>>
>> This is really strange.
>> Can anyone think of another elegant way of implementing permalinks  
>> with jsf?
>>
>> Thanks.
>>
>>
>> Calvin Hill-2 wrote:
>>>
>>> Hello,
>>>
>>> I have had a similar problem but not using JSF.  I was using a home
>>> grown MVC application.  The problem I experienced was doing a  
>>> request
>>> using a specific URI.  The URI was like so "webapp/somePage.jsp".  I
>>> was able to fix it by changing it to "/webapp/somePage.jsp".  The
>>> first time you can get to that page just fine.  But any subsequent
>>> time you could not.  I don't know if these are two entirely  
>>> different
>>> problems that cause the same effect or what.
>>>
>>> The next question I would ask is, on a refresh or clicking the  
>>> href a
>>> second time are you able to step through your servlet filter again?
>>> Was there something in request scope on the first click but when you
>>> do a refresh or the href click, that something is no longer there?
>>> You are dying on the JSF page you were forward too; so I bet you are
>>> getting to the filter.
>>>
>>> Calvin Hill
>>> return Programmer.someType()
>>>
>>>
>>>
>>>
>>> On Dec 27, 2006, at 7:36 AM, yuvalgo wrote:
>>>
>>>>
>>>> Hi,
>>>> Im trying to take control of the navigation.
>>>> let me explain:
>>>> I wish to have my own piece of code to parse the request URI and
>>>> control the
>>>> navigation to the next JSF page.
>>>> This functionality is desired for accomplishing a permalinks scheme
>>>> of some
>>>> sort.
>>>> For example
>>>>
>>>> The link root/yuval/yuvals_stuff should cause the following to  
>>>> happen:
>>>>
>>>> - I parse the request with a servlet filter and know that we need
>>>> to load
>>>> some data for yuval.
>>>> - I use a ViewHandler to load the data (it delegates the call to  
>>>> some
>>>> service that gets the data from the database)
>>>> - I now forward the user to a known jsf page that is bounded  
>>>> with the
>>>> viehandler and presents yuval's stuff .
>>>>
>>>> Actually, the first time i try to use the code, the navigation goes
>>>> well.
>>>> But right after refresh or calling the same url again I get an
>>>> exception.
>>>> The code and the exception are provided here:
>>>>
>>>>
>>>> Here is what i do inside a servlet filter (I also tried to put this
>>>> code
>>>> inside the faces servlet, just for testing):
>>>>
>>>> <code>
>>>> FacesContext fc = FacesUtils.getFacesContext(req, res);
>>>> 			
>>>> String action = "#{viewPollViewHandler.go2}";
>>>> 			
>>>> javax.faces.application.Application application =  
>>>> fc.getApplication();
>>>> MethodBinding mb =
>>>> application.createMethodBinding("#{viewPollViewHandler.go2}",null);
>>>> String outcome = (String)mb.invoke(fc, null);
>>>> 			
>>>> String fromAction = mb.getExpressionString();
>>>> NavigationHandler navigationHandler =
>>>> application.getNavigationHandler();
>>>> navigationHandler.handleNavigation(fc, fromAction, outcome);
>>>> String viewId = fc.getViewRoot().getViewId();
>>>> UIViewRoot view = fc.getApplication().getViewHandler().createView 
>>>> (fc,
>>>> viewId);
>>>> view.setViewId(viewId);
>>>> fc.setViewRoot(view);
>>>>
>>>> fc.getExternalContext().dispatch(viewId);
>>>> fc.responseComplete();
>>>> </code>
>>>>
>>>> Explanation:
>>>>
>>>> First we try to get the FacesContext, using the current request and
>>>> response
>>>> objects. Now we know what action we want to invoke on what
>>>> ViewHandler, so
>>>> we go ahead and make a method binding for this method through  
>>>> the JSF
>>>> Application context. Now we invoke the method and get the outcome
>>>> String
>>>> from it. Till now everything seems to work ok – we get the
>>>> ViewHandler's
>>>> method invoked correctly and we get the proper outcome String  
>>>> from it.
>>>> This means the ViewHandler is now populated with our needed data,
>>>> so all we
>>>> have left to do is go to the presentation page that uses this
>>>> ViewHandler.
>>>> We use JSF's NavigationHandler to navigate as usual, giving it a
>>>> "fromAction" and an outcome. Now we want the name of the page  
>>>> for this
>>>> navigation, so we get the view id from the FacesContext. The view
>>>> id is
>>>> correct and points to the next page as states in the faces-
>>>> navigation.xml,
>>>> so we set it as the new view root and try to "dispatch()" (which is
>>>> the same
>>>> as "forward()") to it.
>>>> The result seems sufficient, as we get to the next page and all the
>>>> data is
>>>> presented correctly (sometimes, in IE only we experienced some
>>>> javascript
>>>> errors that were unknown). The big problem occurs when trying to  
>>>> hit
>>>> "REFRESH" or clicking back and then trying the original href link
>>>> again. We
>>>> suddenly get a NullPointerException that occurred in the "getValue
>>>> ()" method
>>>> of JSF's getValueBinding()".
>>>>
>>>> Can anyone contribute?
>>>>
>>>> Thank in advance!
>>>> Yuval.
>>>>
>>>> -- 
>>>> View this message in context: http://www.nabble.com/Failing-to- 
>>>> take-
>>>> control-of-navigation-tf2886114.html#a8062889
>>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>>
>>>
>>>
>>>
>>
>> -- 
>> View this message in context: http://www.nabble.com/Failing-to- 
>> take-control-of-navigation-tf2886114.html#a8066419
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
>


Re: Failing to take control of navigation

Posted by Calvin Hill <ch...@gmail.com>.
Ok, you are trying to do a request (some form of permanent link) that  
will access another JSF page, right?  Of course, this link could be  
from a static html page, too.  Well, we had the same problem.   
MyFaces has one way of doing it that is found on their Wiki (can't  
find it) using a Servlet.  What we ended up doing is using Shale  
remoting.  You will need to add shale-application, shale-core, shale- 
remoting to your project.  Then open the web.xml file and add the  
following to the filter section;
	<filter>
         	<filter-name>shale</filter-name>
         	<filter- 
class>org.apache.shale.application.faces.ShaleApplicationFilter</ 
filter-class>
     	</filter>

     	<filter-mapping>
         	<filter-name>shale</filter-name>
         	<url-pattern>*.jsf</url-pattern>
     	</filter-mapping>

Now add to the context-param section;
	<context-param>
         	<param-name>
             		org.apache.shale.remoting.DYNAMIC_RESOURCES
         	</param-name>
         	<param-value>
             		/dynamic/ 
*:org.apache.shale.remoting.impl.MethodBindingProcessor
         	</param-value>
     	</context-param>

Now if you have a class called IceCream and it is in the faces- 
config.xml file being managed as icecreamBean; then from the page you  
want to add a permlink add "dynamic/icecreamBean/mixMe.jsf" (dynamic  
refers to what was added in the web.xml file).   mixMe is a function  
within IceCream.  Now, I am just learning Shale and have had help  
(lots).  So don't think that I came up with this all on my own ;).    
So now your function can do what it needs and return an action that  
can be used for navigation.  If this is not it, I do hope someone  
else is able to assist.

Calvin Hill
return Programmer.someType()




On Dec 27, 2006, at 1:25 PM, yuvalgo wrote:

>
> Hi Calvin,
>
> I am able to get to the filter again, but there is this myfaces
> nullpointerexception problem.
>
> This is really strange.
> Can anyone think of another elegant way of implementing permalinks  
> with jsf?
>
> Thanks.
>
>
> Calvin Hill-2 wrote:
>>
>> Hello,
>>
>> I have had a similar problem but not using JSF.  I was using a home
>> grown MVC application.  The problem I experienced was doing a request
>> using a specific URI.  The URI was like so "webapp/somePage.jsp".  I
>> was able to fix it by changing it to "/webapp/somePage.jsp".  The
>> first time you can get to that page just fine.  But any subsequent
>> time you could not.  I don't know if these are two entirely different
>> problems that cause the same effect or what.
>>
>> The next question I would ask is, on a refresh or clicking the href a
>> second time are you able to step through your servlet filter again?
>> Was there something in request scope on the first click but when you
>> do a refresh or the href click, that something is no longer there?
>> You are dying on the JSF page you were forward too; so I bet you are
>> getting to the filter.
>>
>> Calvin Hill
>> return Programmer.someType()
>>
>>
>>
>>
>> On Dec 27, 2006, at 7:36 AM, yuvalgo wrote:
>>
>>>
>>> Hi,
>>> Im trying to take control of the navigation.
>>> let me explain:
>>> I wish to have my own piece of code to parse the request URI and
>>> control the
>>> navigation to the next JSF page.
>>> This functionality is desired for accomplishing a permalinks scheme
>>> of some
>>> sort.
>>> For example
>>>
>>> The link root/yuval/yuvals_stuff should cause the following to  
>>> happen:
>>>
>>> - I parse the request with a servlet filter and know that we need
>>> to load
>>> some data for yuval.
>>> - I use a ViewHandler to load the data (it delegates the call to  
>>> some
>>> service that gets the data from the database)
>>> - I now forward the user to a known jsf page that is bounded with  
>>> the
>>> viehandler and presents yuval's stuff .
>>>
>>> Actually, the first time i try to use the code, the navigation goes
>>> well.
>>> But right after refresh or calling the same url again I get an
>>> exception.
>>> The code and the exception are provided here:
>>>
>>>
>>> Here is what i do inside a servlet filter (I also tried to put this
>>> code
>>> inside the faces servlet, just for testing):
>>>
>>> <code>
>>> FacesContext fc = FacesUtils.getFacesContext(req, res);
>>> 			
>>> String action = "#{viewPollViewHandler.go2}";
>>> 			
>>> javax.faces.application.Application application =  
>>> fc.getApplication();
>>> MethodBinding mb =
>>> application.createMethodBinding("#{viewPollViewHandler.go2}",null);
>>> String outcome = (String)mb.invoke(fc, null);
>>> 			
>>> String fromAction = mb.getExpressionString();
>>> NavigationHandler navigationHandler =
>>> application.getNavigationHandler();
>>> navigationHandler.handleNavigation(fc, fromAction, outcome);
>>> String viewId = fc.getViewRoot().getViewId();
>>> UIViewRoot view = fc.getApplication().getViewHandler().createView 
>>> (fc,
>>> viewId);
>>> view.setViewId(viewId);
>>> fc.setViewRoot(view);
>>>
>>> fc.getExternalContext().dispatch(viewId);
>>> fc.responseComplete();
>>> </code>
>>>
>>> Explanation:
>>>
>>> First we try to get the FacesContext, using the current request and
>>> response
>>> objects. Now we know what action we want to invoke on what
>>> ViewHandler, so
>>> we go ahead and make a method binding for this method through the  
>>> JSF
>>> Application context. Now we invoke the method and get the outcome
>>> String
>>> from it. Till now everything seems to work ok – we get the
>>> ViewHandler's
>>> method invoked correctly and we get the proper outcome String  
>>> from it.
>>> This means the ViewHandler is now populated with our needed data,
>>> so all we
>>> have left to do is go to the presentation page that uses this
>>> ViewHandler.
>>> We use JSF's NavigationHandler to navigate as usual, giving it a
>>> "fromAction" and an outcome. Now we want the name of the page for  
>>> this
>>> navigation, so we get the view id from the FacesContext. The view
>>> id is
>>> correct and points to the next page as states in the faces-
>>> navigation.xml,
>>> so we set it as the new view root and try to "dispatch()" (which is
>>> the same
>>> as "forward()") to it.
>>> The result seems sufficient, as we get to the next page and all the
>>> data is
>>> presented correctly (sometimes, in IE only we experienced some
>>> javascript
>>> errors that were unknown). The big problem occurs when trying to hit
>>> "REFRESH" or clicking back and then trying the original href link
>>> again. We
>>> suddenly get a NullPointerException that occurred in the "getValue
>>> ()" method
>>> of JSF's getValueBinding()".
>>>
>>> Can anyone contribute?
>>>
>>> Thank in advance!
>>> Yuval.
>>>
>>> -- 
>>> View this message in context: http://www.nabble.com/Failing-to-take-
>>> control-of-navigation-tf2886114.html#a8062889
>>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>>
>>
>>
>>
>
> -- 
> View this message in context: http://www.nabble.com/Failing-to-take- 
> control-of-navigation-tf2886114.html#a8066419
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>


Re: Failing to take control of navigation

Posted by yuvalgo <yu...@gmail.com>.
Hi Calvin,

I am able to get to the filter again, but there is this myfaces
nullpointerexception problem.

This is really strange.
Can anyone think of another elegant way of implementing permalinks with jsf?

Thanks.


Calvin Hill-2 wrote:
> 
> Hello,
> 
> I have had a similar problem but not using JSF.  I was using a home  
> grown MVC application.  The problem I experienced was doing a request  
> using a specific URI.  The URI was like so "webapp/somePage.jsp".  I  
> was able to fix it by changing it to "/webapp/somePage.jsp".  The  
> first time you can get to that page just fine.  But any subsequent  
> time you could not.  I don't know if these are two entirely different  
> problems that cause the same effect or what.
> 
> The next question I would ask is, on a refresh or clicking the href a  
> second time are you able to step through your servlet filter again?   
> Was there something in request scope on the first click but when you  
> do a refresh or the href click, that something is no longer there?   
> You are dying on the JSF page you were forward too; so I bet you are  
> getting to the filter.
> 
> Calvin Hill
> return Programmer.someType()
> 
> 
> 
> 
> On Dec 27, 2006, at 7:36 AM, yuvalgo wrote:
> 
>>
>> Hi,
>> Im trying to take control of the navigation.
>> let me explain:
>> I wish to have my own piece of code to parse the request URI and  
>> control the
>> navigation to the next JSF page.
>> This functionality is desired for accomplishing a permalinks scheme  
>> of some
>> sort.
>> For example
>>
>> The link root/yuval/yuvals_stuff should cause the following to happen:
>>
>> - I parse the request with a servlet filter and know that we need  
>> to load
>> some data for yuval.
>> - I use a ViewHandler to load the data (it delegates the call to some
>> service that gets the data from the database)
>> - I now forward the user to a known jsf page that is bounded with the
>> viehandler and presents yuval's stuff .
>>
>> Actually, the first time i try to use the code, the navigation goes  
>> well.
>> But right after refresh or calling the same url again I get an  
>> exception.
>> The code and the exception are provided here:
>>
>>
>> Here is what i do inside a servlet filter (I also tried to put this  
>> code
>> inside the faces servlet, just for testing):
>>
>> <code>
>> FacesContext fc = FacesUtils.getFacesContext(req, res);
>> 			
>> String action = "#{viewPollViewHandler.go2}";
>> 			
>> javax.faces.application.Application application = fc.getApplication();
>> MethodBinding mb =
>> application.createMethodBinding("#{viewPollViewHandler.go2}",null);
>> String outcome = (String)mb.invoke(fc, null);
>> 			
>> String fromAction = mb.getExpressionString();
>> NavigationHandler navigationHandler =  
>> application.getNavigationHandler();
>> navigationHandler.handleNavigation(fc, fromAction, outcome);
>> String viewId = fc.getViewRoot().getViewId();
>> UIViewRoot view = fc.getApplication().getViewHandler().createView(fc,
>> viewId);
>> view.setViewId(viewId);
>> fc.setViewRoot(view);
>>
>> fc.getExternalContext().dispatch(viewId);
>> fc.responseComplete();
>> </code>
>>
>> Explanation:
>>
>> First we try to get the FacesContext, using the current request and  
>> response
>> objects. Now we know what action we want to invoke on what  
>> ViewHandler, so
>> we go ahead and make a method binding for this method through the JSF
>> Application context. Now we invoke the method and get the outcome  
>> String
>> from it. Till now everything seems to work ok – we get the  
>> ViewHandler's
>> method invoked correctly and we get the proper outcome String from it.
>> This means the ViewHandler is now populated with our needed data,  
>> so all we
>> have left to do is go to the presentation page that uses this  
>> ViewHandler.
>> We use JSF's NavigationHandler to navigate as usual, giving it a
>> "fromAction" and an outcome. Now we want the name of the page for this
>> navigation, so we get the view id from the FacesContext. The view  
>> id is
>> correct and points to the next page as states in the faces- 
>> navigation.xml,
>> so we set it as the new view root and try to "dispatch()" (which is  
>> the same
>> as "forward()") to it.
>> The result seems sufficient, as we get to the next page and all the  
>> data is
>> presented correctly (sometimes, in IE only we experienced some  
>> javascript
>> errors that were unknown). The big problem occurs when trying to hit
>> "REFRESH" or clicking back and then trying the original href link  
>> again. We
>> suddenly get a NullPointerException that occurred in the "getValue 
>> ()" method
>> of JSF's getValueBinding()".
>>
>> Can anyone contribute?
>>
>> Thank in advance!
>> Yuval.
>>
>> -- 
>> View this message in context: http://www.nabble.com/Failing-to-take- 
>> control-of-navigation-tf2886114.html#a8062889
>> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Failing-to-take-control-of-navigation-tf2886114.html#a8066419
Sent from the MyFaces - Users mailing list archive at Nabble.com.


Re: Failing to take control of navigation

Posted by Calvin Hill <ch...@gmail.com>.
Hello,

I have had a similar problem but not using JSF.  I was using a home  
grown MVC application.  The problem I experienced was doing a request  
using a specific URI.  The URI was like so "webapp/somePage.jsp".  I  
was able to fix it by changing it to "/webapp/somePage.jsp".  The  
first time you can get to that page just fine.  But any subsequent  
time you could not.  I don't know if these are two entirely different  
problems that cause the same effect or what.

The next question I would ask is, on a refresh or clicking the href a  
second time are you able to step through your servlet filter again?   
Was there something in request scope on the first click but when you  
do a refresh or the href click, that something is no longer there?   
You are dying on the JSF page you were forward too; so I bet you are  
getting to the filter.

Calvin Hill
return Programmer.someType()




On Dec 27, 2006, at 7:36 AM, yuvalgo wrote:

>
> Hi,
> Im trying to take control of the navigation.
> let me explain:
> I wish to have my own piece of code to parse the request URI and  
> control the
> navigation to the next JSF page.
> This functionality is desired for accomplishing a permalinks scheme  
> of some
> sort.
> For example
>
> The link root/yuval/yuvals_stuff should cause the following to happen:
>
> - I parse the request with a servlet filter and know that we need  
> to load
> some data for yuval.
> - I use a ViewHandler to load the data (it delegates the call to some
> service that gets the data from the database)
> - I now forward the user to a known jsf page that is bounded with the
> viehandler and presents yuval's stuff .
>
> Actually, the first time i try to use the code, the navigation goes  
> well.
> But right after refresh or calling the same url again I get an  
> exception.
> The code and the exception are provided here:
>
>
> Here is what i do inside a servlet filter (I also tried to put this  
> code
> inside the faces servlet, just for testing):
>
> <code>
> FacesContext fc = FacesUtils.getFacesContext(req, res);
> 			
> String action = "#{viewPollViewHandler.go2}";
> 			
> javax.faces.application.Application application = fc.getApplication();
> MethodBinding mb =
> application.createMethodBinding("#{viewPollViewHandler.go2}",null);
> String outcome = (String)mb.invoke(fc, null);
> 			
> String fromAction = mb.getExpressionString();
> NavigationHandler navigationHandler =  
> application.getNavigationHandler();
> navigationHandler.handleNavigation(fc, fromAction, outcome);
> String viewId = fc.getViewRoot().getViewId();
> UIViewRoot view = fc.getApplication().getViewHandler().createView(fc,
> viewId);
> view.setViewId(viewId);
> fc.setViewRoot(view);
>
> fc.getExternalContext().dispatch(viewId);
> fc.responseComplete();
> </code>
>
> Explanation:
>
> First we try to get the FacesContext, using the current request and  
> response
> objects. Now we know what action we want to invoke on what  
> ViewHandler, so
> we go ahead and make a method binding for this method through the JSF
> Application context. Now we invoke the method and get the outcome  
> String
> from it. Till now everything seems to work ok – we get the  
> ViewHandler's
> method invoked correctly and we get the proper outcome String from it.
> This means the ViewHandler is now populated with our needed data,  
> so all we
> have left to do is go to the presentation page that uses this  
> ViewHandler.
> We use JSF's NavigationHandler to navigate as usual, giving it a
> "fromAction" and an outcome. Now we want the name of the page for this
> navigation, so we get the view id from the FacesContext. The view  
> id is
> correct and points to the next page as states in the faces- 
> navigation.xml,
> so we set it as the new view root and try to "dispatch()" (which is  
> the same
> as "forward()") to it.
> The result seems sufficient, as we get to the next page and all the  
> data is
> presented correctly (sometimes, in IE only we experienced some  
> javascript
> errors that were unknown). The big problem occurs when trying to hit
> "REFRESH" or clicking back and then trying the original href link  
> again. We
> suddenly get a NullPointerException that occurred in the "getValue 
> ()" method
> of JSF's getValueBinding()".
>
> Can anyone contribute?
>
> Thank in advance!
> Yuval.
>
> -- 
> View this message in context: http://www.nabble.com/Failing-to-take- 
> control-of-navigation-tf2886114.html#a8062889
> Sent from the MyFaces - Users mailing list archive at Nabble.com.
>