01: /*
02: * $Id: Else.java 497654 2007-01-19 00:21:57Z rgielen $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.components;
22:
23: import java.io.Writer;
24: import java.util.Map;
25:
26: import org.apache.struts2.views.annotations.StrutsTag;
27:
28: import com.opensymphony.xwork2.util.ValueStack;
29:
30: /**
31: * <!-- START SNIPPET: javadoc -->
32: *
33: * <p>Perform basic condition flow. 'If' tag could be used by itself or with 'Else If' Tag and/or single/multiple 'Else'
34: * Tag.</p>
35: *
36: * <!-- END SNIPPET: javadoc -->
37: *
38: * <!-- START SNIPPET: params -->
39: *
40: * no params
41: *
42: * <!-- END SNIPPET: params -->
43: *
44: *
45: * <pre>
46: * <!-- START SNIPPET: example -->
47: * <s:if test="%{false}">
48: * <div>Will Not Be Executed</div>
49: * </s:if>
50: * <s:elseif test="%{true}">
51: * <div>Will Be Executed</div>
52: * </s:elseif>
53: * <s:else>
54: * <div>Will Not Be Executed</div>
55: * </s:else>
56: * <!-- END SNIPPET: example -->
57: * </pre>
58: *
59: */
60: @StrutsTag(name="else",tldTagClass="org.apache.struts2.views.jsp.ElseTag",description="Else tag")
61: public class Else extends Component {
62: public Else(ValueStack stack) {
63: super (stack);
64: }
65:
66: public boolean start(Writer writer) {
67: Map context = stack.getContext();
68: Boolean ifResult = (Boolean) context.get(If.ANSWER);
69:
70: context.remove(If.ANSWER);
71:
72: return !((ifResult == null) || (ifResult.booleanValue()));
73: }
74: }
|