开发者

using custom message for multiple intboxes in zk

开发者 https://www.devze.com 2023-04-05 08:38 出处:网络
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 nee

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消