View Javadoc

1   /*
2    * The SmartWeb Framework
3    * Copyright (C) 2004-2006
4    *
5    * This library is free software; you can redistribute it and/or
6    * modify it under the terms of the GNU Lesser General Public
7    * License as published by the Free Software Foundation; either
8    * version 2.1 of the License, or (at your option) any later version.
9    *
10   * This library is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   * Lesser General Public License for more details.
14   *
15   * You should have received a copy of the GNU Lesser General Public
16   * License along with this library; if not, write to the Free Software
17   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18   *
19   * For further informations on the SmartWeb Framework please visit
20   *
21   *                        http://smartweb.sourceforge.net
22   */
23   
24  package net.smartlab.web.page;
25  
26  import java.io.Writer;
27  
28  import javax.servlet.jsp.JspException;
29  import javax.servlet.jsp.JspTagException;
30  
31  import net.smartlab.web.EmptyMarkerTag;
32  
33  import org.apache.commons.beanutils.BeanUtils;
34  import org.apache.struts.taglib.TagUtils;
35  import org.apache.struts.taglib.html.Constants;
36  
37  /**
38   * TODO documentation
39   * 
40   * @author rlogiacco
41   * @jsp.tag name = "reminder" body-content = "empty"
42   */
43  public class ReminderTag extends AbstractTag {
44  
45  	/**
46  	 * TODO documentation Comment for <code>property</code>
47  	 */
48  	private String property;
49  
50  	/**
51  	 * TODO documentation Comment for <code>value</code>
52  	 */
53  	private String value;
54  
55  	/**
56  	 * @param value the value to set.
57  	 * @jsp.attribute required="true" rtexprvalue="true"
58  	 */
59  	public void setValue(String value) {
60  		this.value = value;
61  	}
62  
63  	/**
64  	 * @param property the property to set.
65  	 * @jsp.attribute required="true" rtexprvalue="true"
66  	 */
67  	public void setProperty(String property) {
68  		this.property = property;
69  	}
70  
71  	/**
72  	 * @see javax.servlet.jsp.tagext.Tag#doStartTag()
73  	 */
74  	public int doStartTag() throws JspException {
75  		String[] items = null;
76  		try {
77  			String[] values = (String[])TagUtils.getInstance().lookup(super.context, Constants.BEAN_KEY, property, null);
78  			items = new String[values.length];
79  			System.arraycopy(values, 0, items, 0, items.length);
80  		} catch (Exception e) {
81  			items = context.getRequest().getParameterValues(property);
82  		}
83  		if (items != null) {
84  			try {
85  				Paginator paginator = super.getPaginator();
86  				paginator.reset();
87  				while (paginator.hasNext()) {
88  					Object item = BeanUtils.getProperty(paginator.next(), value);
89  					for (int i = 0; i < items.length; i++) {
90  						if (item != null && items[i] != null && (items[i].equals(EmptyMarkerTag.EMPTY_MARKER) || items[i].equals(item.toString()))) {
91  							items[i] = null;
92  							break;
93  						}
94  					}
95  				}
96  				paginator.reset();
97  				Writer out = context.getOut();
98  				for (int i = 0; i < items.length; i++) {
99  					if (items[i] != null) {
100 						out.write("<input type=\"hidden\" name=\"" + property + "\" value=\"" + items[i] + "\"/>");
101 					}
102 				}
103 			} catch (Exception e) {
104 				throw new JspTagException(e);
105 			}
106 		}
107 		return EVAL_PAGE;
108 	}
109 }