You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shale.apache.org by gerrit <ge...@deborate.de> on 2007/03/02 09:50:34 UTC

view controller – site navigation

I use the shale view controller init() method to make standard site
validations and load data. 
The init-Method has no return value and so no navigation rule is executed.
If one of my validation methods or the load data method returns an error I’d
like execute navigation rules. The reason is to go to a special error page.
Is there a possibility to navigate to another page from the init-method? 

-- 
View this message in context: http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.html#a9266099
Sent from the Shale - User mailing list archive at Nabble.com.


Re: [shale-validator] view controller – site navigation

Posted by gerrit <ge...@deborate.de>.
Hi 

If I output the view root ViewId I get the following:
ViewRoot1: /faces/projekte.jsp
ViewRoot2: /faces/aufgaben.jsp

      FacesContext facesContext = FacesContext.getCurrentInstance();
      log.debug("ViewRoot1: "+facesContext.getViewRoot().getViewId());
      NavigationHandler navigationHandler =
facesContext.getApplication().getNavigationHandler();
      navigationHandler.handleNavigation(facesContext,
"#{/faces/projekte.jsp}","successAufgaben");
      log.debug("ViewRoot2: "+facesContext.getViewRoot().getViewId());
      facesContext.renderResponse();

So in my mind the navigation handler works correct. But on the browser
projekte.jsp is shown. If I press any button on this site, the navigation
behind this button is ignored and aufgaben.jsp is shown.    

Gerrit   


craigmcc wrote:
> 
> On 3/2/07, hermod.opstvedt@dnbnor.no <he...@dnbnor.no> wrote:
>> Hi
>>
>> I think the best way to achieve what you want is to raise a flag in the
>> viewcontrollers init method. Then when the method that is supposed to be
>> executed is called, you check for the flag at the beginning and return
>> the outcome that corresponds to the error situatiuon.
>>
> 
> It actually is possible to navigate from init(), but you have to do a
> bit more work:
> 
>     FacesContext context = FacesContext.getCurrentInstance();
>     NavigationHandler nh =
> context.getApplication().getNavigationHandler();
>     String fromAction = "#{...}"; // Fake expression for the action
> you pretend executed
>     String outcome = "..."; // Fake outcome from the fake action
>     nh.handleNavigation(context, fromAction, outcome);
>     context.renderResponse(); // Skip directly to Render Response phase
> 
> The current view, plus the values you specify for fromAction and
> outcome, are fed into the standard navigation rules processing and a
> new view will be selected based on those rules (or the current view
> redisplayed if no rule matches).  The call to renderResponse() causes
> the remainder of the lifecycle for the current page to be skipped.
> 
> From an architectural viewpoint, something to consider is whether it
> makes sense to load data in the prerender() event instead of init().
> The advantage is that this will only be executed if this is the page
> that will really be rendered -- if you navigated elsewhere, you won't
> pay the performance cost of loading data that will not be used.  The
> disadvantage is that, by the time prerender() is called, you are
> committed to rendering this page and you cannot navigate anywhere
> else.
> 
> Craig
> 
>>
>> -----Original Message-----
>> From: gerrit [mailto:gerrit.scholz@deborate.de]
>> Sent: Friday, March 02, 2007 9:51 AM
>> To: user@shale.apache.org
>> Subject: view controller – site navigation
>>
>>
>>
>> I use the shale view controller init() method to make standard site
>> validations and load data.
>> The init-Method has no return value and so no navigation rule is
>> executed.
>> If one of my validation methods or the load data method returns an error
>> I'd
>> like execute navigation rules. The reason is to go to a special error
>> page.
>> Is there a possibility to navigate to another page from the init-method?
>>
>> --
>> View this message in context:
>> http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.html#a9266099
>> Sent from the Shale - User mailing list archive at Nabble.com.
>>
>>
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>> *
>>
>> This email with attachments is solely for the use of the individual or
>> entity to whom it is addressed. Please also be aware that DnB NOR cannot
>> accept any payment orders or other legally binding correspondence with
>> customers as a part of an email.
>>
>> This email message has been virus checked by the anti virus programs used
>> in the DnB NOR Group.
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>> *
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.html#a9328354
Sent from the Shale - User mailing list archive at Nabble.com.


Re: [shale-validator] view controller – site navigation

Posted by Craig McClanahan <cr...@apache.org>.
On 3/5/07, gerrit <ge...@deborate.de> wrote:
>
> This is the way I tried, but it works not for me.
>
> Init-method
> FacesContext facesContext = FacesContext.getCurrentInstance();
> NavigationHandler navigationHandler =
> facesContext.getApplication().getNavigationHandler();
>       navigationHandler.handleNavigation(facesContext,
> "#{projekteFace.fake}","successAufgaben");
>  facesContext.renderResponse();
>
> faces-config.xml:
>
> <navigation-rule>
>     <from-view-id>/faces/projekte.jsp</from-view-id>
>     <navigation-case>
>         <from-outcome>successAufgaben</from-outcome>
>         <to-view-id>/faces/aufgaben.jsp</to-view-id>
>     </navigation-case>
>  </navigation-rule>
>
> The current page is projekte.jsp. My assumption was that after
> renderResponce is executed the navigation rule is takes from the
> faces-config.xml. After that aufgaben.jsp should be shown and not
> projekte.jsp.
>

Is this view controller the one that is associated with page
"/faces/projekte.jsp"?  That is also important, because the navigation
handler uses that to match the <from-view-id> element of the
navigation rules.

Craig


>
>
> craigmcc wrote:
> >
> > It actually is possible to navigate from init(), but you have to do a
> > bit more work:
> >
> >     FacesContext context = FacesContext.getCurrentInstance();
> >     NavigationHandler nh =
> > context.getApplication().getNavigationHandler();
> >     String fromAction = "#{...}"; // Fake expression for the action
> > you pretend executed
> >     String outcome = "..."; // Fake outcome from the fake action
> >     nh.handleNavigation(context, fromAction, outcome);
> >     context.renderResponse(); // Skip directly to Render Response phase
> >
> > The current view, plus the values you specify for fromAction and
> > outcome, are fed into the standard navigation rules processing and a
> > new view will be selected based on those rules (or the current view
> > redisplayed if no rule matches).  The call to renderResponse() causes
> > the remainder of the lifecycle for the current page to be skipped.
> >
> > From an architectural viewpoint, something to consider is whether it
> > makes sense to load data in the prerender() event instead of init().
> > The advantage is that this will only be executed if this is the page
> > that will really be rendered -- if you navigated elsewhere, you won't
> > pay the performance cost of loading data that will not be used.  The
> > disadvantage is that, by the time prerender() is called, you are
> > committed to rendering this page and you cannot navigate anywhere
> > else.
> >
> > Craig
> >
> >>
> >> -----Original Message-----
> >> From: gerrit [mailto:gerrit.scholz@deborate.de]
> >> Sent: Friday, March 02, 2007 9:51 AM
> >> To: user@shale.apache.org
> >> Subject: view controller – site navigation
> >>
> >>
> >>
> >> I use the shale view controller init() method to make standard site
> >> validations and load data.
> >> The init-Method has no return value and so no navigation rule is
> >> executed.
> >> If one of my validation methods or the load data method returns an error
> >> I'd
> >> like execute navigation rules. The reason is to go to a special error
> >> page.
> >> Is there a possibility to navigate to another page from the init-method?
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.html#a9266099
> >> Sent from the Shale - User mailing list archive at Nabble.com.
> >>
> >>
> >>
> >> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> >> *
> >>
> >> This email with attachments is solely for the use of the individual or
> >> entity to whom it is addressed. Please also be aware that DnB NOR cannot
> >> accept any payment orders or other legally binding correspondence with
> >> customers as a part of an email.
> >>
> >> This email message has been virus checked by the anti virus programs used
> >> in the DnB NOR Group.
> >>
> >> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> >> *
> >>
> >>
> >
> >
>
> --
> View this message in context: http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.html#a9310294
> Sent from the Shale - User mailing list archive at Nabble.com.
>
>

SV: [shale-validator] view controller - site navigation

Posted by Hermod Opstvedt <he...@opstvedt.com>.
Hi

I think you should do it like this:

Init-method
FacesContext facesContext = FacesContext.getCurrentInstance();
NavigationHandler navigationHandler =
facesContext.getApplication().getNavigationHandler();
      navigationHandler.handleNavigation(facesContext,
"#{/faces/projekte.jsp}","successAufgaben");
 facesContext.renderResponse();

Your from view id has to match. Also note my previous mail about doing it
this way.

Hermod


-----Opprinnelig melding-----
Fra: gerrit [mailto:gerrit.scholz@deborate.de] 
Sendt: 5. mars 2007 13:10
Til: user@shale.apache.org
Emne: Re: [shale-validator] view controller - site navigation


This is the way I tried, but it works not for me. 

Init-method
FacesContext facesContext = FacesContext.getCurrentInstance();
NavigationHandler navigationHandler =
facesContext.getApplication().getNavigationHandler();
      navigationHandler.handleNavigation(facesContext,
"#{projekteFace.fake}","successAufgaben");
 facesContext.renderResponse();

faces-config.xml:

<navigation-rule>
    <from-view-id>/faces/projekte.jsp</from-view-id>
    <navigation-case>
        <from-outcome>successAufgaben</from-outcome>
        <to-view-id>/faces/aufgaben.jsp</to-view-id>
    </navigation-case>
 </navigation-rule>

The current page is projekte.jsp. My assumption was that after
renderResponce is executed the navigation rule is takes from the
faces-config.xml. After that aufgaben.jsp should be shown and not
projekte.jsp.



craigmcc wrote:
> 
> It actually is possible to navigate from init(), but you have to do a
> bit more work:
> 
>     FacesContext context = FacesContext.getCurrentInstance();
>     NavigationHandler nh =
> context.getApplication().getNavigationHandler();
>     String fromAction = "#{...}"; // Fake expression for the action
> you pretend executed
>     String outcome = "..."; // Fake outcome from the fake action
>     nh.handleNavigation(context, fromAction, outcome);
>     context.renderResponse(); // Skip directly to Render Response phase
> 
> The current view, plus the values you specify for fromAction and
> outcome, are fed into the standard navigation rules processing and a
> new view will be selected based on those rules (or the current view
> redisplayed if no rule matches).  The call to renderResponse() causes
> the remainder of the lifecycle for the current page to be skipped.
> 
> From an architectural viewpoint, something to consider is whether it
> makes sense to load data in the prerender() event instead of init().
> The advantage is that this will only be executed if this is the page
> that will really be rendered -- if you navigated elsewhere, you won't
> pay the performance cost of loading data that will not be used.  The
> disadvantage is that, by the time prerender() is called, you are
> committed to rendering this page and you cannot navigate anywhere
> else.
> 
> Craig
> 
>>
>> -----Original Message-----
>> From: gerrit [mailto:gerrit.scholz@deborate.de]
>> Sent: Friday, March 02, 2007 9:51 AM
>> To: user@shale.apache.org
>> Subject: view controller - site navigation
>>
>>
>>
>> I use the shale view controller init() method to make standard site
>> validations and load data.
>> The init-Method has no return value and so no navigation rule is
>> executed.
>> If one of my validation methods or the load data method returns an error
>> I'd
>> like execute navigation rules. The reason is to go to a special error
>> page.
>> Is there a possibility to navigate to another page from the init-method?
>>
>> --
>> View this message in context:
>>
http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.ht
ml#a9266099
>> Sent from the Shale - User mailing list archive at Nabble.com.
>>
>>
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>> *
>>
>> This email with attachments is solely for the use of the individual or
>> entity to whom it is addressed. Please also be aware that DnB NOR cannot
>> accept any payment orders or other legally binding correspondence with
>> customers as a part of an email.
>>
>> This email message has been virus checked by the anti virus programs used
>> in the DnB NOR Group.
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>> *
>>
>>
> 
> 

-- 
View this message in context:
http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.ht
ml#a9310294
Sent from the Shale - User mailing list archive at Nabble.com.


Re: [shale-validator] view controller – site navigation

Posted by gerrit <ge...@deborate.de>.
This is the way I tried, but it works not for me. 

Init-method
FacesContext facesContext = FacesContext.getCurrentInstance();
NavigationHandler navigationHandler =
facesContext.getApplication().getNavigationHandler();
      navigationHandler.handleNavigation(facesContext,
"#{projekteFace.fake}","successAufgaben");
 facesContext.renderResponse();

faces-config.xml:

<navigation-rule>
    <from-view-id>/faces/projekte.jsp</from-view-id>
    <navigation-case>
        <from-outcome>successAufgaben</from-outcome>
        <to-view-id>/faces/aufgaben.jsp</to-view-id>
    </navigation-case>
 </navigation-rule>

The current page is projekte.jsp. My assumption was that after
renderResponce is executed the navigation rule is takes from the
faces-config.xml. After that aufgaben.jsp should be shown and not
projekte.jsp.



craigmcc wrote:
> 
> It actually is possible to navigate from init(), but you have to do a
> bit more work:
> 
>     FacesContext context = FacesContext.getCurrentInstance();
>     NavigationHandler nh =
> context.getApplication().getNavigationHandler();
>     String fromAction = "#{...}"; // Fake expression for the action
> you pretend executed
>     String outcome = "..."; // Fake outcome from the fake action
>     nh.handleNavigation(context, fromAction, outcome);
>     context.renderResponse(); // Skip directly to Render Response phase
> 
> The current view, plus the values you specify for fromAction and
> outcome, are fed into the standard navigation rules processing and a
> new view will be selected based on those rules (or the current view
> redisplayed if no rule matches).  The call to renderResponse() causes
> the remainder of the lifecycle for the current page to be skipped.
> 
> From an architectural viewpoint, something to consider is whether it
> makes sense to load data in the prerender() event instead of init().
> The advantage is that this will only be executed if this is the page
> that will really be rendered -- if you navigated elsewhere, you won't
> pay the performance cost of loading data that will not be used.  The
> disadvantage is that, by the time prerender() is called, you are
> committed to rendering this page and you cannot navigate anywhere
> else.
> 
> Craig
> 
>>
>> -----Original Message-----
>> From: gerrit [mailto:gerrit.scholz@deborate.de]
>> Sent: Friday, March 02, 2007 9:51 AM
>> To: user@shale.apache.org
>> Subject: view controller – site navigation
>>
>>
>>
>> I use the shale view controller init() method to make standard site
>> validations and load data.
>> The init-Method has no return value and so no navigation rule is
>> executed.
>> If one of my validation methods or the load data method returns an error
>> I'd
>> like execute navigation rules. The reason is to go to a special error
>> page.
>> Is there a possibility to navigate to another page from the init-method?
>>
>> --
>> View this message in context:
>> http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.html#a9266099
>> Sent from the Shale - User mailing list archive at Nabble.com.
>>
>>
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>> *
>>
>> This email with attachments is solely for the use of the individual or
>> entity to whom it is addressed. Please also be aware that DnB NOR cannot
>> accept any payment orders or other legally binding correspondence with
>> customers as a part of an email.
>>
>> This email message has been virus checked by the anti virus programs used
>> in the DnB NOR Group.
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
>> *
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.html#a9310294
Sent from the Shale - User mailing list archive at Nabble.com.


Re: [shale-validator] SV: view controller - site navigation

Posted by gerrit <ge...@deborate.de>.
Hi 

The faces-config.xml was only a cutout. I have defined more navigation cases
so that different target methods had different outcomes. But I don’t
understand what you mean with “Deferring the outcome to the actual method to
be invoked”. Should I call a target method from the init method – this make
no sense for me. 

Gerrit   


Hermod Opstvedt wrote:
> 
> Hi
> 
> It definitely works, but from an architectural it does not feel right.
> Reason is that you may want different outcomes for different target
> methods.
> Deferring the outcome to the actual method to be invoked makes it cleaner
> in
> my mind.
> 
> Hermod
> 
> 
> -----Opprinnelig melding-----
> Fra: craigmcc@gmail.com [mailto:craigmcc@gmail.com] På vegne av Craig
> McClanahan
> Sendt: 5. mars 2007 06:43
> Til: user@shale.apache.org
> Emne: Re: view controller – site navigation
> 
> On 3/2/07, hermod.opstvedt@dnbnor.no <he...@dnbnor.no> wrote:
>> Hi
>>
>> I think the best way to achieve what you want is to raise a flag in the
> viewcontrollers init method. Then when the method that is supposed to be
> executed is called, you check for the flag at the beginning and return the
> outcome that corresponds to the error situatiuon.
>>
> 
> It actually is possible to navigate from init(), but you have to do a
> bit more work:
> 
>     FacesContext context = FacesContext.getCurrentInstance();
>     NavigationHandler nh =
> context.getApplication().getNavigationHandler();
>     String fromAction = "#{...}"; // Fake expression for the action
> you pretend executed
>     String outcome = "..."; // Fake outcome from the fake action
>     nh.handleNavigation(context, fromAction, outcome);
>     context.renderResponse(); // Skip directly to Render Response phase
> 
> The current view, plus the values you specify for fromAction and
> outcome, are fed into the standard navigation rules processing and a
> new view will be selected based on those rules (or the current view
> redisplayed if no rule matches).  The call to renderResponse() causes
> the remainder of the lifecycle for the current page to be skipped.
> 
> From an architectural viewpoint, something to consider is whether it
> makes sense to load data in the prerender() event instead of init().
> The advantage is that this will only be executed if this is the page
> that will really be rendered -- if you navigated elsewhere, you won't
> pay the performance cost of loading data that will not be used.  The
> disadvantage is that, by the time prerender() is called, you are
> committed to rendering this page and you cannot navigate anywhere
> else.
> 
> Craig
> 
>>
>> -----Original Message-----
>> From: gerrit [mailto:gerrit.scholz@deborate.de]
>> Sent: Friday, March 02, 2007 9:51 AM
>> To: user@shale.apache.org
>> Subject: view controller – site navigation
>>
>>
>>
>> I use the shale view controller init() method to make standard site
>> validations and load data.
>> The init-Method has no return value and so no navigation rule is
>> executed.
>> If one of my validation methods or the load data method returns an error
> I'd
>> like execute navigation rules. The reason is to go to a special error
> page.
>> Is there a possibility to navigate to another page from the init-method?
>>
>> --
>> View this message in context:
> http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.ht
> ml#a9266099
>> Sent from the Shale - User mailing list archive at Nabble.com.
>>
>>
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> *
>>
>> This email with attachments is solely for the use of the individual or
>> entity to whom it is addressed. Please also be aware that DnB NOR cannot
>> accept any payment orders or other legally binding correspondence with
>> customers as a part of an email.
>>
>> This email message has been virus checked by the anti virus programs used
>> in the DnB NOR Group.
>>
>> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> *
>>
>>
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/view-controller-%E2%80%93-site-navigation-tf3332431.html#a9328082
Sent from the Shale - User mailing list archive at Nabble.com.