1 package org.jbpm.webapp.bean; 2 3 import javax.faces.application.FacesMessage; 4 import javax.faces.context.FacesContext; 5 6 public class JsfHelper { 7 8 public static long getId(String parameterName) { 9 long value = -1; 10 String valueText = (String ) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(parameterName); 11 try { 12 Long id = new Long (valueText); 13 value = id.longValue(); 14 } catch (NumberFormatException e) { 15 throw new RuntimeException ("couldn't parse '"+parameterName+"'='"+valueText+"' as a long"); 16 } 17 return value; 18 } 19 20 public static void addMessage(String msg) { 21 FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(msg)); 22 } 23 24 public static void setSessionAttribute(String key, Object value) { 25 FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key, value); 26 } 27 28 public static Object getSessionAttribute(String key) { 29 return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(key); 30 } 31 32 public static void removeSessionAttribute(String key) { 33 FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(key); 34 } 35 36 public static String getParameter(String name) { 37 return (String ) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name); 38 } 39 } 41 | Popular Tags |