Note that there are some explanatory texts on larger screens.

plurals
  1. POHow Do I Use @ConversationScoped
    primarykey
    data
    text
    <p>I am writing a JSF 2.0 application, and I want to use CDI annotations instead of the "equivalent" JSF annotations. In other words, @Model or @Named instead of @ManagedBean, and @Inject instead of @ManagedProperty.</p> <p>The only thing I cannot get to work is @ViewScoped which is necessary for AJAX components. The only reliable work-around is to use @SessionScoped, which is not a good practice.</p> <p>What is the correct practice? As much as I search I just get more confused.</p> <p>This is on GlassFish 3.1.1, which I understand has Weld 1.1.0 in it.</p> <p>UPDATE: The original form of this question said that I could not get @ConversationScoped to work. Since then I found my error and I did get it to work like so:</p> <pre><code>@Model @ConversationScoped public class Abean implements Serializable { @Inject Conversation conversation; // stuff omitted for brevity public String getSomething() { if (conversation.isTransient()) conversation.begin(); return "something"; } </code></pre> <p>This seems to do the trick. However now my question is changed. Where exactly are you supposed to call conversation.end()? Do I have to write a filter to detect when the user leaves the page? Or if it is left alone, just when would the <em>Abean</em> instance be de-referenced?</p> <p>SECOND UPDATE: A very good discussion of CDI's @ConversationScoped I found <a href="http://www.theserverside.com/tip/Dependency-Injection-in-Java-EE-6-Conversations-Part-4" rel="noreferrer">here.</a></p> <p>I am still left with the problem of how to call conversation.end(). My bean provides stateful backing to a data table browser updated via AJAX, and the optimal place to call end() is when the user navigates away from the page. However short of writing a filter to monitor the pages I don't really see any way of doing that. Any suggestion of "best practice" is welcome.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload