Overview
Other MyFaces Extensions
- ExtVal
- Ext-Script
- [Orchestra]
- [Portlet Bridge]
Community
Development
Sponsorship
Your browser does not support iframes
MyFaces CODI provides powerful scopes for JSF applications. The inspiration for most parts came from MyFaces Orchestra. If you already know MyFaces Orchestra you will be able to use the scopes provided by MyFaces CODI easily. Also the migration of existing applications shouldn't be that hard.
For users who aren't familiar with the conversation concepts provided by MyFaces Orchestra:
Orchestra allows to group beans within a (named) conversation. Furthermore, it's possible to use beans with different (conversation-) lifecycles in the same page. (Usually there isn't one big conversation - like the std. CDI conversation which is more like a bit smarter session for a window/tab.) Conversations are bound to a window/tab of a browser. That means you automatically get new conversations, if you open the application in a new tab/window. Conversations are started automatically as soon as a conversation scoped bean is used. A conversation ends based on a timeout (in case of the access scope - a conversation ends as soon as it wasn't used by a page). Furthermore, it's possible to end (or restart) conversations manually. That means via an API call it's possible to end a conversation immediately. The next access leads to a new conversation. If the whole session gets destroyed, also all conversations will be destroyed automatically.
MyFaces CODI provides all these principles of MyFaces Orchestra in combination with typesafe improvements as well as the support of CDI mechanisms like qualifiers.
And why do we need new scopes? CDI already provides conversations. That's right and CDI is a great spec. and the EG did a nice job, however, (compared to the concepts of MyFaces Orchestra) CDI std. conversations are not that nice. So we saw the need to port a lot of the concepts provided by MyFaces Orchestra to CDI.
MyFaces CODI provides the following types of conversations:
@ConversationScoped public class DemoBean1 { public String getWelcomeText() { return "Hello MyFaces CODI!"; } }
That's it!
As soon as you access the bean, the conversation gets started!
Hint
If you would like to use the bean within your JSF pages, you have to add @Named
(javax.inject.Named
).
@Named @ConversationScoped public class DemoBean2 { @Inject private DemoBean1 bean1; private String text; @PostConstruct protected void init() { text = this.bean1.getWelcomeText(); } /*generated*/ public String getText() { return text; } }
#{demoBean2.text} //e.g.: <h:outputText value="#{demoBean2.text}"/>
Be Careful
If you are using MyFaces CODI you don't need std. CDI conversations any more. So it might be a good idea to exclude javax.enterprise.context.ConversationScoped
and javax.enterprise.context.Conversation
via IDE settings. If you are using those classes instead of the CODI classes, you will see different results.
@ConversationScoped
means you are using a bean with a timeout (default: 30 minutes). As soon as a bean gets accessed, the bean is touched which leads to a reset of the timeout.
Hint
You can see the default values in: org.apache.myfaces.extensions.cdi.javaee.jsf.api.ConfigParameter
@ConversationScoped public class DemoBean3 { @Inject private Conversation conversation; public void save() { //your custom logic //... this.conversation.end(); //or use: //conversation.restart(); //... if you know that you will need new instances of the same beans e.g. in the next view //#restart it's just a possible performance improvement } }
The usage is exactly the same like @ConversationScoped
. The only difference is that there is no timeout.
You can compare it to a session per window. However, as we will see later on it's possible to reset the window-context manually.
@WindowScoped public class DemoBean4 { }
The usage is exactly the same like @ConversationScoped
. The only difference is that there is no timeout. If you don't use @ViewAccessScoped
beans within a view, they won't be available any longer. That means: They get cleaned up automatically, as soon as you don't use them.
@ViewAccessScoped public class DemoBean5 { }