001: /*
002: * (C) Copyright 2004 Nabh Information Systems, Inc.
003: *
004: * All copyright notices regarding Nabh's products MUST remain
005: * intact in the scripts and in the outputted HTML.
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: */
021: package com.nabhinc.portlet.mvcportlet.taglib;
022:
023: import javax.portlet.RenderRequest;
024: import javax.servlet.jsp.JspException;
025: import javax.servlet.jsp.JspWriter;
026: import javax.servlet.jsp.tagext.TagSupport;
027:
028: import com.nabhinc.portlet.mvcportlet.core.Constants;
029: import com.nabhinc.portlet.mvcportlet.core.ControllerPortletConfig;
030: import com.nabhinc.portlet.mvcportlet.core.FormErrors;
031:
032: /**
033: *
034: * @author Padmanabh Dabke
035: * (c) 2004 Nabh Information Systems, Inc. All Rights Reserved.
036: */
037: public class FormLabelTag extends TagSupport {
038: private String mtKey = null;
039: private String mtFieldName = null;
040: private String fltStyleClass = "formFieldError";
041:
042: public void release() {
043: super .release();
044: mtKey = null;
045: mtFieldName = null;
046: fltStyleClass = "formFieldError";
047: }
048:
049: public String getName() {
050: return mtFieldName;
051: }
052:
053: public void setName(String fieldName) {
054: mtFieldName = fieldName;
055: }
056:
057: public String getKey() {
058: return mtKey;
059: }
060:
061: public void setKey(String val) {
062: mtKey = val;
063: }
064:
065: /**
066: * @return Returns the error stylesheet class.
067: */
068: public String getStyleClass() {
069: return fltStyleClass;
070: }
071:
072: /**
073: * Sets the error stylesheet class name
074: * Default is <code>formFieldError</code>
075: * @param styleClass The stylesheet class to set.
076: */
077: public void setStyleClass(String styleClass) {
078: fltStyleClass = styleClass;
079: }
080:
081: public int doStartTag() throws JspException {
082:
083: try {
084: RenderRequest request = (RenderRequest) pageContext
085: .getRequest().getAttribute("javax.portlet.request");
086: JspWriter out = pageContext.getOut();
087: boolean isErrorField = false;
088:
089: FormErrors formErrors = (FormErrors) request
090: .getPortletSession().getAttribute(
091: Constants.FORM_ERRORS_ATTRIB
092: + request.getPortletMode()
093: .toString().toLowerCase());
094: if (formErrors != null
095: && formErrors.isErrorField(mtFieldName)) {
096: isErrorField = true;
097: }
098:
099: ControllerPortletConfig config = (ControllerPortletConfig) request
100: .getAttribute(Constants.PORTLET_CONFIG_ATTRIB);
101: if (isErrorField) {
102: out.print("<span class=\"");
103: out.print(fltStyleClass);
104: out.print("\">");
105: out.print(config.getLocalizedMessage(mtKey, request));
106: out.print("</span>");
107: } else {
108: out.print(config.getLocalizedMessage(mtKey, request));
109: }
110: } catch (Exception ex) {
111: throw new JspException(ex);
112: }
113:
114: return SKIP_BODY;
115: }
116:
117: public int doEndTag() {
118: return EVAL_PAGE;
119: }
120:
121: }
|