Jsf使用自定义验证器

时间:2018-04-25 13:40:24

标签: jsf

我想验证以下datatable.which显示网址集的每个内容。

<h:form id="dfCompose" styleClass="form-horizontal">
    <h:dataTable styleClass="attachPanel" id="attmsg" width="100%" value="#{ForumTool.attachments}" >

        .....................
        ........................

        <f:validator validatorId="forumAndTopicUrlContentValidator" /> 
        <f:attribute name="validationItemLabel" value="#{msgs.cdfm_att}" /> 

    <h:dataTable/>

<h:form/>

我编写了一个自定义验证器来验证jsf数据表内容。 import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

    public class ForumAndTopicUrlContentValidator implements Validator{

        private static final String MESSAGECENTER_BUNDLE = "org.sakaiproject.api.app.messagecenter.bundle.Messages";

        @Override
        public void validate(FacesContext arg0, UIComponent arg1, Object arg2)
                throws ValidatorException {

            List inputValue = (List) arg2;

        }

    }

但是当带有数据表的页面加载时

失败并出现以下运行时异常

  

堆栈跟踪:       at org.sakaiproject.portal.charon.SkinnableCharonPortal.forwardTool(SkinnableCharonPortal.java:1508)   由以下原因引起:org.apache.jasper.JasperException:发生异常   在第157行处理JSP页面/jsp/dfCompose.jsp

     

154:155:
  156:157:
   158:                                  159:160:

     

堆栈跟踪:       在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)   由:java.lang.ClassCastException引起:   javax.faces.component.html.HtmlDataTable无法强制转换为   javax.faces.component.EditableValueHolder       在javax.faces.webapp.ValidatorTag.doStartTag(ValidatorTag.java:130)       at org.apache.jsp.jsp.dfCompose_jsp._jspx_meth_f_005fvalidator_005f2(dfCompose_jsp.java:1627)       at org.apache.jsp.jsp.dfCompose_jsp._jspx_meth_h_005fdataTable_005f0(dfCompose_jsp.java:1100)       在org.apache.jsp.jsp.dfCompose_jsp._jspService(dfCompose_jsp.java:379)       在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)       在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)       在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)       在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:727)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)       在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)       在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)       在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)       在org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:748)       at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:486)       在org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:411)       在org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338

如何通过自定义验证器验证jsf数据表内容?

0 个答案:

没有答案