KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > util > WidgetUtils


1 /*
2  * Created on 22 avr. 2004
3  */

4 package fr.improve.struts.taglib.layout.util;
5
6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8
9 import javax.servlet.ServletRequest JavaDoc;
10
11 /**
12  * Define usefull method to work with widgets.
13  *
14  * @author jnribette
15  */

16 public class WidgetUtils {
17     private static final String JavaDoc WIDGET_ID = "fr.improve.struts.taglib.layout.util.WidgetUtils.WIDGET_ID";
18     
19     /**
20      * Generate a unique page id for a specified widget.
21      */

22     public static String JavaDoc generateId(ServletRequest JavaDoc in_request, String JavaDoc in_widgetType) {
23         // Get the Map holding the last attributed ids.
24
Map JavaDoc lc_map = (Map JavaDoc) in_request.getAttribute(WIDGET_ID);
25         if (lc_map==null) {
26             lc_map = new HashMap JavaDoc();
27             in_request.setAttribute(WIDGET_ID, lc_map);
28         }
29         
30         // Get the last attribute id.
31
Integer JavaDoc lc_id = (Integer JavaDoc) lc_map.get(in_widgetType);
32         if (lc_id==null) {
33             lc_id = new Integer JavaDoc(-1);
34         }
35         
36         // Increment the id
37
lc_id = new Integer JavaDoc(lc_id.intValue()+1);
38         
39         // Store the new id.
40
lc_map.put(in_widgetType, lc_id);
41         
42         // Return the id.
43
return lc_id.toString();
44     }
45 }
46
Popular Tags