From: Walter M. <wal...@us...> - 2008-02-25 14:28:45
|
User: walterim Date: 08/02/25 06:28:51 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils JsfUtils.java.vsl Log: Added methods to handle converters and FacesEvents parameters Revision Changes Path 1.2 +51 -0 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl Index: JsfUtils.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl,v retrieving revision 1.1 retrieving revision 1.2 diff -u -w -r1.1 -r1.2 --- JsfUtils.java.vsl 5 Dec 2006 19:39:21 -0000 1.1 +++ JsfUtils.java.vsl 25 Feb 2008 14:28:51 -0000 1.2 @@ -147,4 +147,55 @@ { return TEMPORARY_DIRECTORY + session.getId() + SERIALIZED_FORM_FILE_NAME; } + + /** + * Uses the converter identified by converterId to convert the value to a String. + * @value the value to be converted + * @converterId the id of the converter to be used + * @componentId the id of the component being rendered + * @return the String representation of the value. + */ + public static String valueFromConverter( + final Object value, + final String converterId, + final String componentId){ + final javax.faces.context.FacesContext facesContext=javax.faces.context.FacesContext.getCurrentInstance(); + final javax.faces.convert.Converter converter = facesContext.getApplication().createConverter(converterId); + return converter.getAsString(facesContext, + org.apache.commons.lang.StringUtils.isEmpty(componentId)?null:facesContext.getViewRoot().findComponent(componentId), + value); + } + + /** + * Uses the converter identified by converterId to convert the value to a String. + * @value the value to be converted + * @converterId the id of the converter to be used + * @return the String representation of the value. + */ + public static String valueFromConverter( + final Object value, + final String converterId){ + final javax.faces.context.FacesContext facesContext=javax.faces.context.FacesContext.getCurrentInstance(); + final javax.faces.convert.Converter converter = facesContext.getApplication().createConverter(converterId); + return converter.getAsString(facesContext,null,value); + } + + /** + * Returns an javax.faces.event.ActionEvent parameter value, from its name + * @parameterName the parameter name + * @event ActionEvent containing the parameter + * @return the parameter value. + */ + public static Object getParameterValue(String parameterName, javax.faces.event.ActionEvent event){ + for(Object uiObject : event.getComponent().getChildren()){ + if(uiObject instanceof javax.faces.component.UIParameter){ + final javax.faces.component.UIParameter param = (javax.faces.component.UIParameter)uiObject; + if(param.getName().equals(parameterName)) { + return param.getValue(); + } + } + } + throw new RuntimeException("Parameter "+parameterName+" not found"); + } + } |
From: Chad B. <cwb...@us...> - 2008-05-16 19:05:45
|
User: cwbrandon Date: 08/05/16 12:05:33 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils JsfUtils.java.vsl Log: add methods for getting and setting attributes on any kind of request, session, etc Revision Changes Path 1.5 +65 -0 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl Index: JsfUtils.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl,v retrieving revision 1.4 retrieving revision 1.5 diff -u -w -r1.4 -r1.5 --- JsfUtils.java.vsl 8 Apr 2008 16:29:07 -0000 1.4 +++ JsfUtils.java.vsl 16 May 2008 19:05:33 -0000 1.5 @@ -192,6 +192,71 @@ } /** + * Gets the attribute from the given object. The object can be either a context, request + * or resposne (HttpServletContext/PortletContext, HttpServletRequest/PortletRequest, etc). + * + * @param object the object from which to retrieve the attribute. + * @param attributeName the attribute name. + * @return the value of the attribute if one is present. + */ + public static Object getAttribute(final Object object, final String attributeName) + { + try + { + Object attribute = null; + if (object != null) + { + try + { + final java.lang.reflect.Method method = object.getClass().getMethod("getAttribute", new Class[]{String.class}); + method.invoke(object, new Object[]{attributeName}); + } + catch (NoSuchMethodException exception) + { + } + } + return attribute; + } + catch (Exception exception) + { + throw new RuntimeException(exception); + } + } + + /** + * Sets the attribute on the given object. The object can be either a context, request + * or resposne (HttpServletContext/PortletContext, HttpServletRequest/PortletRequest, etc). + * + * @param object the object on which to set the attribute. + * @param attributeName the attribute name. + * @param attributeValue the value of the attribute to set. + * @return the value of the attribute if one is present. + */ + public static Object setAttribute(final Object object, final String attributeName, final Object attributeValue) + { + try + { + Object attribute = null; + if (object != null) + { + try + { + final java.lang.reflect.Method method = object.getClass().getMethod("setAttribute", new Class[]{String.class, Object.class}); + method.invoke(object, new Object[]{attributeName, attributeValue}); + } + catch (NoSuchMethodException exception) + { + } + } + return attribute; + } + catch (Exception exception) + { + throw new RuntimeException(exception); + } + } + + /** * Uses the converter identified by converterId to convert the value to a String. * @value the value to be converted * @converterId the id of the converter to be used |
From: Chad B. <cwb...@us...> - 2008-05-20 16:21:46
|
User: cwbrandon Date: 08/05/20 09:21:46 Modified: andromda-jsf2/src/main/resources/templates/jsf2/utils JsfUtils.java.vsl Log: fix typo Revision Changes Path 1.6 +2 -4 cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl Index: JsfUtils.java.vsl =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-jsf2/src/main/resources/templates/jsf2/utils/JsfUtils.java.vsl,v retrieving revision 1.5 retrieving revision 1.6 diff -u -w -r1.5 -r1.6 --- JsfUtils.java.vsl 16 May 2008 19:05:33 -0000 1.5 +++ JsfUtils.java.vsl 20 May 2008 16:21:46 -0000 1.6 @@ -209,7 +209,7 @@ try { final java.lang.reflect.Method method = object.getClass().getMethod("getAttribute", new Class[]{String.class}); - method.invoke(object, new Object[]{attributeName}); + attribute = method.invoke(object, new Object[]{attributeName}); } catch (NoSuchMethodException exception) { @@ -232,11 +232,10 @@ * @param attributeValue the value of the attribute to set. * @return the value of the attribute if one is present. */ - public static Object setAttribute(final Object object, final String attributeName, final Object attributeValue) + public static void setAttribute(final Object object, final String attributeName, final Object attributeValue) { try { - Object attribute = null; if (object != null) { try @@ -248,7 +247,6 @@ { } } - return attribute; } catch (Exception exception) { |