Index.zul
- <zk>
- <window border="normal" closable="false"
- apply="org.zkoss.bind.BindComposer"
- viewModel="@id('vm') @init('pkg$.IndexVm')" width="100%" height="100%">
- <doublebox value="@load(vm.theNumber)" tooltiptext="@load(vm.theNumber) @converter(vm.myConverter)"/>
- <doublebox value="@load(vm.theNumber2)" tooltiptext="@load(vm.theNumber2) @converter(vm.myConverter)"/>
- <doublebox value="@load(vm.theNumber3)" tooltiptext="@load(vm.theNumber3) @converter(vm.myConverter)"/>
- </window>
- </zk>
CustomConveter.java
import org.zkoss.bind.BindContext;
import org.zkoss.bind.Converter;
import org.zkoss.zk.ui.Component;
/**
*
* @author sitansu
*/
public class CustomConverter implements Converter {
public Object coerceToUi(Object val, Component comp, BindContext ctx) {
String value = String.valueOf(val);
int pointer = value.length();
if (value.contains(",")|| value.contains(".")) {
for (int counter = value.length()-1;counter>0;counter--) {
char character = value.charAt(counter);
if (character == '0') {
pointer = counter - 1;
continue;
} else if (character == ',') {
pointer = counter - 1;
break;
} else {
break;
}
}
value = value.substring(0, pointer);
}
return value;
}
public Object coerceToBean(Object val, Component comp, BindContext ctx) {
throw new UnsupportedOperationException("Not supported yet.");
}
}
IndexVm .java
import org.zkoss.bind.Converter;
/**
*
* @author Sitansu
*/
public class IndexVm {
public IndexVm () {}
private Converter myConverter = new CustomConverter();
public Converter getMyConverter(){
return myConverter;
}
public double getTheNumber () {
return 40.000;
}
public double getTheNumber2 () {
return 40.1;
}
public double getTheNumber3 () {
return (double)40;
}
}
No comments:
Post a Comment