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;
}
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;
}
Aggregations