001: /**
002: * $Id: BeanSetTag.java,v 1.6 2005/09/21 10:50:18 dg154973 Exp $
003: * Copyright 2002 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.taglibs.base;
014:
015: import com.sun.portal.log.common.PortalLogger;
016:
017: import java.beans.*;
018: import java.util.logging.Logger;
019: import java.util.logging.Level;
020: import javax.servlet.jsp.*;
021:
022: /**
023: * BeanSetTag - Set a bean property
024: *
025: * This class writes the specified bean property
026: * to the specified value onto
027: * page output or saves the value into the page context
028: * using the "id" attribute.
029: *
030: * Attributes:
031: *
032: * property
033: * name of the bean property to set
034: * value
035: * value of the bean property to set
036: * name
037: * name to use to retrieve the property from the page context
038: * id
039: * name to use to find the property on the page context
040: *
041: * @author Robert O'Brien
042: * @version 1.0
043: * @see BeanSetTag
044: * @see BeanSupport
045: */
046: public class BeanSetTag extends BeanSupport {
047:
048: // Create a logger for this class
049: private static Logger debugLogger = PortalLogger
050: .getLogger(BeanSetTag.class);
051:
052: /**
053: * The value of the bean property to set
054: */
055: public String value;
056:
057: /**
058: * Get the value of the bean property
059: *
060: * @return the value
061: */
062: public String getValue() {
063: return value;
064: }
065:
066: /**
067: * Set the value of the bean property
068: *
069: * @param value the value
070: */
071: public void setValue(String value) {
072: this .value = evalAttribute(value);
073: }
074:
075: /**
076: * Write the property value to the bean
077: *
078: * @return SKIP_BODY
079: * @exception JspException
080: */
081: public int doStartTag() throws JspException {
082: Object value;
083:
084: try {
085: bean = findBean();
086: } catch (Exception e) {
087: debugLogger.log(Level.FINE, "PSMA_CSPWTB0007", e);
088: }
089:
090: if (id != null) {
091: value = pageContext.findAttribute(id);
092: } else {
093: value = getValue();
094: }
095:
096: /** It's OK to set the value of a property to null, for clearing multi-valued props etc.
097: if (value == null) {
098: debugLogger.log(Level.FINE, "PSMA_CSPWTB0009", getProperty());
099: throw new JspException(
100: this.getClass().getName()+".doStartTag(): No value found for" + getProperty() + " property");
101: }
102: */
103:
104: if (edit != null) {
105: value = edit.editString(value.toString());
106: }
107:
108: debugLogger.finest("this=" + this + ", bean=" + bean
109: + ", prop=" + property + ", value=" + value);
110:
111: try {
112: writeProperty(bean, value);
113: } catch (IntrospectionException e) {
114: debugLogger.log(Level.FINE, "PSMA_CSPWTB0010",
115: getProperty());
116: }
117:
118: return SKIP_BODY;
119: }
120:
121: /**
122: * Edit bean...
123: */
124: private Edit edit = null;
125:
126: /**
127: * Set the edit bean
128: */
129: public void setEdit(String edit) {
130: this .edit = (Edit) pageContext.getAttribute(edit);
131: }
132:
133: /**
134: * Cleanup
135: */
136: public void release() {
137: super.release();
138: value = null;
139: edit = null;
140: }
141:
142: }
|