0

I need some JSF 2.1.29 advice. I have a bean:

public class PlayerCardBean{

    private Integer playerId;
    //GET, SET, Other fileds and methods
}

The facelet playerCard.xhtml for the bean contains <a> tag for redirecting to another page:

<a href="javascript://"  
    onclick="openPage('#{request.contextPath}/panels/playerExternalTransactionList.html?playerId=#{playerCardBean.playerId}');">
        <h:outputText value="#msgs['playerCard.externalTransactionList.all']}" />
</a>

I need this bean stay alived when the user is on the playerCard.xhtml as well as we're redirecting from the playerCard.xhtml to by the link within the <a> tag.

The view scope is smaller. The bean is going to be destroyed after redirecting.

How can I keep that bean alive when we're redirecting between those two views? By the <a> tag and probably by the "back"-button in a browser.

I think that storing the fields within a session is not a good idea because they are not a true-session attributes.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
St.Antario
  • 26,175
  • 41
  • 130
  • 318
  • Don't hack it that way. You should not be insterested in keeping the whole bean alive, but in sending parameters from one bean to another. Just pass them as query parameters or put them in the flash scope. – Aritz May 13 '15 at 09:12
  • @XtremeBiker That's clear, right. But how can I handle back-button click in a browser? – St.Antario May 13 '15 at 10:46
  • That subject has been discussed before: http://stackoverflow.com/questions/10305718/avoid-back-button-on-jsf-web-application Basically, gain control over what you want to avoid cache over. – Aritz May 13 '15 at 10:50

3 Answers3

2

I can think of the following two solutions:

  1. Use the conversation scope. It requires annotating your bean with the @ConversationScoped annotation and you will need to manage (begin and end) the conversation programatically. (This answer contains some useful sample code.)
  2. Use the Flash.
Community
  • 1
  • 1
Robby Cornelissen
  • 91,784
  • 22
  • 134
  • 156
  • I'm on tomcat, therefore can't use CDI just as simple. But I'm using spring frameowrk. Maybe I can do some with it? – St.Antario May 13 '15 at 07:15
2

You can use the @ConversationScope. This scope is started and ended programmatically. http://www.byteslounge.com/tutorials/java-ee-cdi-conversationscoped-example

jklee
  • 2,198
  • 2
  • 15
  • 25
1

There is no perfect solution in JSF 2.1 but you can create your own scope which will be good replacement for conversation scope.

More details: https://blog.oio.de/2012/07/24/jsf-2-custom-scopes-without-3rd-party-libraries/

sQer
  • 1,136
  • 8
  • 9