Search in sources :

Example 6 with OuterFormTagMissingRuntimeException

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

the class TagHelper method getModel.

/**
 * For an enclosed tag, this will return the model from the pageContext attribute, and it may be null.
 * If the tag is not enclosed, it will get the model from the FormBase, and it will throw a RuntimeException if the model is not found.
 * @param pageContext The PageContext of the jsp.
 * @param fieldName The field name.
 * @param tagName The tag name.
 * @return a WidgetModel object.
 */
public static Object getModel(PageContext pageContext, String fieldName, String tagName) {
    Object model = null;
    if (isEnclosed(pageContext)) {
        Map map = getModelMap(pageContext);
        if (map != null)
            model = map.get(fieldName);
    } else {
        FormBase formObject = getFormBase(pageContext);
        if (formObject != null) {
            // Work out the method to get the model...should be like getFieldNameWM()
            Class formClass = formObject.getClass();
            String methodStr = "get" + StringHelper.getUpper1(fieldName) + "WM";
            if (log.isDebugEnabled())
                log.debug("Introspect. Looking for " + methodStr + " on " + formClass.getName());
            Method method = null;
            try {
                method = formClass.getMethod(methodStr, new Class[] {});
            } catch (NoSuchMethodException e) {
                String str = "Method :" + methodStr + " not found";
                log.error(str, e);
                throw new WidgetModelAccessMethodNotFoundRuntimeException(str, e);
            }
            try {
                model = method.invoke(formObject, new Object[] {});
                if (log.isDebugEnabled())
                    log.debug("Introspect. Got Model from FormBean");
            } catch (Exception e) {
                String str = "Error while invoking the method :" + methodStr;
                log.error(str, e);
                throw new WidgetModelAccessMethodInvocationRuntimeException(str, e);
            }
        } else {
            String str = "The " + tagName + " for field " + fieldName + " should be inside a FormTag";
            log.error(str);
            throw new OuterFormTagMissingRuntimeException(str);
        }
    }
    return model;
}
Also used : FormBase(org.jaffa.presentation.portlet.FormBase) WidgetModelAccessMethodNotFoundRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodNotFoundRuntimeException) Method(java.lang.reflect.Method) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) JspException(javax.servlet.jsp.JspException) RulesEngineException(org.jaffa.rules.RulesEngineException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) WidgetModelAccessMethodNotFoundRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodNotFoundRuntimeException) WidgetModelAccessMethodInvocationRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodInvocationRuntimeException) WidgetModelAccessMethodInvocationRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodInvocationRuntimeException)

Example 7 with OuterFormTagMissingRuntimeException

use of org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException 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)

Example 8 with OuterFormTagMissingRuntimeException

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

the class ButtonTag method otherDoStartTagOperations.

// 
// methods called from doStartTag()
// 
/**
 * This generates the HTML for the tag.
 */
public void otherDoStartTagOperations() {
    try {
        super.otherDoStartTagOperations();
    } catch (JspException e) {
        log.error("ButtonTag.otherDoStartTagOperations() error: " + e);
    }
    // 
    // TODO: code that performs other operations in doStartTag
    // should be placed here.
    // It will be called after initializing variables,
    // finding the parent, setting IDREFs, etc, and
    // before calling theBodyShouldBeEvaluated().
    // 
    // check if the tag is enclosed
    boolean enclosed = TagHelper.isEnclosed(pageContext);
    // 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);
    }
    if (getGuarded())
        formTag.registerGuardedButton();
    // Generate the HTML
    JspWriter out = pageContext.getOut();
    String formName = TagHelper.getFormTag(pageContext).getHtmlName();
    String idPrefix = getHtmlIdPrefix();
    String eventPrefix = getJaffaEventNamePrefix();
    try {
        out.println(getHtml(idPrefix, eventPrefix, formName, enclosed));
    } 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) JspException(javax.servlet.jsp.JspException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Example 9 with OuterFormTagMissingRuntimeException

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

the class GridTag method otherDoStartTagOperations.

/**
 * Sets the GridModel and an iterator on the rows of the GridModel.
 */
public void otherDoStartTagOperations() throws JspException {
    super.otherDoStartTagOperations();
    // Ensure a correct value is passed in outputType
    if (m_outputType == null)
        m_outputType = OUTPUT_TYPE_WEB_PAGE;
    else if (!OUTPUT_TYPE_WEB_PAGE.equals(m_outputType) && !OUTPUT_TYPE_EXCEL.equals(m_outputType) && !OUTPUT_TYPE_XML.equals(m_outputType))
        throw new IllegalArgumentException("Illegal outputType '" + m_outputType + "' passed to the " + TAG_NAME + ". Valid values are " + OUTPUT_TYPE_WEB_PAGE + ',' + OUTPUT_TYPE_EXCEL + ',' + OUTPUT_TYPE_XML);
    // The grid tag cannot be enclosed withing another tag !!!
    if (TagHelper.isEnclosed(pageContext)) {
        String str = "The " + TAG_NAME + " cannot be enclosed within another tag";
        log.error(str);
        throw new TagCannotBeEnclosedRuntimeException(str);
    }
    // Store the Original Attributes
    m_originalAttributes = TagHelper.getOriginalAttributes(pageContext);
    // 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 model
    try {
        m_model = (GridModel) 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);
    }
    if (m_model != null) {
        Collection rows = m_model.getRows();
        if (rows != null && rows.size() > 0) {
            m_hasRows = true;
            m_modelIterator = rows.iterator();
        }
    }
    if (isUserGrid()) {
        // raise an error, if the error-flag is set on the model
        if (m_model.getErrorInSavingUserSettings()) {
            TagHelper.getFormBase(pageContext).raiseError((HttpServletRequest) pageContext.getRequest(), ActionMessages.GLOBAL_MESSAGE, "error.widgets.usergrid.savefailed");
            m_model.setErrorInSavingUserSettings(false);
        }
        // See if there are any user configuration settings available for this user and grid.
        UserSession us = UserSession.getUserSession((HttpServletRequest) pageContext.getRequest());
        UserGridManager userGridManager = new UserGridManager();
        // returns null if no configuration settings are found.
        m_selectedCols = userGridManager.getColSettings(us.getUserId(), getUserGridId());
    // @todo: There was legacy code at this point as we used to store translated labels
    // in the XML files. We have for a while now, only stored labels. This TODO is to add
    // back in the legacy support...if the need arises.
    }
    // Determine based on widget type and Context rules if user has disabled hints
    if (!m_popupHintsSet) {
        m_popupHints = isUserGrid();
        String rule = isUserGrid() ? RULE_USERGRID_POPUP : RULE_GRID_POPUP;
        String popupHints = (String) ContextManagerFactory.instance().getProperty(rule);
        if (popupHints != null)
            m_popupHints = Boolean.valueOf(popupHints).booleanValue();
        log.debug("popupHints (from rule: " + rule + ") defaults to " + m_popupHints);
    }
}
Also used : JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) UserSession(org.jaffa.presentation.portlet.session.UserSession) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) TagCannotBeEnclosedRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.TagCannotBeEnclosedRuntimeException) UserGridManager(org.jaffa.presentation.portlet.widgets.controller.UserGridManager)

Example 10 with OuterFormTagMissingRuntimeException

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

the class RaiseErrorsTag method otherDoEndTagOperations.

/**
 * This generates the HTML for the tag.
 * Writes a script tag containing error message details to be added to the current jsp.
 *
 * @throws JspException if any error occurs.
 */
public void otherDoEndTagOperations() throws JspException {
    // Get the form bean from the page.
    FormBase form = TagHelper.getFormBase(pageContext);
    if (form == null) {
        String str = "The " + TAG_NAME + " should be inside a FormTag";
        log.error(str);
        throw new OuterFormTagMissingRuntimeException(str);
    }
    // get the errors from the form
    if (!FormBase.hasErrors((HttpServletRequest) pageContext.getRequest())) {
        return;
    }
    ActionMessages errors = FormBase.getErrors((HttpServletRequest) pageContext.getRequest());
    StringBuilder buf = new StringBuilder();
    buf.append("<SCRIPT type=\"text/javascript\">");
    for (Iterator itr = errors.get(); itr.hasNext(); ) {
        ActionMessage error = (ActionMessage) itr.next();
        buf.append("addMessage(\"");
        String messageHtml = StringHelper.convertToHTML(MessageHelper.findMessage(pageContext, error.getKey(), error.getValues()));
        String labelEditorLink = TagHelper.getLabelEditorLink(pageContext, error.getKey());
        // escape the message for html to prevent XSS
        String message = Encode.forHtml(messageHtml) + labelEditorLink;
        buf.append(message);
        buf.append("\");");
    }
    // delete the error so that it doesn't get re-displayed
    form.clearErrors((HttpServletRequest) pageContext.getRequest());
    buf.append("</SCRIPT>");
    // add the script tag containing the error message to the current jsp
    try {
        JspWriter w = pageContext.getOut();
        w.print(buf.toString());
    } catch (IOException e) {
        String str = "Exception in writing the " + TAG_NAME;
        log.error(str, e);
        throw new JspWriteRuntimeException(str, e);
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JspWriteRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException) ActionMessages(org.apache.struts.action.ActionMessages) FormBase(org.jaffa.presentation.portlet.FormBase) Iterator(java.util.Iterator) ActionMessage(org.apache.struts.action.ActionMessage) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) IOException(java.io.IOException) JspWriter(javax.servlet.jsp.JspWriter)

Aggregations

OuterFormTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)10 JspWriteRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.JspWriteRuntimeException)8 IOException (java.io.IOException)7 JspWriter (javax.servlet.jsp.JspWriter)7 JspException (javax.servlet.jsp.JspException)6 FormBase (org.jaffa.presentation.portlet.FormBase)4 SimpleWidgetModel (org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)4 MissingParametersRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.MissingParametersRuntimeException)4 IPropertyRuleIntrospector (org.jaffa.rules.IPropertyRuleIntrospector)4 WidgetModelAccessMethodNotFoundRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodNotFoundRuntimeException)2 Method (java.lang.reflect.Method)1 Iterator (java.util.Iterator)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ActionMessage (org.apache.struts.action.ActionMessage)1 ActionMessages (org.apache.struts.action.ActionMessages)1 UserSession (org.jaffa.presentation.portlet.session.UserSession)1 UserGridManager (org.jaffa.presentation.portlet.widgets.controller.UserGridManager)1 ImageModel (org.jaffa.presentation.portlet.widgets.model.ImageModel)1 TagCannotBeEnclosedRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.TagCannotBeEnclosedRuntimeException)1 WidgetModelAccessMethodInvocationRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodInvocationRuntimeException)1