View Javadoc

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