KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > webapp > bean > JsfHelper


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 JavaDoc parameterName) {
9     long value = -1;
10     String JavaDoc valueText = (String JavaDoc) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(parameterName);
11     try {
12       Long JavaDoc id = new Long JavaDoc(valueText);
13       value = id.longValue();
14     } catch (NumberFormatException JavaDoc e) {
15       throw new RuntimeException JavaDoc("couldn't parse '"+parameterName+"'='"+valueText+"' as a long");
16     }
17     return value;
18   }
19   
20   public static void addMessage(String JavaDoc msg) {
21     FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(msg));
22   }
23
24   public static void setSessionAttribute(String JavaDoc key, Object JavaDoc value) {
25     FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(key, value);
26   }
27
28   public static Object JavaDoc getSessionAttribute(String JavaDoc key) {
29     return FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(key);
30   }
31
32   public static void removeSessionAttribute(String JavaDoc key) {
33     FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(key);
34   }
35
36   public static String JavaDoc getParameter(String JavaDoc name) {
37     return (String JavaDoc) FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get(name);
38   }
39   // private static final Log log = LogFactory.getLog(JsfHelper.class);
40
}
41
Popular Tags