I use JSF 2.0, hibernate-validator4.2.jar validation-api.jar tomcat and Eclipse.
我使用了JSF 2.0、hibernate-validator4.2。jar验证api。jar tomcat和Eclipse。
I put @Size(min=3, message="xxx")
annotation in a @ManagedBean and <f:validateBean />
between <h:inputText value="#{user.name}"></h:inputText>
我在@ManagedBean和
When I try to run the project i get this error...
当我试图运行这个项目时,我得到了这个错误……
exception
javax.servlet.ServletException: Expression Error: Named Object: javax.faces.Bean not found.
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
root cause
javax.faces.FacesException: Expression Error: Named Object: javax.faces.Bean not found.
com.sun.faces.application.ApplicationImpl.createValidator(ApplicationImpl.java:1593)
com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl.createValidator(ValidatorTagHandlerDelegateImpl.java:244)
com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl.applyAttachedObject(ValidatorTagHandlerDelegateImpl.java:132)
com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl.applyNested(ValidatorTagHandlerDelegateImpl.java:211)
com.sun.faces.facelets.tag.jsf.ValidatorTagHandlerDelegateImpl.apply(ValidatorTagHandlerDelegateImpl.java:87)
javax.faces.view.facelets.DelegatingMetaTagHandler.apply(DelegatingMetaTagHandler.java:120)
javax.faces.view.facelets.DelegatingMetaTagHandler.applyNextHandler(DelegatingMetaTagHandler.java:137)
why? (this only appears when i put tag)
为什么?(这只在我加标签时出现)
User.java
User.java
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.validation.constraints.Size;
@ManagedBean(name="user")
@SessionScoped
public class User{
@Size(min=3, message="At least 3 characters!")
private String name;
public String getName() {
return nume;
}
public void setName(String name){
this.name=name;
}
}
adduser.xhtml
adduser.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="/templates/master_layout.xhtml">
<ui:define name="text_header" >Panou de control: Adauga user </ui:define>
<ui:define name="content">
<h:panelGrid columns="3">
<h:outputText value="Name"></h:outputText>
<h:inputText value="#{user.name}">
<f:validateBean />
</h:inputText>
<h:commandButton value="Inregistreaza" action="index.xhtml"></h:commandButton>
</h:panelGrid>
</ui:define>
</ui:composition>
</html>
1 个解决方案
#1
5
It should work perfectly fine, although the empty <f:validateBean/>
tag is entirely superfluous in this context. It's supposed to be used to "finetune" validation more, such as grouping of validation and/or disabling the implicit bean validation on a per-input basis by specifying the desired tag attributes. You have however no attributes on that tag, so just remove that tag altogether. On a default JSF 2 + JSR 303 project setup, it's supposed to kick in fully transparently without adding more JSF tags whenever there's a JSR 303 annotation on the property such as @Size
and likes.
虽然空
But I don't think that removing the tag will solve this particular exception. Your problem lies thus deeper. This validator is supposed to be auto-registered on startup. However, the exception basically tells that the validator is not registered at all. With the information given so far, it's not possible to give a targeted answer. I can think of the following possible causes:
但是我不认为移除标签会解决这个特殊的异常。因此,你的问题更深层。这个验证器应该在启动时自动注册。但是,这个异常基本上告诉验证器根本没有注册。根据目前给出的信息,不可能给出一个有针对性的答案。我可以想到以下可能的原因:
- There's a bug in the JSF implementation which you're using. Upgrade it to a newer version.
- 您正在使用的JSF实现中有一个错误。升级到更新的版本。
- You have multiple JSF libraries of different versions in your classpath. Cleanup it.
- 在类路径中有多个不同版本的JSF库。清理它。
- The
faces-config.xml
root declaration is not declared conform JSF 2.x. Fix it. - faces-config。xml根声明没有声明遵循JSF 2.x。解决它。
#1
5
It should work perfectly fine, although the empty <f:validateBean/>
tag is entirely superfluous in this context. It's supposed to be used to "finetune" validation more, such as grouping of validation and/or disabling the implicit bean validation on a per-input basis by specifying the desired tag attributes. You have however no attributes on that tag, so just remove that tag altogether. On a default JSF 2 + JSR 303 project setup, it's supposed to kick in fully transparently without adding more JSF tags whenever there's a JSR 303 annotation on the property such as @Size
and likes.
虽然空
But I don't think that removing the tag will solve this particular exception. Your problem lies thus deeper. This validator is supposed to be auto-registered on startup. However, the exception basically tells that the validator is not registered at all. With the information given so far, it's not possible to give a targeted answer. I can think of the following possible causes:
但是我不认为移除标签会解决这个特殊的异常。因此,你的问题更深层。这个验证器应该在启动时自动注册。但是,这个异常基本上告诉验证器根本没有注册。根据目前给出的信息,不可能给出一个有针对性的答案。我可以想到以下可能的原因:
- There's a bug in the JSF implementation which you're using. Upgrade it to a newer version.
- 您正在使用的JSF实现中有一个错误。升级到更新的版本。
- You have multiple JSF libraries of different versions in your classpath. Cleanup it.
- 在类路径中有多个不同版本的JSF库。清理它。
- The
faces-config.xml
root declaration is not declared conform JSF 2.x. Fix it. - faces-config。xml根声明没有声明遵循JSF 2.x。解决它。