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
38
39
40
41 public class UIConversation extends AbstractConversationComponent
42 {
43 private final static Log log = LogFactory.getLog(UIConversation.class);
44
45 public static final String COMPONENT_TYPE = "org.apache.myfaces.Conversation";
46
47 public void encodeBegin(FacesContext context) throws IOException
48 {
49 super.encodeBegin(context);
50
51 UIComponent cmp = getParent();
52 if (cmp instanceof UIStartConversation)
53 {
54
55 return;
56 }
57
58 if (getName() == null)
59 {
60 throw new IllegalArgumentException("conversation name (attribute name=) required if used outside of startConversation tag");
61 }
62
63 elevateBean(context, getName(), getBeanBinding());
64 }
65
66 ValueBinding getBeanBinding()
67 {
68 return getValueBinding("value");
69 }
70
71 public static void elevateBean(FacesContext context, String conversationName, ValueBinding valueBinding)
72 {
73 Conversation conversation = ConversationManager.getInstance().getConversation(conversationName);
74 if (conversation == null)
75 {
76 log.debug("no conversation named '" + conversationName + "' running - can't elevate bean '" + valueBinding.getExpressionString());
77 return;
78 }
79 ConversationManager.getInstance().getConversationBeanElevator().elevateBean(context, conversation, valueBinding);
80 }
81 }