[jboss-user] [JBoss Seam] - Re: f:converter and maxdigits
damianharvey
do-not-reply at jboss.com
Sun Jan 27 01:43:10 EST 2008
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#4123806
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4123806
More information about the jboss-user
mailing list