i have several intboxes under the same window parent. I created a custom validator with custom message for an intbox. For displaying the error message i use a label which i give a unique id. Now i need to use the same constraint for all the intboxes. As in the custom error message i have a unique label id for displaying the error so how do i use the same message for all the intboxes? Here is the code for my custom validator with custom message:
<zscipt> <![CDATA[
class MyConst implements Constraint, CustomConstraint {
//Constraint//
public void validate(Component comp, Object value) {
if (value == null || ((Integer)value).intValue() >8)
throw new WrongValueException(comp, "values only b/w 0 and 8");
}
//CustomConstraint//
public void showCustomError(Component comp, WrongValueEx开发者_Python百科ception ex) {
errmsg.setValue(ex != null ? ex.getMessage(): "");
}
}
Constraint ctt = new MyConst();
]]>
Thanks.
There are a couple solutions. First, you could enhance MyConst's constructor to accept Label.
Second, you could use a name pattern. For example, if the label's ID is always a catenation of the textbox's ID and, say, "Error". Then, you could use comp.getFellow(comp.getId()+"Error") to retrieve the label.
In addition, you could use the server-side component selector to get the label.
精彩评论