JSF2 ConversationScope

  • Yan Langlois
    Yan Langlois

    I would like to use jasper report like this :

    public class Controler {
         @Inject private Conversation conversation;
         public void actionMethod() {
            if(conversation.isTransient()) conversation.begin();


    public class DataSourceBeanFactory implements Serializable {
        private Logger logger = Logger.getLogger(getClass());
        private Controler controler;
        public Collection<DataBean> getDataBeanList() {
            // using controler to get data...
            return new arrayList<DataBean>();

    then in XHTML :

    <jr:dataSource type="bean" id="dataSource" value="#{dataSourceBeanFactory.dataBeanList}" />

    My Controle begins a long running conversation before XHTML "render"
    <jr:dataSource/> (even befor the page with jr:dataSource).
    My problem is that when I am in the getDataBeanList method it is like a was in
    a new transient conversation.
    Then when I call again my controler I am in the first long running

    How is it possible ?

  • Hi yanlaglois,

    This is not the first question about "Conversation Scope" as you may have
    already noticed. When using the available versions of the plugin we must have
    in mind that it was focused to address the integration issues between
    JasperReports 3.x and JSF 1.2. Any integration out of that scope is not
    properly supported and "Conversation Scope" wasn't available when JSF 1.2 was
    in the market. However, any progress to get the plugin supporting that feature
    will receive -of course- a great welcome.

    Said that and taking a look to your code snippets I wonder that if the reason
    of the problem may be related to the fact that "Conversation Scope" is a CDI
    standard, not a JSF standard ... (¿?) So it seems that the
    "dataSourceBeanFactory" bean doesn't know anything about the conversation
    started before.

    Did you tried to achieve the same using the JSF "View Scope" ? You're saying
    that the conversation is started before the page that contains the
    "jr:dataSource" but may be tempted to change your approach of a one using AJAX
    and that JSF "View Scope".

    Thanks for your post, it you could provide any feedback about your progress it
    would be great.

  • It looks like you may have the use of conversation scope within the beans
    inverted. You inject the conversation scope into the Controler . Then you
    inject this bean into the DataSourceBeanFactory. I believe that you need to
    code things inversely. I believe that you need to have beans to be used WITHIN
    the conversation scope injected INTO the bean where the conversation scope is
    injected. See http://www.theserverside.com/tip/Dependency-Injection-in-Java-

    The login, user and preferences fields produce named backing beans for use
    in the wizard pages. Because these beans are produced by the conversational
    bean, they are available throughout the conversation as well as being
    available to the parent bean holding the bean instances.

  • Yan Langlois
    Yan Langlois

    Thank you.

    I managed to make my report work when my object are SessionScoped. But If I
    use ConversationScoped object, the report does not work. It does not find the
    conversationscoped object.

    I wonder how I can passe my conversationscoped objects to my report without
    using the session (a4j:param or f:param does not work). If it is possible can
    you tell my how please ?

  • As I said above, I believe that conversation scope is unavailable, because you
    need to inject the DataSourceBeanFactory into the Controller class you have
    created and not the other way around. The conversation scope is tied to the
    Controller class and classes that you want to use with the conversation
    created when the Controller class is instantiated need to be injected into the
    bean that contains the conversation. Once you inject the DataSourceBeanFactory
    into the controller, you can add a method to the controller called
    getDataBeanList that accesses the dataBeanList from the DataSourceBeanFactory
    that you have injected.

    I believe that this may fix your issue.