如何在wicket java中为dropdownchoice和checkbox添加验证

lxkprmvk  于 2021-07-06  发布在  Java
关注(0)|答案(1)|浏览(452)

我有一个复选框和下拉列表在一个html页面。单击submit(提交)时,如果同时选中了这两个字段,则会显示一条错误消息,其中任何一个字段都应为必填字段,并要求至少选择一个值。
我创建了一个新类作为formvalidator实现ivalidator并重写validate方法。但我不知道如何使用下拉选择值和复选框值提交方法调用广告如何显示在html中。
java代码-

IModel<Project> dropdownModel =   new PropertyModel<Project>(criteria,"selectedBillableProject");
        DropDownChoice<Project> billableProjectsList = new DropDownChoice<>(
                "projectsList",
                dropdownModel,
                billableProjects,
                new ChoiceRenderer<Project>("fullNameWithCustomer"));
        billableProjectsList.setLabel(new ResourceModel("printMonth.billable"));

        form.add(billableProjectsList);

}

protected void onSubmit() {
           .....
            validateInputComponents(reportCriteria);
.....
}

public void validateInputComponents(ReportCriteria reportCriteria){

          add(new FormComponentValidator(reportCriteria.getSelectedBillableProject(), unbillableProjectsView.getModelObject()));      

        }

我已将FormComponentValidTo更新为类似于:https://cwiki.apache.org/confluence/display/wicket/validating+related+fields
但它会导致以下错误onsubmit()。11-26@22:37:25 error org.apache.wicket.request.cycle.requestcycle-处理错误消息java.lang.illegalstateexception:stream at org.eclipse.jetty.server.response.getwriter(response)时出错。java:693)在javax.servlet.servletresponsewrapper.getwriter(servletresponsewrapper。java:152)在servlet.servletresponsewrapper.getwriter(servletresponsewrapper。java:152)位于org.springframework.security.web.context.savecontextonupdateorerrorresponsewrapper.getwriter(savecontextonupdateorerrorresponsewrapper。java:125)在org.apache.wicket.protocol.http.servlet.servletwebresponse.write(servletwebresponse。java:109)在org.apache.wicket.protocol.http.headerbufferingwebresponse.write(headerbufferingwebresponse。java:179)在org.apache.wicket.protocol.http.bufferedwebresponse$writecharsequenceaction.invoke(bufferedwebresponse)中。java:171)在org.apache.wicket.protocol.http.bufferedwebresponse.writeto(bufferedwebresponse。java:602)在org.apache.wicket.request.handler.render.webageender.respond(webageender。java:232)在org.apache.wicket.core.request.handler.renderPagerRequestHandler.respond(renderPagerRequestHandler。java:175)在org.apache.wicket.request.cycle.requestcycle$handlerexecutor.respond(requestcycle。java:890)在org.apache.wicket.request.requesthandlerstack.execute(requesthandlerstack。java:64)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(requestcycle。java:310)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(requestcycle。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(请求周期。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(requestcycle。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(requestcycle。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(请求周期。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(requestcycle。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(requestcycle。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(请求周期。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(requestcycle。java:319)在org.apache.wicket.request.cycle.requestcycle.executeexceptionrequesthandler(requestcycle。java:319)在org.apache.wicket.request.cycle.requestcycle.processrequest(请求周期。java:233)在org.apache.wicket.request.cycle.requestcycle.processrequestanddetach(requestcycle。java:289)在org.apache.wicket.protocol.http.wicketfilter.processrequestcycle(wicketfilter。java:259)在org.apache.wicket.protocol.http.wicketfilter.processrequest(wicketfilter。java:201)在org.apache.wicket.protocol.http.wicketfilter.dofilter(wicketfilter。java:282)位于org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler。java:1484)在org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy。java:330)位于org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter)。java:87)在org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy。java:342)在org.springframework.security.web.filterchainproxy.dofilternternal(filterchainproxy。java:192)在org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy。java:160)在org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy。java:346)在org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy。java:262)位于org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler。java:1484)位于org.springframework.orm.hibernate4.support.opensessioninviewfilter.dofilternternal(opensessioninviewfilter)。java:151)在org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter。java:107)位于org.eclipse.jetty.servlet.servlethandler$cachedchain.dofilter(servlethandler。java:1476)位于org.eclipse.jetty.servlet.servlethandler.dohandle(servlethandler。java:501)在org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler。java:137)在org.eclipse.jetty.security.securityhandler.handle(securityhandler。java:557)位于org.eclipse.jetty.server.session.sessionhandler.dohandle(sessionhandler。java:231)在org.eclipse.jetty.server.handler.contexthandler.dohandle(contexthandler。java:1086)位于org.eclipse.jetty.servlet.servlethandler.doscope(servlethandler。java:429)在org.eclipse.jetty.server.session.sessionhandler.doscope(sessionhandler。java:193)在org.eclipse.jetty.server.handler.contexthandler.doscope(contexthandler。java:1020)在org.eclipse.jetty.server.handler.scopedhandler.handle(scopedhandler。java:135)在org.eclipse.jetty.server.handler.contexthandlercollection.handle(contexthandlercollection。java:255) 在org.eclipse.jetty.server.handler.handlercollection.handle(handlercollection。java:154)位于org.eclipse.jetty.server.handler.handlerwrapper.handle(handlerwrapper)。java:116)在org.eclipse.jetty.server.server.handle(server。java:370)位于org.eclipse.jetty.server.abstracthttpconnection.handlerequest(abstracthttpconnection)。java:494)在org.eclipse.jetty.server.abstracthttpconnection.content(abstracthttpconnection)。java:982)位于org.eclipse.jetty.server.abstracthttpconnection$requesthandler.content(abstracthttpconnection)。java:1043)在org.eclipse.jetty.http.httpparser.parsenext(httpparser。java:865)在org.eclipse.jetty.http.httpparser.parseavailable(httpparser。java:240)在org.eclipse.jetty.server.asynchttpconnection.handle(asynchttpconnection)。java:82)在org.eclipse.jetty.io.nio.selectchannelendpoint.handle(selectchannelendpoint。java:696)在org.eclipse.jetty.io.nio.selectchannelendpoint$1.run(selectchannelendpoint.org.eclipse.jetty.io.nio.selectchannelendpoint$1.run)。java:53)在org.eclipse.jetty.util.thread.queuedthreadpool.runjob(queuedthreadpool。java:608)在org.eclipse.jetty.util.thread.queuedthreadpool$3.run(queuedthreadpool。java:543)在java.lang.thread.run(线程。java:748)
我错过了什么吗。请帮忙

cld4siwp

cld4siwp1#

您的表单中似乎缺少用于显示验证错误/消息的反馈面板。请参阅此处的用户指南,并遵循整个示例:
https://ci.apache.org/projects/wicket/guide/8.x/single.html#_form_validation_and_feedback_messages

相关问题