Home » struts-2.1.8.1-src » org.apache » struts2 » showcase » [javadoc | source]

    1   /*
    2    * $Id: UITagExample.java 536388 2007-05-09 01:10:00Z musachy $
    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.showcase;
   22   
   23   import java.io.File;
   24   import java.util.ArrayList;
   25   import java.util.Collections;
   26   import java.util.Date;
   27   import java.util.HashMap;
   28   import java.util.List;
   29   import java.util.Map;
   30   
   31   import org.apache.struts2.ServletActionContext;
   32   
   33   import com.opensymphony.xwork2.ActionSupport;
   34   import com.opensymphony.xwork2.Validateable;
   35   import com.opensymphony.xwork2.util.ValueStack;
   36   
   37   /**
   38    */
   39   public class UITagExample extends ActionSupport implements Validateable {
   40   
   41       private static final long serialVersionUID = -94044809860988047L;
   42   
   43   
   44       String name;
   45       Date birthday;
   46       Date wakeup;
   47       String bio;
   48       String favouriteColor;
   49       List friends;
   50       boolean legalAge;
   51       String state;
   52       String region;
   53       File picture;
   54       String pictureContentType;
   55       String pictureFileName;
   56       String favouriteLanguage;
   57       String favouriteVehicalType = "MotorcycleKey";
   58       String favouriteVehicalSpecific = "YamahaKey";
   59   
   60       List leftSideCartoonCharacters;
   61       List rightSideCartoonCharacters;
   62   
   63       List favouriteLanguages = new ArrayList();
   64       List vehicalTypeList = new ArrayList();
   65       Map vehicalSpecificMap = new HashMap();
   66   
   67       String thoughts;
   68   
   69       public UITagExample() {
   70           favouriteLanguages.add(new Language("EnglishKey", "English Language"));
   71           favouriteLanguages.add(new Language("FrenchKey", "French Language"));
   72           favouriteLanguages.add(new Language("SpanishKey", "Spanish Language"));
   73   
   74           VehicalType car = new VehicalType("CarKey", "Car");
   75           VehicalType motorcycle = new VehicalType("MotorcycleKey", "Motorcycle");
   76           vehicalTypeList.add(car);
   77           vehicalTypeList.add(motorcycle);
   78   
   79           List cars = new ArrayList();
   80           cars.add(new VehicalSpecific("MercedesKey", "Mercedes"));
   81           cars.add(new VehicalSpecific("HondaKey", "Honda"));
   82           cars.add(new VehicalSpecific("FordKey", "Ford"));
   83   
   84           List motorcycles = new ArrayList();
   85           motorcycles.add(new VehicalSpecific("SuzukiKey", "Suzuki"));
   86           motorcycles.add(new VehicalSpecific("YamahaKey", "Yamaha"));
   87   
   88           vehicalSpecificMap.put(car, cars);
   89           vehicalSpecificMap.put(motorcycle, motorcycles);
   90       }
   91   
   92   
   93   
   94       public List getLeftSideCartoonCharacters() {
   95           return leftSideCartoonCharacters;
   96       }
   97       public void setLeftSideCartoonCharacters(List leftSideCartoonCharacters) {
   98           this.leftSideCartoonCharacters = leftSideCartoonCharacters;
   99       }
  100   
  101   
  102       public List getRightSideCartoonCharacters() {
  103           return rightSideCartoonCharacters;
  104       }
  105       public void setRightSideCartoonCharacters(List rightSideCartoonCharacters) {
  106           this.rightSideCartoonCharacters = rightSideCartoonCharacters;
  107       }
  108   
  109   
  110       public String getFavouriteVehicalType() {
  111           return favouriteVehicalType;
  112       }
  113   
  114       public void setFavouriteVehicalType(String favouriteVehicalType) {
  115           this.favouriteVehicalType = favouriteVehicalType;
  116       }
  117   
  118       public String getFavouriteVehicalSpecific() {
  119           return favouriteVehicalSpecific;
  120       }
  121   
  122       public void setFavouriteVehicalSpecific(String favouriteVehicalSpecific) {
  123           this.favouriteVehicalSpecific = favouriteVehicalSpecific;
  124       }
  125   
  126       public List getVehicalTypeList() {
  127           return vehicalTypeList;
  128       }
  129   
  130       public List getVehicalSpecificList() {
  131           ValueStack stack = ServletActionContext.getValueStack(ServletActionContext.getRequest());
  132           Object vehicalType = stack.findValue("top");
  133           if (vehicalType != null && vehicalType instanceof VehicalType) {
  134               List l = (List) vehicalSpecificMap.get(vehicalType);
  135               return l;
  136           }
  137           return Collections.EMPTY_LIST;
  138       }
  139   
  140       public List getFavouriteLanguages() {
  141           return favouriteLanguages;
  142       }
  143   
  144       public String execute() throws Exception {
  145           return SUCCESS;
  146       }
  147   
  148       public String getName() {
  149           return name;
  150       }
  151   
  152       public void setName(String name) {
  153           this.name = name;
  154       }
  155   
  156       public Date getBirthday() {
  157           return birthday;
  158       }
  159   
  160       public void setBirthday(Date birthday) {
  161           this.birthday = birthday;
  162       }
  163   
  164       public String getBio() {
  165           return bio;
  166       }
  167   
  168       public void setBio(String bio) {
  169           this.bio = bio;
  170       }
  171   
  172       public String getFavouriteColor() {
  173           return favouriteColor;
  174       }
  175   
  176       public void setFavouriteColor(String favoriteColor) {
  177           this.favouriteColor = favoriteColor;
  178       }
  179   
  180       public List getFriends() {
  181           return friends;
  182       }
  183   
  184       public void setFriends(List friends) {
  185           this.friends = friends;
  186       }
  187   
  188       public boolean isLegalAge() {
  189           return legalAge;
  190       }
  191   
  192       public void setLegalAge(boolean legalAge) {
  193           this.legalAge = legalAge;
  194       }
  195   
  196       public String getState() {
  197           return state;
  198       }
  199   
  200       public void setState(String state) {
  201           this.state = state;
  202       }
  203   
  204       public String getRegion() {
  205           return region;
  206       }
  207   
  208       public void setRegion(String region) {
  209           this.region = region;
  210       }
  211   
  212       public void setPicture(File picture) {
  213           this.picture = picture;
  214       }
  215       
  216       public File getPicture() {
  217           return this.picture;
  218       }
  219   
  220       public void setPictureContentType(String pictureContentType) {
  221           this.pictureContentType = pictureContentType;
  222       }
  223   
  224       public void setPictureFileName(String pictureFileName) {
  225           this.pictureFileName = pictureFileName;
  226       }
  227   
  228       public void setFavouriteLanguage(String favouriteLanguage) {
  229           this.favouriteLanguage = favouriteLanguage;
  230       }
  231   
  232       public String getFavouriteLanguage() {
  233           return favouriteLanguage;
  234       }
  235   
  236   
  237       public void setThoughts(String thoughts) {
  238           this.thoughts = thoughts;
  239       }
  240   
  241       public String getThoughts() {
  242           return this.thoughts;
  243       }
  244   
  245       public Date getWakeup() {
  246           return wakeup;
  247       }
  248   
  249       public void setWakeup(Date wakeup) {
  250           this.wakeup = wakeup;
  251       }
  252   
  253       public String doSubmit() {
  254           return SUCCESS;
  255       }
  256   
  257   
  258   
  259       // === inner class
  260       public static class Language {
  261           String description;
  262           String key;
  263   
  264           public Language(String key, String description) {
  265               this.key = key;
  266               this.description = description;
  267           }
  268   
  269           public String getKey() {
  270               return key;
  271           }
  272           public String getDescription() {
  273               return description;
  274           }
  275   
  276       }
  277   
  278   
  279       public static class VehicalType {
  280           String key;
  281           String description;
  282           public VehicalType(String key, String description) {
  283               this.key = key;
  284               this.description = description;
  285           }
  286   
  287           public String getKey() { return this.key; }
  288           public String getDescription() { return this.description; }
  289   
  290           public boolean equals(Object obj) {
  291               if (! (obj instanceof VehicalType)) {
  292                   return false;
  293               }
  294               else {
  295                   return key.equals(((VehicalType)obj).getKey());
  296               }
  297           }
  298   
  299           public int hashCode() {
  300               return key.hashCode();
  301           }
  302       }
  303   
  304   
  305       public static class VehicalSpecific {
  306           String key;
  307           String description;
  308           public VehicalSpecific(String key, String description) {
  309               this.key = key;
  310               this.description = description;
  311           }
  312   
  313           public String getKey() { return this.key; }
  314           public String getDescription() { return this.description; }
  315   
  316           public boolean equals(Object obj) {
  317               if (! (obj instanceof VehicalSpecific)) {
  318                   return false;
  319               }
  320               else {
  321                   return key.equals(((VehicalSpecific)obj).getKey());
  322               }
  323           }
  324   
  325           public int hashCode() {
  326               return key.hashCode();
  327           }
  328       }
  329   }

Home » struts-2.1.8.1-src » org.apache » struts2 » showcase » [javadoc | source]