Search in sources :

Example 1 with WidgetModelAccessMethodNotFoundRuntimeException

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

the class TagHelper method getFieldValue.

/**
 * For an enclosed tag, this will return the fieldValue from the pageContext attribute, and it may be null.
 * If the tag is not enclosed, it will get the fieldValue from the FormBase, and it will throw a RuntimeException if the property is not found.
 * @param pageContext The PageContext of the jsp.
 * @param fieldName The field name.
 * @param tagName The tag name.
 * @return a value for the field.
 */
public static Object getFieldValue(PageContext pageContext, String fieldName, String tagName) {
    Object value = null;
    if (isEnclosed(pageContext)) {
        Map map = getModelMap(pageContext);
        if (map != null)
            value = map.get(fieldName);
    } else {
        FormBase formObject = getFormBase(pageContext);
        if (formObject != null) {
            try {
                value = BeanHelper.getField(formObject, fieldName);
            } catch (NoSuchMethodException e) {
                // Lets look for a getXyzWM() method
                try {
                    value = BeanHelper.getField(formObject, fieldName + "WM");
                } catch (NoSuchMethodException e1) {
                    String str = "Getter Method for field " + fieldName + " not found while evaluating the " + tagName;
                    log.error(str, e);
                    throw new WidgetModelAccessMethodNotFoundRuntimeException(str, e);
                }
            }
        } else {
            String str = "The " + tagName + " for field " + fieldName + " should be inside a FormTag";
            log.error(str);
            throw new OuterFormTagMissingRuntimeException(str);
        }
    }
    if (value != null && value instanceof SimpleWidgetModel)
        value = ((SimpleWidgetModel) value).getWidgetValue();
    return value;
}
Also used : FormBase(org.jaffa.presentation.portlet.FormBase) WidgetModelAccessMethodNotFoundRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodNotFoundRuntimeException) OuterFormTagMissingRuntimeException(org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException) SimpleWidgetModel(org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)

Example 2 with WidgetModelAccessMethodNotFoundRuntimeException

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

Aggregations

FormBase (org.jaffa.presentation.portlet.FormBase)2 OuterFormTagMissingRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.OuterFormTagMissingRuntimeException)2 WidgetModelAccessMethodNotFoundRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodNotFoundRuntimeException)2 Method (java.lang.reflect.Method)1 JspException (javax.servlet.jsp.JspException)1 SimpleWidgetModel (org.jaffa.presentation.portlet.widgets.model.SimpleWidgetModel)1 WidgetModelAccessMethodInvocationRuntimeException (org.jaffa.presentation.portlet.widgets.taglib.exceptions.WidgetModelAccessMethodInvocationRuntimeException)1 RulesEngineException (org.jaffa.rules.RulesEngineException)1