You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Yee CN <ye...@streamyx.com> on 2006/01/06 10:26:53 UTC

How to implement 'back' button

Hi,

 

I am thinking of providing a 'back' button on all my pages. Below is a
sketch on how I intended to do it, but before embarking on it I would like
to know whether anybody has done similar and to hear from you Gurus whether
my approach is workable.

 

1) I have a stack<backingBean, nagivgationResult> to store the pages being
visited and the associated backing bean.

    The stack will be limited to store (say) the last 10 pages visited, so
it won't grow continuously. I think a circular list could probably be used
for this.

 

2) A phase listener will push the current page's backing bean and navigation
to the stack; it will happen at the AFTER RENDER_RESPONSE phase.

 

3) The 'back' button will pop the stack - restores the backing bean and
navigates back to the page concerned.

 

4) Some pages can be marked to not to participate in this scheme.

 

I am assuming a) the beans are in request scope, b) there is only one
backing bean per page.

For session scope beans I would have to serialize the bean.

 

Please - any comments?

 

Best regards,

Yee

 

 

 

// getting an restoring a manage bean

public static Object getManagedBean(String beanName) {

            Object o = getValueBinding( "#{" + beanName + "}"
).getValue(FacesContext.getCurrentInstance());

            return o;

}  

            

public static void setManageBean(String beanName, Object bean) {

            getValueBinding( "#{" + beanName + "}"
).setValue(FacesContext.getCurrentInstance(), bean);

}

 

// some helper methods

private static Application getApplication() {

            ApplicationFactory appFactory =
(ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTO
RY);

            return appFactory.getApplication(); 

}

            

private static ValueBinding getValueBinding(String el) {

            return getApplication().createValueBinding(el);

}

            

private static Object getElValue(String el) {

            return
getValueBinding(el).getValue(FacesContext.getCurrentInstance());

}

            

 


RE: How to implement 'back' button

Posted by Yee CN <ye...@streamyx.com>.
Thanks Cenk, I fond this web page after you email. There are some
limitations with the scheme as I stated in my last post, which I think can
be fixed.

Sorry I misquoted your name in my last positing.

 

Regards,

Yee

 

  _____  

From: Cenk Çivici [mailto:cenk.civici@gmail.com] 
Sent: Friday, 6 January 2006 7:07 PM
To: MyFaces Discussion; yeecn@streamyx.com
Subject: Re: How to implement 'back' button

 

http://www.jroller.com/comments/cenkcivici/Weblog/custom_jsf_navigation_hand
ler_for contains an implementation for this requirement. 

 

-Cenk Çivici

 

On 1/6/06, Yee CN <ye...@streamyx.com> wrote: 

Hi,

 

I am thinking of providing a 'back' button on all my pages. Below is a
sketch on how I intended to do it, but before embarking on it I would like
to know whether anybody has done similar and to hear from you Gurus whether
my approach is workable. 

 

1) I have a stack<backingBean, nagivgationResult> to store the pages being
visited and the associated backing bean.

    The stack will be limited to store (say) the last 10 pages visited, so
it won't grow continuously. I think a circular list could probably be used
for this. 

 

2) A phase listener will push the current page's backing bean and navigation
to the stack; it will happen at the AFTER RENDER_RESPONSE phase.

 

3) The 'back' button will pop the stack – restores the backing bean and
navigates back to the page concerned.

 

4) Some pages can be marked to not to participate in this scheme.

 

I am assuming a) the beans are in request scope, b) there is only one
backing bean per page.

For session scope beans I would have to serialize the bean.

 

Please – any comments?

 

Best regards,

Yee

 

 

 

// getting an restoring a manage bean

public static Object getManagedBean(String beanName) {

            Object o = getValueBinding( "#{" + beanName + "}"
).getValue(FacesContext.getCurrentInstance());

            return o;

}  

            

public static void setManageBean(String beanName, Object bean) {

            getValueBinding( "#{" + beanName + "}"
).setValue(FacesContext.getCurrentInstance(), bean);

}

 

// some helper methods

private static Application getApplication() {

            ApplicationFactory appFactory =
(ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTO
RY);

            return appFactory.getApplication(); 

}

            

private static ValueBinding getValueBinding(String el) {

            return getApplication().createValueBinding(el);

}

            

private static Object getElValue(String el) {

            return
getValueBinding(el).getValue(FacesContext.getCurrentInstance());

}

            

 

 


Re: How to implement 'back' button

Posted by Cenk Çivici <ce...@gmail.com>.
http://www.jroller.com/comments/cenkcivici/Weblog/custom_jsf_navigation_handler_for
contains
an implementation for this requirement.

-Cenk Çivici


On 1/6/06, Yee CN <ye...@streamyx.com> wrote:
>
>  Hi,
>
>
>
> I am thinking of providing a 'back' button on all my pages. Below is a
> sketch on how I intended to do it, but before embarking on it I would like
> to know whether anybody has done similar and to hear from you Gurus whether
> my approach is workable.
>
>
>
> 1) I have a stack<backingBean, nagivgationResult> to store the pages being
> visited and the associated backing bean.
>
>     The stack will be limited to store (say) the last 10 pages visited, so
> it won't grow continuously. I think a circular list could probably be used
> for this.
>
>
>
> 2) A phase listener will push the current page's backing bean and
> navigation to the stack; it will happen at the AFTER RENDER_RESPONSEphase.
>
>
>
> 3) The 'back' button will pop the stack – restores the backing bean and
> navigates back to the page concerned.
>
>
>
> 4) Some pages can be marked to not to participate in this scheme.
>
>
>
> I am assuming a) the beans are in request scope, b) there is only one
> backing bean per page.
>
> For session scope beans I would have to serialize the bean.
>
>
>
> Please – any comments?
>
>
>
> Best regards,
>
> Yee
>
>
>
>
>
>
>
> // getting an restoring a manage bean
>
> public static Object getManagedBean(String beanName) {
>
>             Object o = getValueBinding( "#{" + beanName + "}" ).getValue(
> FacesContext.getCurrentInstance());
>
>             return o;
>
> }
>
>
>
> public static void setManageBean(String beanName, Object bean) {
>
>             getValueBinding( "#{" + beanName + "}" ).setValue(
> FacesContext.getCurrentInstance(), bean);
>
> }
>
>
>
> // some helper methods
>
> private static Application getApplication() {
>
>             ApplicationFactory appFactory =
> (ApplicationFactory)FactoryFinder.getFactory(
> FactoryFinder.APPLICATION_FACTORY);
>
>             return appFactory.getApplication();
>
> }
>
>
>
> private static ValueBinding getValueBinding(String el) {
>
>             return getApplication().createValueBinding(el);
>
> }
>
>
>
> private static Object getElValue(String el) {
>
>             return getValueBinding(el).getValue(
> FacesContext.getCurrentInstance());
>
> }
>
>
>
>
>

Re: How to implement 'back' button

Posted by Cagatay Civici <ca...@gmail.com>.
Hi,

We have done a similiar thing, there is a custom navigation handler which
manages the navigation in our application. There are special action names
and for the back operation the name is "@back@", the navigation handler also
uses a navigation data holder, which tracks the pages visited using a stack.
When a return action named @back@ is realized, the last view stored is
popped from stack and navigation occurs afterwards.

regards,

Cagatay Civici

On 1/6/06, Yee CN <ye...@streamyx.com> wrote:
>
>  Hi,
>
>
>
> I am thinking of providing a 'back' button on all my pages. Below is a
> sketch on how I intended to do it, but before embarking on it I would like
> to know whether anybody has done similar and to hear from you Gurus whether
> my approach is workable.
>
>
>
> 1) I have a stack<backingBean, nagivgationResult> to store the pages being
> visited and the associated backing bean.
>
>     The stack will be limited to store (say) the last 10 pages visited, so
> it won't grow continuously. I think a circular list could probably be used
> for this.
>
>
>
> 2) A phase listener will push the current page's backing bean and
> navigation to the stack; it will happen at the AFTER RENDER_RESPONSEphase.
>
>
>
> 3) The 'back' button will pop the stack – restores the backing bean and
> navigates back to the page concerned.
>
>
>
> 4) Some pages can be marked to not to participate in this scheme.
>
>
>
> I am assuming a) the beans are in request scope, b) there is only one
> backing bean per page.
>
> For session scope beans I would have to serialize the bean.
>
>
>
> Please – any comments?
>
>
>
> Best regards,
>
> Yee
>
>
>
>
>
>
>
> // getting an restoring a manage bean
>
> public static Object getManagedBean(String beanName) {
>
>             Object o = getValueBinding( "#{" + beanName + "}" ).getValue(
> FacesContext.getCurrentInstance());
>
>             return o;
>
> }
>
>
>
> public static void setManageBean(String beanName, Object bean) {
>
>             getValueBinding( "#{" + beanName + "}" ).setValue(
> FacesContext.getCurrentInstance(), bean);
>
> }
>
>
>
> // some helper methods
>
> private static Application getApplication() {
>
>             ApplicationFactory appFactory =
> (ApplicationFactory)FactoryFinder.getFactory(
> FactoryFinder.APPLICATION_FACTORY);
>
>             return appFactory.getApplication();
>
> }
>
>
>
> private static ValueBinding getValueBinding(String el) {
>
>             return getApplication().createValueBinding(el);
>
> }
>
>
>
> private static Object getElValue(String el) {
>
>             return getValueBinding(el).getValue(
> FacesContext.getCurrentInstance());
>
> }
>
>
>
>
>

RE: How to implement 'back' button

Posted by Nico Krijnen <ni...@graphit.nl>.
Hi,

 

I had some trouble doing this in a navigation handler so I implemented a
similar mechanism some time ago and have been using it succesfully for some
time now. It is not exactly what you describe, but might be just what you
need. It basicly works as following:

 

HistoryManager (request scope managed bean)

   .addCurrentViewState()

      Pushes viewstate on internal stack

   .returnToLast()

      Pops and restores last viewstate from stack

 

Each button-action that needs to save the current state has the following
ActionListener:

 

AddViewStateListener

   .processAction()

      Calls historyManager.addCurrentViewState()

 

The pages following the button-action store the historyManager using
<t:saveState/> tags. To return to the previous state the a button-action can
call "historyManager.returnToLast".

 

We also have a HistoryMarkers bean (session scope) that allows you to mark a
specific state and return to it later by calling a specific url. We use this
to return to our application after redirecting to an external website url.

 

If there is any interest for this mechanism we could put these classes in
the myfaces sandbox.

 

Kind regards,
Nico Krijnen

GRAPHit B.V.
The Netherlands

  _____  

Van: Yee CN [mailto:yeecn@streamyx.com] 
Verzonden: vrijdag 6 januari 2006 10:27
Aan: 'MyFaces Discussion'
Onderwerp: How to implement 'back' button

 

Hi,

 

I am thinking of providing a 'back' button on all my pages. Below is a
sketch on how I intended to do it, but before embarking on it I would like
to know whether anybody has done similar and to hear from you Gurus whether
my approach is workable.

 

1) I have a stack<backingBean, nagivgationResult> to store the pages being
visited and the associated backing bean.

    The stack will be limited to store (say) the last 10 pages visited, so
it won't grow continuously. I think a circular list could probably be used
for this.

 

2) A phase listener will push the current page's backing bean and navigation
to the stack; it will happen at the AFTER RENDER_RESPONSE phase.

 

3) The 'back' button will pop the stack - restores the backing bean and
navigates back to the page concerned.

 

4) Some pages can be marked to not to participate in this scheme.

 

I am assuming a) the beans are in request scope, b) there is only one
backing bean per page.

For session scope beans I would have to serialize the bean.

 

Please - any comments?

 

Best regards,

Yee

 

 

 

// getting an restoring a manage bean

public static Object getManagedBean(String beanName) {

            Object o = getValueBinding( "#{" + beanName + "}"
).getValue(FacesContext.getCurrentInstance());

            return o;

}  

            

public static void setManageBean(String beanName, Object bean) {

            getValueBinding( "#{" + beanName + "}"
).setValue(FacesContext.getCurrentInstance(), bean);

}

 

// some helper methods

private static Application getApplication() {

            ApplicationFactory appFactory =
(ApplicationFactory)FactoryFinder.getFactory(FactoryFinder.APPLICATION_FACTO
RY);

            return appFactory.getApplication(); 

}

            

private static ValueBinding getValueBinding(String el) {

            return getApplication().createValueBinding(el);

}

            

private static Object getElValue(String el) {

            return
getValueBinding(el).getValue(FacesContext.getCurrentInstance());

}