001: /*
002: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
003: * @author <a href="mailto:oliver.wehrens@aei.mpg.de">Oliver Wehrens</a>
004: * @version $Id: TextFieldTag.java 6385 2007-10-25 14:02:26Z wehrens $
005: */
006:
007: package org.gridsphere.provider.portletui.tags;
008:
009: import org.gridsphere.provider.portletui.beans.TextFieldBean;
010: import org.gridsphere.provider.portletui.beans.ValidatorBean;
011:
012: import javax.servlet.jsp.JspException;
013: import javax.servlet.jsp.JspWriter;
014:
015: /**
016: * A <code>TextFieldTag</code> represents a text field element
017: */
018: public class TextFieldTag extends InputTag {
019:
020: protected TextFieldBean textFieldBean = null;
021: protected int size = 0;
022: protected int maxlength = 0;
023:
024: /**
025: * Returns the (html) size of the field
026: *
027: * @return size of the field
028: */
029: public int getSize() {
030: return size;
031: }
032:
033: /**
034: * Sets the (html) size of the field
035: *
036: * @param size size of the field
037: */
038: public void setSize(int size) {
039: this .size = size;
040: }
041:
042: /**
043: * Returns the (html) max length of the field
044: *
045: * @return the max length of the field
046: */
047: public int getMaxlength() {
048: return maxlength;
049: }
050:
051: /**
052: * Sets the (html) max length of the field
053: *
054: * @param maxlength the max length of the field
055: */
056: public void setMaxlength(int maxlength) {
057: this .maxlength = maxlength;
058: }
059:
060: public int doStartTag() throws JspException {
061: return EVAL_BODY_INCLUDE;
062: }
063:
064: public int doEndTag() throws JspException {
065: if (!beanId.equals("")) {
066: textFieldBean = (TextFieldBean) getTagBean();
067: if (textFieldBean == null) {
068: //log.debug("Creating new text field bean");
069: textFieldBean = new TextFieldBean();
070: this .setBaseComponentBean(textFieldBean);
071: } else {
072: //log.debug("Using existing text field bean");
073: this .updateBaseComponentBean(textFieldBean);
074: }
075: } else {
076: textFieldBean = new TextFieldBean();
077: this .setBaseComponentBean(textFieldBean);
078: }
079: if (maxlength != 0)
080: textFieldBean.setMaxLength(maxlength);
081: if (size != 0)
082: textFieldBean.setSize(size);
083: if (onFocus != null)
084: textFieldBean.setOnFocus(onFocus);
085: if (onClick != null)
086: textFieldBean.setOnClick(onClick);
087: if (onChange != null)
088: textFieldBean.setOnChange(onChange);
089: if (onBlur != null)
090: textFieldBean.setOnBlur(onBlur);
091: if (onSelect != null)
092: textFieldBean.setOnSelect(onBlur);
093:
094: if (cssClass != null)
095: textFieldBean.addCssClass(cssClass);
096: if (cssStyle != null)
097: textFieldBean.addCssStyle(cssStyle);
098: //debug();
099: JspWriter out;
100:
101: try {
102: out = pageContext.getOut();
103: out.print(textFieldBean.toStartString());
104: // print out validators, represented as hidden fields
105: if (!validatorBeans.isEmpty()) {
106: ValidatorBean validatorBean = null;
107: for (int i = 0; i < validatorBeans.size(); i++) {
108: validatorBean = (ValidatorBean) validatorBeans
109: .get(i);
110: validatorBean.setName(textFieldBean
111: .getEncodedName());
112: out.print(validatorBean.toStartString());
113: }
114: }
115: validatorBeans.clear();
116: cssClass = null;
117: } catch (Exception e) {
118: throw new JspException(e.getMessage());
119: }
120: super.release();
121: return EVAL_PAGE;
122: }
123:
124: }
|