Search in sources :

Example 1 with MissingParametersRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException in project jaffa-framework by jaffa-projects.

the class CheckBoxTag method otherDoStartTagOperations.

/**
 * This generates the HTML for the tag.
 */
public void otherDoStartTagOperations() {
    try {
        super.otherDoStartTagOperations();
    } catch (JspException e) {
        log.error("CheckBoxTag.otherDoStartTagOperations() error=" + e);
    }
    // Preprocess if within a Property widget
    IPropertyRuleIntrospector propertyRuleIntrospector = lookupPropertyTag();
    // raise an error, if the 'field' is null
    if (getField() == null) {
        String str = "The " + TAG_NAME + " requires 'field' parameter to be supplied or it should be within a PropertyTag";
        log.error(str);
        throw new MissingParametersRuntimeException(str);
    }
    // Get the formtag from the page & register the widget
    FormTag formTag = TagHelper.getFormTag(pageContext);
    if (formTag == null) {
        String str = "The " + TAG_NAME + " should be inside a FormTag";
        log.error(str);
        throw new OuterFormTagMissingRuntimeException(str);
    }
    // Will hold the required html
    String html = null;
    // Get the model
    SimpleWidgetModel model = null;
    try {
        model = (SimpleWidgetModel) TagHelper.getModel(pageContext, getField(), TAG_NAME);
    } catch (ClassCastException e) {
        String str = "Wrong WidgetModel for " + TAG_NAME + " on field " + getField();
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
    // Check for an IPropertyRuleIntrospector, if this tag is not within a Property widget
    try {
        if (propertyRuleIntrospector == null)
            propertyRuleIntrospector = TagHelper.getPropertyRuleIntrospector(pageContext, getField());
        // Wrap the propertyRuleIntrospector
        propertyRuleIntrospector = TagHelper.wrapPropertyRuleIntrospector(propertyRuleIntrospector, model);
    } catch (JspException e) {
        log.error("CheckBoxTag.otherDoStartTagOperations(): error property inspector: " + e);
    }
    if (propertyRuleIntrospector.isHidden()) {
        // Display the (Restricted) text for a hidden field
        html = TagHelper.getTextForHiddenField(pageContext);
    } else {
        if (model != null) {
            if (propertyRuleIntrospector.isReadOnly()) {
                // Render a readOnly field as a displayOnly checkbox
                m_displayOnly = true;
                if (m_type != null && m_type.equalsIgnoreCase("HTML"))
                    m_type = "IMAGE";
            }
            html = getHtml(getHtmlIdPrefix(), model);
        }
    }
    if (html != null) {
        // Write the HTML
        JspWriter out = pageContext.getOut();
        try {
            out.print(html);
        } catch (IOException e) {
            String str = "Exception in writing the " + TAG_NAME;
            log.error(str, e);
            throw new JspWriteRuntimeException(str, e);
        }
    }
}
Also used : IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector) JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) JspException(javax.servlet.jsp.JspException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) MissingParametersRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException) SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)

Example 2 with MissingParametersRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException in project jaffa-framework by jaffa-projects.

the class DateTimeTag method otherDoStartTagOperations.

/**
 * This generates the HTML for the tag.
 */
public void otherDoStartTagOperations() {
    try {
        super.otherDoStartTagOperations();
    } catch (JspException e) {
        log.error("DateTimeTag.otherDoStartTagOperations(): error=" + e);
    }
    // Preprocess if within a Property widget
    IPropertyRuleIntrospector propertyRuleIntrospector = lookupPropertyTag();
    // raise an error, if the 'field' is null
    if (getField() == null) {
        String str = "The " + TAG_NAME + " requires 'field' parameter to be supplied or it should be within a PropertyTag";
        log.error(str);
        throw new MissingParametersRuntimeException(str);
    }
    // Get the formtag from the page & register the widget
    FormTag formTag = TagHelper.getFormTag(pageContext);
    if (formTag == null) {
        String str = "The " + TAG_NAME + " should be inside a FormTag";
        log.error(str);
        throw new OuterFormTagMissingRuntimeException(str);
    }
    // Will hold the required html
    String html = null;
    // Get the model
    SimpleWidgetModel model = null;
    try {
        model = (SimpleWidgetModel) TagHelper.getModel(pageContext, getField(), TAG_NAME);
    } catch (ClassCastException e) {
        String str = "Wrong WidgetModel for " + TAG_NAME + " on field " + getField();
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
    // Check for an IPropertyRuleIntrospector, if this tag is not within a Property widget
    try {
        if (propertyRuleIntrospector == null)
            propertyRuleIntrospector = TagHelper.getPropertyRuleIntrospector(pageContext, getField());
        // Wrap the propertyRuleIntrospector
        propertyRuleIntrospector = TagHelper.wrapPropertyRuleIntrospector(propertyRuleIntrospector, model);
    } catch (JspException e) {
        log.error("DateTimeTag.otherDoStartTagOperations(): error: property editor: " + e);
    }
    if (propertyRuleIntrospector.isHidden()) {
        // Display the (Restricted) text for a hidden field
        html = TagHelper.getTextForHiddenField(pageContext);
    } else {
        if (model != null) {
            if (propertyRuleIntrospector.isReadOnly()) {
                // Just display the text for a readOnly field
                Object value = getDateOnly() ? (Object) model.getDateOnlyValue() : (Object) model.getDateTimeValue();
                html = StringHelper.convertToHTML(Formatter.format(value));
            } else {
                String classPrefix = propertyRuleIntrospector.isMandatory() ? "<span class=\"editboxMandatoryPrefix\">&nbsp;</span>" : "<span class=\"editboxOptionalPrefix\">&nbsp;</span>";
                String classSuffix = propertyRuleIntrospector.isMandatory() ? "<span class=\"editboxMandatorySuffix\">&nbsp;</span>" : "<span class=\"editboxOptionalSuffix\">&nbsp;</span>";
                html = classPrefix + getHtml(getHtmlIdPrefix(), model, propertyRuleIntrospector) + classSuffix;
            }
        }
    }
    if (html != null) {
        // Write the HTML
        JspWriter out = pageContext.getOut();
        try {
            out.print(html);
        } catch (IOException e) {
            String str = "Exception in writing the " + TAG_NAME;
            log.error(str, e);
            throw new JspWriteRuntimeException(str, e);
        }
    }
}
Also used : IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector) JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) JspException(javax.servlet.jsp.JspException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) MissingParametersRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException) SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)

Example 3 with MissingParametersRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException in project jaffa-framework by jaffa-projects.

the class EditBoxTag method otherDoStartTagOperations.

/**
 * This generates the HTML for the tag.
 */
public void otherDoStartTagOperations() throws JspException {
    log.debug(this.NAME + ".otherDoStartTagOperations()...");
    try {
        super.otherDoStartTagOperations();
    } catch (JspException e) {
        log.error(this.NAME + ".otherDoStartTagOperations(): error=" + e);
    }
    // Preprocess if within a Property widget
    IPropertyRuleIntrospector propertyRuleIntrospector = lookupPropertyTag();
    // raise an error, if the 'field' is null
    if (getField() == null) {
        String str = "The " + TAG_NAME + " requires 'field' parameter to be supplied or it should be within a PropertyTag";
        log.error(str);
        throw new MissingParametersRuntimeException(str);
    }
    // Get the formtag from the page & register the widget
    FormTag formTag = TagHelper.getFormTag(pageContext);
    if (formTag == null) {
        String str = "The " + TAG_NAME + " should be inside a FormTag";
        log.error(str);
        throw new OuterFormTagMissingRuntimeException(str);
    }
    // Will hold the required html
    String html = null;
    // Get the model
    SimpleWidgetModel model = null;
    try {
        model = (SimpleWidgetModel) TagHelper.getModel(pageContext, getField(), TAG_NAME);
    } catch (ClassCastException e) {
        String str = "Wrong WidgetModel for " + TAG_NAME + " on field " + getField();
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
    // Check for an IPropertyRuleIntrospector, if this tag is not within a Property widget
    try {
        if (propertyRuleIntrospector == null)
            propertyRuleIntrospector = TagHelper.getPropertyRuleIntrospector(pageContext, getField());
        // Wrap the propertyRuleIntrospector
        propertyRuleIntrospector = TagHelper.wrapPropertyRuleIntrospector(propertyRuleIntrospector, model);
        if (log.isDebugEnabled())
            log.debug(this.NAME + " [field=" + getField() + "] PropertyRuleIntrospector is " + propertyRuleIntrospector);
    } catch (JspException e) {
        log.error("EditBoxTag.otherDoStartTagOperations(): error=" + e);
    }
    if (propertyRuleIntrospector.isHidden()) {
        // Display the (Restricted) text for a hidden field
        html = TagHelper.getTextForHiddenField(pageContext);
    } else {
        if (model != null) {
            if (propertyRuleIntrospector.isReadOnly()) {
                if (!m_password) {
                    // Just display the text for a readOnly field
                    html = StringHelper.convertToHTML(propertyRuleIntrospector.format(model.getWidgetValue()));
                    html = convertTextToHtml(html, getRows() > 1);
                }
            } else {
                String formName = TagHelper.getFormTag(pageContext).getHtmlName();
                String idPrefix = getHtmlIdPrefix();
                String eventPrefix = getJaffaEventNamePrefix();
                String classPrefix = propertyRuleIntrospector.isMandatory() ? "<span class=\"editboxMandatoryPrefix\">&nbsp;</span>" : "<span class=\"editboxOptionalPrefix\">&nbsp;</span>";
                String classSuffix = propertyRuleIntrospector.isMandatory() ? "<span class=\"editboxMandatorySuffix\">&nbsp;</span>" : "<span class=\"editboxOptionalSuffix\">&nbsp;</span>";
                // Set the layout on the model from the introspector
                model.setLayout(propertyRuleIntrospector.getLayout());
                // Generate the HTML
                try {
                    // @TODO - need to use the getHtmlTextArea regardless of rows, if this is a LIFO/FIFO comment style field
                    String commentStyle = propertyRuleIntrospector.getCommentStyle();
                    if (PLAIN.equals(commentStyle))
                        commentStyle = null;
                    // Default the trim attribute to 'false' for textarea and password fields. Default to 'true' for all others
                    if (!m_trimAttributePassed)
                        m_trim = getRows() > 1 || commentStyle != null || m_password ? false : true;
                    if (getRows() > 1 || commentStyle != null) {
                        // retrieve the original text from the orignal model. Create one if the orignal model does not exist when LIFO/FIFO.
                        String originalText = null;
                        if (LIFO.equals(commentStyle) || FIFO.equals(commentStyle)) {
                            FormBase formObject = TagHelper.getFormBase(pageContext);
                            SimpleWidgetModel origWM = (SimpleWidgetModel) formObject.getWidgetCache().getModel(getField() + "_original");
                            if (origWM == null) {
                                // this is the first time this comment tag has been executed
                                formObject.getWidgetCache().addModel(getField() + "_original", new SimpleWidgetModel(model));
                                originalText = model.getStringValue();
                                model.setWidgetValue(null);
                            } else {
                                // the original text was cached
                                originalText = origWM.getStringValue();
                            }
                        }
                        // create the html string
                        StringBuffer sb = new StringBuffer();
                        if (FIFO.equals(commentStyle)) {
                            if (originalText != null)
                                sb.append(convertTextToHtml(originalText, true)).append("<br/>");
                        }
                        sb.append(classPrefix).append(getHtmlTextArea(idPrefix, eventPrefix, formName, model, propertyRuleIntrospector)).append(classSuffix);
                        if (LIFO.equals(commentStyle)) {
                            if (originalText != null)
                                sb.append("<br/>").append(convertTextToHtml(originalText, true));
                        }
                        html = sb.toString();
                    } else {
                        html = classPrefix + getHtml(idPrefix, eventPrefix, formName, model, propertyRuleIntrospector) + classSuffix;
                    }
                } catch (JspException e) {
                    log.error("EditBox.otherDoStartTagOperations(): error in getHtml call: " + e);
                }
            }
        }
    }
    if (html != null) {
        // Write the HTML
        JspWriter out = pageContext.getOut();
        try {
            out.print(html);
        } catch (IOException e) {
            String str = "Exception in writing the " + TAG_NAME;
            log.error(str, e);
            throw new JspWriteRuntimeException(str, e);
        }
    }
}
Also used : JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel) IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector) JspException(javax.servlet.jsp.JspException) FormBase(org.jaffa.presentation.portlet.FormBase) MissingParametersRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)

Example 4 with MissingParametersRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException in project jaffa-framework by jaffa-projects.

the class RadioButtonTag method otherDoStartTagOperations.

/**
 * This generates the HTML for the tag.
 * @throws JspException if any error occurs.
 */
public void otherDoStartTagOperations() throws JspException {
    super.otherDoStartTagOperations();
    // Preprocess if within a Property widget
    IPropertyRuleIntrospector propertyRuleIntrospector = lookupPropertyTag();
    // raise an error, if the 'field' is null
    if (getField() == null) {
        String str = "The " + TAG_NAME + " requires 'field' parameter to be supplied or it should be within a PropertyTag";
        log.error(str);
        throw new MissingParametersRuntimeException(str);
    }
    // Will hold the required html
    String html = null;
    // Get the model
    SimpleWidgetModel model = null;
    try {
        model = (SimpleWidgetModel) TagHelper.getModel(pageContext, getField(), TAG_NAME);
    } catch (ClassCastException e) {
        String str = "Wrong WidgetModel for " + TAG_NAME + " on field " + getField();
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
    // Check for an IPropertyRuleIntrospector, if this tag is not within a Property widget
    if (propertyRuleIntrospector == null)
        propertyRuleIntrospector = TagHelper.getPropertyRuleIntrospector(pageContext, getField());
    // Wrap the propertyRuleIntrospector
    propertyRuleIntrospector = TagHelper.wrapPropertyRuleIntrospector(propertyRuleIntrospector, model);
    if (propertyRuleIntrospector.isHidden()) {
        // Display the (Restricted) text for a hidden field
        html = TagHelper.getTextForHiddenField(pageContext);
    } else {
        if (model != null) {
            if (propertyRuleIntrospector.isReadOnly()) {
                // Render a readOnly field as a displayOnly checkbox
                m_displayOnly = true;
            }
            html = getHtml(getHtmlIdPrefix(), model, propertyRuleIntrospector);
        }
    }
    if (html != null) {
        // Write the HTML
        JspWriter out = pageContext.getOut();
        try {
            out.print(html);
        } catch (IOException e) {
            String str = "Exception in writing the " + TAG_NAME;
            log.error(str, e);
            throw new JspWriteRuntimeException(str, e);
        }
    }
}
Also used : IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector) JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) MissingParametersRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException) SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)

Example 5 with MissingParametersRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException in project jaffa-framework by jaffa-projects.

the class TextTag method otherDoStartTagOperations.

// //////////////////////////////////////////////////////////////
// /                                                          ///
// /   User methods.                                          ///
// /                                                          ///
// /   Modify these methods to customize your tag handler.    ///
// /                                                          ///
// //////////////////////////////////////////////////////////////
// 
// methods called from doStartTag()
// 
/**
 * This generates the HTML for the tag.
 */
public void otherDoStartTagOperations() {
    try {
        super.otherDoStartTagOperations();
    } catch (JspException e) {
        log.error("TextTag.otherDoStartTagOperations(): error=" + e);
    }
    // Preprocess if within a Property widget
    IPropertyRuleIntrospector propertyRuleIntrospector = lookupPropertyTag();
    // raise an error, if the 'field' is null
    if (getField() == null) {
        String str = "The " + TAG_NAME + " requires 'field' parameter to be supplied or it should be within a PropertyTag";
        log.error(str);
        throw new MissingParametersRuntimeException(str);
    }
    // Get the formtag from the page & register the widget
    FormTag formTag = TagHelper.getFormTag(pageContext);
    if (formTag == null) {
        String str = "The " + TAG_NAME + " should be inside a FormTag";
        log.error(str);
        throw new OuterFormTagMissingRuntimeException(str);
    }
    // Get the value
    Object value = null;
    // Check for an IPropertyRuleIntrospector, if this tag is not within a Property widget
    if (propertyRuleIntrospector == null)
        try {
            propertyRuleIntrospector = TagHelper.getPropertyRuleIntrospector(pageContext, getField());
        } catch (JspException e) {
            log.error("TextTag.otherDoStartTagOperations() error getting property inspector=" + e);
        }
    if (propertyRuleIntrospector != null && propertyRuleIntrospector.isHidden()) {
        // Display the (Restricted) text for a hidden field
        value = TagHelper.getTextForHiddenField(pageContext);
    } else {
        // Use introspection to obtain the field-value from an IModelMap or the FormBase
        value = TagHelper.getFieldValue(pageContext, getField(), TAG_NAME);
        // format the value
        if (value != null) {
            // Determine the layout to be used for formatting the value
            // The highest precedence goes to the rules definition
            String layout = propertyRuleIntrospector != null ? propertyRuleIntrospector.getLayout() : null;
            if (layout == null) {
                // Use the layout attribute, if specified
                if (m_layout != null) {
                    layout = m_layout;
                } else {
                    // Use the domain and domain attributes, if specified
                    if (m_domain != null && m_domainField != null)
                        layout = obtainLayoutUsingFieldMetaData(m_domain, m_domainField);
                    // Finally try to use the Form and Field to determine the appropriate FieldMetaData
                    // Do it only if they differ from the domain/domainField
                    String formClass = TagHelper.getFormBase(pageContext).getClass().getName();
                    if (layout == null && (m_domain == null || m_domainField == null || !m_domain.equals(formClass) || !m_domainField.equals(getField())))
                        layout = obtainLayoutUsingFieldMetaData(formClass, getField());
                }
            }
            // Now Format the value
            String formattedValue = null;
            if (layout != null)
                formattedValue = Formatter.format(value, layout);
            else
                formattedValue = Formatter.format(value);
            if (formattedValue != null) {
                if (formattedValue.length() == 0)
                    formattedValue = null;
                else {
                    if (getType() == null || !getType().equalsIgnoreCase("HTML")) {
                        formattedValue = StringHelper.convertToHTML(formattedValue);
                        formattedValue = StringHelper.replace(formattedValue, "\r\n", "<BR>");
                        formattedValue = StringHelper.replace(formattedValue, "\n\r", "<BR>");
                        formattedValue = StringHelper.replace(formattedValue, "\r", "<BR>");
                        formattedValue = StringHelper.replace(formattedValue, "\n", "<BR>");
                    // formattedValue = StringHelper.replace(formattedValue, " ", TagHelper.HTML_SPACE_CHARACTER);
                    }
                    if (getMaxLength() != null)
                        formattedValue = processMaxLength(formattedValue);
                    formattedValue = generateHyperlink(formattedValue, propertyRuleIntrospector);
                }
            }
            value = formattedValue;
        }
    }
    if (value != null) {
        // wrap <pre> tag arround the value if it is a comment property
        if (isPreFormated(propertyRuleIntrospector)) {
            value = "<pre>" + value + "</pre>";
        }
        // Write the HTML
        JspWriter out = pageContext.getOut();
        try {
            out.print(value);
        } catch (IOException e) {
            String str = "Exception in writing the " + TAG_NAME;
            log.error(str, e);
            throw new JspWriteRuntimeException(str, e);
        }
    }
}
Also used : IPropertyRuleIntrospector(org.jaffa.rules.IPropertyRuleIntrospector) JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) JspException(javax.servlet.jsp.JspException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter) MissingParametersRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)

Aggregations

IOException (java.io.IOException)7 JspWriteRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException)7 MissingParametersRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)7 JspException (javax.servlet.jsp.JspException)6 JspWriter (javax.servlet.jsp.JspWriter)6 IPropertyRuleIntrospector (org.jaffa.rules.IPropertyRuleIntrospector)5 SimpleWidgetModel (org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)4 OuterFormTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)4 FormBase (org.jaffa.presentation.portlet.FormBase)1