Primefaces 带“的输入掩码”;";价值观
如何在输入中输入每4个数字,我有如下内容:Primefaces 带“的输入掩码”;";价值观,primefaces,input-mask,Primefaces,Input Mask,如何在输入中输入每4个数字,我有如下内容: <p:inputMask mask="9999, 9999" placeHolder="_"/> 但是我需要“N”值,所以我不知道如何做到这一点。可以使用输入掩码来约束输入,这在用户将数据输入系统时受到约束。您不能设置没有限制的数字 我建议你改用转换器 xhtml 转换器 import java.io.Serializable; import java.math.RoundingMode; import java.text.Decim
<p:inputMask mask="9999, 9999" placeHolder="_"/>
但是我需要“N”值,所以我不知道如何做到这一点。可以使用输入掩码来约束输入,这在用户将数据输入系统时受到约束。您不能设置没有限制的数字 我建议你改用转换器 xhtml 转换器
import java.io.Serializable;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
/**
*
* @author Wittakarn
*/
@FacesConverter("numberConverter")
public class NumberConverter implements Serializable, Converter {
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
return string.replaceAll(",", "");
}
public String getAsString(FacesContext fc, UIComponent uic, Object o) {
String resp = "";
DecimalFormat decimalFormat;
if (o != null) {
decimalFormat = new DecimalFormat("#,####");
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
try {
resp = decimalFormat.format(Double.parseDouble(o.toString()));
} catch (Exception ex) {
ex.printStackTrace();
}
}
return resp;
}
}
@SessionScoped
@ManagedBean(name = "inputTextView")
public class InputTextView {
private String numberInput;
public String getNumberInput() {
return numberInput;
}
public void setNumberInput(String numberInput) {
this.numberInput = numberInput;
}
}
import java.io.Serializable;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
/**
*
* @author Wittakarn
*/
@FacesConverter("numberConverter")
public class NumberConverter implements Serializable, Converter {
public Object getAsObject(FacesContext fc, UIComponent uic, String string) {
return string.replaceAll(",", "");
}
public String getAsString(FacesContext fc, UIComponent uic, Object o) {
String resp = "";
DecimalFormat decimalFormat;
if (o != null) {
decimalFormat = new DecimalFormat("#,####");
decimalFormat.setRoundingMode(RoundingMode.HALF_UP);
try {
resp = decimalFormat.format(Double.parseDouble(o.toString()));
} catch (Exception ex) {
ex.printStackTrace();
}
}
return resp;
}
}