1 23 28 package com.sun.enterprise.tools.jsfext.event.handlers.basic; 29 30 import com.sun.enterprise.tools.jsfext.event.handlers.HandlerContext; 31 32 import java.util.ArrayList ; 33 import java.util.Iterator ; 34 import java.util.List ; 35 36 import javax.faces.component.UIComponent; 37 38 39 46 public class UtilHandlers { 47 48 51 public UtilHandlers() { 52 } 53 54 61 public void println(HandlerContext context) { 62 String value = (String ) context.getInputValue("value"); 63 System.out.println(value); 64 } 65 66 73 public void dec(HandlerContext context) { 74 Integer value = (Integer ) context.getInputValue("number"); 75 context.setOutputValue("value", new Integer (value.intValue() - 1)); 76 } 77 78 85 public void inc(HandlerContext context) { 86 Integer value = (Integer ) context.getInputValue("number"); 87 context.setOutputValue("value", new Integer (value.intValue() + 1)); 88 } 89 90 96 public void setAttribute(HandlerContext context) { 97 String key = (String ) context.getInputValue("key"); 98 Object value = context.getInputValue("value"); 99 context.getFacesContext().getExternalContext(). 100 getRequestMap().put(key, value); 101 } 102 103 111 public void getIterator(HandlerContext context) { 112 List list = (List ) context.getInputValue("list"); 113 context.setOutputValue("iterator", list.iterator()); 114 } 115 116 124 public void iteratorHasNext(HandlerContext context) { 125 Iterator it = (Iterator ) context.getInputValue("iterator"); 126 context.setOutputValue("hasNext", Boolean.valueOf(it.hasNext())); 127 } 128 129 137 public void iteratorNext(HandlerContext context) { 138 Iterator it = (Iterator ) context.getInputValue("iterator"); 139 context.setOutputValue("next", it.next()); 140 } 141 142 149 public void createList(HandlerContext context) { 150 int size = ((Integer ) context.getInputValue("size")).intValue(); 151 List list = new ArrayList (size); 152 for (int count = 0; count < size; count++) { 153 list.add(""); 154 } 155 context.setOutputValue("result", list); 156 } 157 158 164 public boolean returnTrue(HandlerContext context) { 165 return true; 166 } 167 168 174 public boolean returnFalse(HandlerContext context) { 175 return false; 176 } 177 178 184 public void getClientId(HandlerContext context) { 185 UIComponent comp = (UIComponent) context.getInputValue("component"); 186 context.setOutputValue("clientId", 187 comp.getClientId(context.getFacesContext())); 188 } 189 190 198 public void getId(HandlerContext context) { 199 Object obj = context.getInputValue("object"); 200 if (obj == null) { 201 return; 202 } 203 204 String clientId = null; 205 String id = null; 206 if (obj instanceof UIComponent) { 207 clientId = 208 ((UIComponent) obj).getClientId(context.getFacesContext()); 209 id = ((UIComponent) obj).getId(); 210 } else { 211 clientId = obj.toString(); 212 id = clientId.substring(clientId.lastIndexOf(':') + 1); 213 } 214 context.setOutputValue("id", id); 215 context.setOutputValue("clientId", clientId); 216 } 217 } 218 | Popular Tags |