1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.orchestra.conversation.jsf.components;
21
22 import java.io.IOException;
23 import java.util.Arrays;
24 import java.util.Collection;
25
26 import javax.faces.component.UICommand;
27 import javax.faces.context.FacesContext;
28 import javax.faces.el.MethodBinding;
29 import javax.faces.el.ValueBinding;
30
31 import org.apache.myfaces.orchestra.conversation.ConversationUtils;
32 import org.apache.myfaces.orchestra.conversation.jsf._JsfConversationUtils;
33 import org.apache.myfaces.orchestra.conversation.jsf.lib._EndConversationMethodBindingFacade;
34 import org.apache.myfaces.shared_orchestra.util.StringUtils;
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 public class UIEndConversation extends AbstractConversationComponent
81 {
82 public static final String COMPONENT_TYPE = "org.apache.myfaces.orchestra.EndConversation";
83
84 private String onOutcome;
85 private String errorOutcome;
86
87 private boolean inited = false;
88
89 public void encodeBegin(FacesContext context) throws IOException
90 {
91 super.encodeBegin(context);
92
93 UICommand command = _JsfConversationUtils.findParentCommand(this);
94 if (command != null)
95 {
96
97
98 if (!inited)
99 {
100 MethodBinding original = command.getAction();
101 command.setAction(new _EndConversationMethodBindingFacade(
102 getName(),
103 getOnOutcomes(),
104 original,
105 getErrorOutcome()));
106 inited = true;
107 }
108 }
109 else
110 {
111
112 ConversationUtils.invalidateIfExists(getName());
113 }
114 }
115
116 private Collection getOnOutcomes()
117 {
118 String onOutcome = getOnOutcome();
119 if (onOutcome == null || onOutcome.trim().length() < 1)
120 {
121 return null;
122 }
123
124 return Arrays.asList(StringUtils.trim(StringUtils.splitShortString(onOutcome, ',')));
125 }
126
127 public void restoreState(FacesContext context, Object state)
128 {
129 Object[] states = (Object[]) state;
130 super.restoreState(context, states[0]);
131 inited = ((Boolean) states[1]).booleanValue();
132 onOutcome = (String) states[2];
133 errorOutcome = (String) states[3];
134 }
135
136 public Object saveState(FacesContext context)
137 {
138 return new Object[]
139 {
140 super.saveState(context),
141 inited ? Boolean.TRUE : Boolean.FALSE,
142 onOutcome,
143 errorOutcome
144 };
145 }
146
147 public String getOnOutcome()
148 {
149 if (onOutcome != null)
150 {
151 return onOutcome;
152 }
153 ValueBinding vb = getValueBinding("onOutcome");
154 if (vb == null)
155 {
156 return null;
157 }
158 return (String) vb.getValue(getFacesContext());
159 }
160
161 public void setOnOutcome(String onOutcome)
162 {
163 this.onOutcome = onOutcome;
164 }
165
166 public String getErrorOutcome()
167 {
168 if (errorOutcome != null)
169 {
170 return errorOutcome;
171 }
172 ValueBinding vb = getValueBinding("errorOutcome");
173 if (vb == null)
174 {
175 return null;
176 }
177 return (String) vb.getValue(getFacesContext());
178 }
179
180 public void setErrorOutcome(String errorOutcome)
181 {
182 this.errorOutcome = errorOutcome;
183 }
184 }