JSF 自定义一个component的时候 如果
你想为这个component加上自定义的验证机制
需要怎么做?下面是我做一个关于登陆组件的时候遇到的问题
LoginComponentTag为组件标签库
UILoginComponent为组件定义
LoginRender为组件编码解码
LoginValidator为自定义登陆验证器当我使用LoginRender为组件编码时,
写了以下代码形成一个表单,用于提交:
public void encodeBegin(FacesContext arg0, UIComponent arg1)
            throws IOException {
        super.encodeBegin(arg0, arg1);
        ResponseWriter out=null;
        out=arg0.getResponseWriter();
        String id=arg1.getClientId(arg0);
        out.write("<table>");
        out.write("<form method=post action='login.faces'>");
        out.write("<tr>");
        encodeText(arg1,out,id,"txt_user_value");//写一个文本框
        encodeTextField(arg1,out,id,"");//写一个输入框
        out.write("</tr>");
        out.write("<tr>");
        encodeText(arg1,out,id,"txt_pwd_value");//写一个文本框
        encodePwdField(arg1,out,id,"");//写一个密码输入框
        out.write("</tr>");
        out.write("<tr>");
        encodeCommand(arg1,out,id,"cmd_submit_value","submit");//提交按钮
        encodeCommand(arg1,out,id,"cmd_reset_value","reset");//重置按钮
        out.write("</tr>");
        out.write("</form>");
        out.write("</table>");
        
    }形成的html代码为
<table>
<form method=post action='login.faces'>
<tr>
<td>username:</td>
<td><input type="text" size="10" value="" />
</td>
</tr>
<tr>
<td>password:</td>
<td><input type="password" size="10" value="" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</form>
</table>当提交后返回的是原login.jsp也没有答应验证的错误信息
也就是没能执行验证步骤:
我的验证代码写在UILoginComponent 的 processValidators 方法下面
当使用JSF提供的标签生成的html代码基本相同
但是,它可以执行验证,可以执行到应用程序的业务逻辑等地方
生成的html代码如下(只用了一个按钮)<form id="_id2" method="post" action="/TelCart/login.faces" enctype="application/x-www-form-urlencoded">
<input type="submit" name="_id2:_id3" value="login" />
<input type="hidden" name="_id2" value="_id2" />
</form>这个action 可以执行到应用程序所写的逻辑 action="#{login.validator}"
以下为原JSP代码:
<f:view>

<h:messages></h:messages>
<h:form>
<h:commandButton action="#{login.validator}" value="login" ></h:commandButton>
</h:form>
<h:messages></h:messages>
</f:view>为什么自定义的标签不行,怎么样才能达到JSF标签的这个效果
请高手指点一二,介绍几本JSF的相关这方面的书籍也好!