1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.custom.conversation;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import java.io.IOException;
25
26 import javax.faces.context.FacesContext;
27 import javax.faces.el.ValueBinding;
28 import javax.faces.component.UIComponent;
29
30
31
32
33
34
35
36
37 public class UIConversation extends AbstractConversationComponent
38 {
39 private final static Log log = LogFactory.getLog(UIConversation.class);
40
41 public static final String COMPONENT_TYPE = "org.apache.myfaces.Conversation";
42
43 public void encodeBegin(FacesContext context) throws IOException
44 {
45 super.encodeBegin(context);
46
47 UIComponent cmp = getParent();
48 if (cmp instanceof UIStartConversation)
49 {
50
51 return;
52 }
53
54 if (getName() == null)
55 {
56 throw new IllegalArgumentException("conversation name (attribute name=) required if used outside of startConversation tag");
57 }
58
59 elevateBean(context, getName(), getBeanBinding());
60 }
61
62 ValueBinding getBeanBinding()
63 {
64 return getValueBinding("value");
65 }
66
67 public static void elevateBean(FacesContext context, String conversationName, ValueBinding valueBinding)
68 {
69 Conversation conversation = ConversationManager.getInstance().getConversation(conversationName);
70 if (conversation == null)
71 {
72 log.debug("no conversation named '" + conversationName + "' running - can't elevate bean '" + valueBinding.getExpressionString());
73 return;
74 }
75 ConversationManager.getInstance().getConversationBeanElevator().elevateBean(context, conversation, valueBinding);
76 }
77 }