Displaying Error Messages in JSF

Hi all,

Im new to JSF. I am not able to display the errors i got in the BackEnd bean

i added the errors in the bean like

public String validate(){

if(userName.equals(password))

return"success";

FacesContext context = FacesContext.getCurrentInstance();

context.addMessage("loginError",new FacesMessage("LoginError","UserName Password Doesnt Match"));

return"failure";

}

is there any mistake in the code?

and

in the JSP i used

<h:message id="loginError" errorClass="loginError" for="loginError" style="color: red" showSummary="true" showDetail="true"/>

how to show the errors?

please can any one help me?

waiting for reply

thanx in advance....

By

Thirupathi B

[1279 byte] By [b.thirupathi.reddya] at [2007-11-26 13:17:30]
# 1
if you put <h:messages/> in the JSP page, it will show ALL the messages, I think.Here's the link to the API for it: http://java.sun.com/javaee/javaserverfaces/1.2_MR1/docs/tlddocs/index.htmlMessage was edited by: Illu
Illua at 2007-7-7 17:41:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

JSF<h:form id="formId">

...

<h:message for="formId" ... />

</h:form>

MyBeancontext.addMessage("formId" ...

or:

JSF<h:form id="formId">

<h:inputText id="username" ... />

...

<h:message for="username" ... />

</h:form>

MyBeancontext.addMessage("formId:username" ...

BalusCa at 2007-7-7 17:41:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Or you can make a custom validator for a field and throw ValidatorException. Thats also a way to show error messages for a specified field.

.....

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

...

FacesMessage message = new FacesMessage();

message.setDetail("value not valid");

message.setSummary("value not valid");

message.setSeverity(FacesMessage.SEVERITY_ERROR);

throw new ValidatorException(message);

}

basti78a at 2007-7-7 17:41:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...