在我的 xpage 上,我为 inputtext 控件定义了一个验证器:<xp:inputText id="cv" disabled="#{!employeeBean.employee.editable}" value="1" validator="#{employeeValidator.valAttachments}"> <xp:this.required><![CDATA[#{javascript:return submittedBy("btnSendToHR")}]]></xp:this.required> <xp:this.validators> <xp:validateRequired message="No CV added"> </xp:validateRequired> </xp:this.validators></xp:inputText>验证器非常基础,看起来有点如下:public void valAttachments(FacesContext facesContext, UIComponent component, Object value) { // my business logic here String msg = null; msg = "//collecting string from properties file"; FacesMessage message = new FacesMessage(msg); throw new ValidatorException(message); }现在我试图让我的验证器以触发提交的按钮为条件 (submittedBy("btnSendToHR"))(我在这篇博客文章中找到了灵感http://dontpanic82.blogspot.com/2010/03/xpages-制作验证行为.html):<xp:this.validator><![CDATA[#{javascript://emploteeValidator.valAttachmentsif (true == submittedBy("btnSendToHR")){ importPackage(se.bank.app.test); var mv = new se.bank.app.test.EmployeeValidator(); mv.valAttachments(facesContext, getComponent("cv"),"0" );}}]]></xp:this.validator>我看到该方法被调用(例如,当我在方法中包含 System.out.println() 时)。一个例子:执行 JavaScript 动作表达式时出错脚本解释器错误,行 = 5,列 = 12:调用方法时出错来自 valAttachments 的 Java 类“se.bank.app.test.EmployeeValidator”上的“valAttachments(com.ibm.xsp.domino.context.DominoFacesContext, com.ibm.xsp.component.xp.XspInputText, string)”:测试验证 cv , 提交值=0有人可以解释我如何根据提交 Id(一个按钮)制作验证器?
2 回答
繁星淼淼
TA贡献1775条经验 获得超11个赞
也许你正在尝试比你需要的更复杂的东西。验证器已经可以访问触发验证的组件。SeeUIComponent component
是参数之一。那可能是 xp:eventHandler 但从getParent()
那里向上导航。这可能会让您获得所需的一切。
如果要避免在验证器中编码,请this.getParent()
在 eventHandler 的 SSJS 中获取组件。例如,您可以传递一个参数以根据 ID 设置有效。
添加回答
举报
0/150
提交
取消