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"); + } + } |