All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jpaoletti.jpm.struts.converter.EditDecimalConverter Maven / Gradle / Ivy

The newest version!
package jpaoletti.jpm.struts.converter;

import java.math.BigDecimal;

import java.math.RoundingMode;
import jpaoletti.jpm.converter.ConverterException;
import jpaoletti.jpm.core.PMContext;

/**Converter for integer 
* Properties: currency and format *
 * {@code
 * 
 *     
 *         
 *         
 *         
 *     
 * 
 * }
 * 
* @author jpaoletti * */ public class EditDecimalConverter extends DefaultStrutsConverter { @Override public Object build(PMContext ctx) throws ConverterException { try { final String separator = getConfig("separator", "."); return new BigDecimal(((String) ctx.getFieldValue()).replace(separator, ".")); } catch (Exception e) { return null; } } @Override public String visualize(PMContext ctx) throws ConverterException { BigDecimal p = (BigDecimal) ctx.getFieldValue(); if (p == null) { p = (BigDecimal) getValue(ctx.getEntityInstance(), ctx.getField()); } final Integer decimals = Integer.parseInt(getConfig("decimals", "2")); final String separator = getConfig("separator", "."); final String value = (p == null) ? "" : p.setScale( decimals, RoundingMode.HALF_EVEN).toString().replace(".", separator); ctx.setFieldValue(value); return super.visualize("decimal-edit.jsp?" + "&isNull=" + (p == null) + "&withNull=" + getConfig("with-null", "false") + "&separator=" + separator + "&decimals=" + decimals); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy