1 14 15 package com.sun.facelets.tag.jstl.core; 16 17 import com.sun.facelets.tag.TagConfig; 18 import com.sun.facelets.tag.TagException; 19 20 import java.io.IOException ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import javax.el.ELException; 26 import javax.faces.FacesException; 27 28 import javax.faces.component.UIComponent; 29 30 import com.sun.facelets.FaceletContext; 31 import com.sun.facelets.FaceletException; 32 import com.sun.facelets.tag.TagHandler; 33 34 38 public final class ChooseHandler extends TagHandler { 39 40 private final ChooseOtherwiseHandler otherwise; 41 private final ChooseWhenHandler[] when; 42 43 public ChooseHandler(TagConfig config) { 44 super(config); 45 46 List whenList = new ArrayList (); 47 Iterator itr = this.findNextByType(ChooseWhenHandler.class); 48 while (itr.hasNext()) { 49 whenList.add(itr.next()); 50 } 51 if (whenList.isEmpty()) { 52 throw new TagException(this.tag, "Choose Tag must have one or more When Tags"); 53 } 54 this.when = (ChooseWhenHandler[]) whenList.toArray(new ChooseWhenHandler[whenList.size()]); 55 56 itr = this.findNextByType(ChooseOtherwiseHandler.class); 57 if (itr.hasNext()) { 58 this.otherwise = (ChooseOtherwiseHandler) itr.next(); 59 } else { 60 this.otherwise = null; 61 } 62 } 63 64 public void apply(FaceletContext ctx, UIComponent parent) 65 throws IOException , FacesException, FaceletException, ELException { 66 for (int i = 0; i < this.when.length; i++) { 67 if (this.when[i].isTestTrue(ctx)) { 68 this.when[i].apply(ctx, parent); 69 return; 70 } 71 } 72 if (this.otherwise != null) { 73 this.otherwise.apply(ctx, parent); 74 } 75 } 76 77 } 78 | Popular Tags |