blob: 0231a3cda0238e8f8347869d5fb7d89c740a2bd5 [file] [log] [blame]
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*******************************************************************************/
package org.ofbiz.webapp.taglib;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilJ2eeCompat;
import org.ofbiz.webapp.pseudotag.EntityField;
import org.ofbiz.entity.GenericEntityException;
/**
* EntityFieldTag - Tag to Print Localized Entity Fields.
*/
@SuppressWarnings("serial")
public class EntityFieldTag extends TagSupport {
public static final String module = EntityFieldTag.class.getName();
protected String field = null;
protected String type = null;
protected String attribute = null;
protected Object defaultObj = "";
protected String prefix = null;
protected String suffix = null;
public String getAttribute() {
return attribute;
}
public void setAttribute(String attribute) {
this.attribute = attribute;
}
public String getField() {
return field;
}
public void setField(String field) {
this.field = field;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPrefix() {
return prefix;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public String getSuffix() {
return suffix;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
public Object getDefault() {
return defaultObj;
}
public void setDefault(Object defaultObj) {
this.defaultObj = defaultObj;
}
@Override
public int doStartTag() throws JspException {
try {
EntityField.run(attribute, field, prefix, suffix, defaultObj.toString(), type, pageContext);
} catch (IOException e) {
if (UtilJ2eeCompat.useNestedJspException(pageContext.getServletContext())) {
throw new JspException(e.getMessage(), e);
} else {
Debug.logError(e, "Server does not support nested exceptions, here is the exception", module);
throw new JspException(e.toString());
}
} catch (GenericEntityException e) {
if (UtilJ2eeCompat.useNestedJspException(pageContext.getServletContext())) {
throw new JspException("Entity Engine error: " + e.getMessage(), e);
} else {
Debug.logError(e, "Server does not support nested exceptions, here is the exception", module);
throw new JspException("Entity Engine error: " + e.toString());
}
}
return (SKIP_BODY);
}
}