View Javadoc

1   /*
2    * $Id: Else.java 497654 2007-01-19 00:21:57Z rgielen $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "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   *  &lt;s:if test="%{false}"&gt;
48   *      &lt;div&gt;Will Not Be Executed&lt;/div&gt;
49   *  &lt;/s:if&gt;
50   *  &lt;s:elseif test="%{true}"&gt;
51   *      &lt;div&gt;Will Be Executed&lt;/div&gt;
52   *  &lt;/s:elseif&gt;
53   *  &lt;s:else&gt;
54   *      &lt;div&gt;Will Not Be Executed&lt;/div&gt;
55   *  &lt;/s:else&gt;
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  }