I had a similar problem today but was getting IllegalArgumentExceptions and
ClassCastExceptions. For anyone interested below is a basic Float Currency converter. You
use it like this:
| <h:inputText id="myvalue" converter="#{floatCurrencyConverter}"
value="#{mybean.myFloatValue}"/>
| import java.text.NumberFormat;
|
| import javax.faces.component.UIComponent;
| import javax.faces.context.FacesContext;
|
| import org.jboss.seam.annotations.Name;
| import org.jboss.seam.annotations.faces.Converter;
| import org.jboss.seam.annotations.intercept.BypassInterceptors;
|
| @Name("floatCurrencyConverter")
| @BypassInterceptors
| @Converter
| public class FloatCurrencyConverter implements javax.faces.convert.Converter {
|
| public Object getAsObject(FacesContext context, UIComponent cmp, String value) {
| NumberFormat nf = NumberFormat.getCurrencyInstance();
|
| try {
| return new Float(nf.parse(value).floatValue());
| } catch(java.text.ParseException e) {
| e.printStackTrace();
| return null;
| }
| }
|
| public String getAsString(FacesContext context, UIComponent cmp, Object value) {
|
| NumberFormat nf = NumberFormat.getCurrencyInstance();
| return nf.format(value);
| }
| }
|
Cheers,
Damian.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4123806#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...