Step by step tutorial: how to build a bean for Servoy - Servoy Stuff
Step by step tutorial: how to build a bean for Servoy - Servoy Stuff
Step by step tutorial: how to build a bean for Servoy - Servoy Stuff
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
How <strong>to</strong> <strong>build</strong> a <strong>bean</strong> <strong>for</strong> <strong>Servoy</strong> - A <strong>step</strong> <strong>by</strong> <strong>step</strong> <strong>tu<strong>to</strong>rial</strong> brought <strong>to</strong> you <strong>by</strong> <strong>Servoy</strong> <strong>Stuff</strong><br />
The testChanged() method doesn’t exist yet in our class, but there is little Eclipse won’t do <strong>for</strong> you if<br />
you ask it nicely with a “Quick Fix” trick:<br />
This will add the method stub directly in our WicketTestBean class (even if the java file is not opened)!<br />
And now, do you remember what we did in our Swing <strong>bean</strong> be<strong>for</strong>e we updated our record That’s<br />
right, we checked if an update was needed <strong>by</strong> comparing the value of the new text <strong>to</strong> the previous<br />
version.<br />
Which means we need <strong>to</strong> add a previousText variable <strong>to</strong> our class:<br />
protected String previousText;<br />
And then update its value when <strong>Servoy</strong> sets a selected record:<br />
public void setSelectedRecord(IRecord record) {<br />
this.currentRecord = record;<br />
if (<strong>Servoy</strong>Utils.isContainedInFoundset(currentRecord,getDataProviderID())) {<br />
Object o = currentRecord.getValue(getDataProviderID());<br />
this.text = (o==null) null : o.<strong>to</strong>String();<br />
this.previousText = getText();<br />
setChanged();<br />
}<br />
}<br />
Now that our previousText value is coherent, we can use it <strong>to</strong> test if the new value is really « new » :<br />
/**<br />
* Will trigger an update if the text has changed:<br />
*/<br />
public void testChanged() {<br />
if (!Utils.stringSafeEquals(previousText, getText())) {<br />
setChanged();<br />
}<br />
}<br />
You remember the Utils.stringSafeEquals we used in our Swing <strong>bean</strong>. Same thing here, and if it is<br />
needed we set our ChangesRecorder <strong>to</strong> “changed”.<br />
26/37