0

re: Decimalbox onChanging (OnEvent)

asked 2008-07-09 02:16:25 +0800

nargv2008 gravatar image nargv2008
48

I have issue with decimalbox OnChanging EventListener. Please see codes below.
My goal is to make sure that the inputevent is working. So on "onEvent" method
I always set the Value to zero However, it only works
during the first input meaning If i input something during first attempt, it is setting my decimalbox
correctly to zero but the next or succeeding input attempt it cannot set the value to zero. If you noticed
in my code I put some testing with background and setting style() is working but the setValue() is not.


Thanks,


*** ZUL SCRIPT ****

<zk>
<separator spacing="20px"/>
<hbox spacing="2em">
<decimalbox use="BoxWeight"/>
</hbox>
</zk>


*** JAVA CODE ***
BoxWeight

public class BoxWeight extends Decimalbox implements EventListener {
private InputEvent ie;
private static Log log = LogFactory.getLog(BoxWeight.class);
private int i=0;
public BoxWeight() {
this.setValue(new BigDecimal(0));
this.addEventListener("onChanging",this);
}


public void onChanging() {

}

public void onEvent(Event arg0) {
if(i==0) {
this.setStyle("background:yellow");
}
if(i==1) {
this.setStyle("background:red");
}
if(i==2) {
this.setStyle("background:blue");
}
this.setValue(new BigDecimal(0));
i++;

}

public boolean isAsap() {
// TODO Auto-generated method stub
return false;
}

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2008-07-09 06:24:28 +0800

dennis gravatar image dennis
3679 1 6
http://www.javaworld.com....

When onChanging , the original value of decimalbox doesn't be changed to the changing value(remain on 0 when changing in this case)
So, when you change the value to '0' , there is no update to client since the value doesn't change from component view.
try following code , it should work.

	public void onEvent(Event arg0) {
		if (i == 0) {
			this.setStyle("background:yellow");
		}else if (i == 1) {
			this.setStyle("background:red");
		}else if (i == 2) {
			this.setStyle("background:blue");
		}else{
			this.setValue(new BigDecimal(-1));
			this.setValue(new BigDecimal(0));
		}
		i++;
	}

link publish delete flag offensive edit

answered 2008-07-09 06:58:46 +0800

nargv2008 gravatar image nargv2008
48

my really concern is that in each input or everytime new input in decimalbox will be evaluated meaning onchanging rather than
onChange. like if user entered "-" or "," it should not be considered but immediately disappeared/removed that
in the decimalbox. I was able to solve my problem using invalidate().

So my workaround is to use invalidate

public void onEvent(Event arg0) {
ie = (InputEvent)arg0;
evaluateDecimalBox(this,ie.getValue());

}



public String evaluateDecimalBox(Decimalbox aComp,String aValue) {


if( (aValue==null)|| (aValue.trim().length()==0)) {
aValue="0.0";
aComp.setValue(new BigDecimal(0));
aComp.invalidate();
}

//cannot accept negative value
if(aValue.startsWith("-")) {
aValue="0.0";
aComp.setValue(new BigDecimal(0));
aComp.invalidate();
}

//if negative was somewhere remove it in screen
else
if(aValue.indexOf("-")!=-1) {
log.info("negative is not permitted");
aValue=aComp.getValue().toString();
aComp.setValue(new BigDecimal(aValue));
aComp.invalidate();
}
//cannot accept duplicate dots
if(aValue.indexOf(".")!=-1) {
if(aValue.indexOf(".")==aValue.lastIndexOf(".")) {
//retain value

//remove multiple dots
}else {
aValue=aComp.getValue().toString();
aComp.setValue(new BigDecimal(aValue));
aComp.invalidate();
}
}
//cannot accept commas
if(aValue.indexOf(",")!=-1) {
aValue=aComp.getValue().toString();
aComp.setValue(new BigDecimal(aValue));
aComp.invalidate();
}
return aValue;
}


thanks...my evaluation is working fine now.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2008-07-09 02:16:25 +0800

Seen: 307 times

Last updated: Jul 09 '08

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More