JSF Validations

Hi All,

I am just started learning JSF [ 3 days old in JSF]. i was trying to do validation,it was giving me the follwing error.

Conversion Error setting value '' for 'null Converter'.

My JSP Code

-

<h:message for="inputText1" styleClass="warning"/>

<h:inputText id="inputText1" value="#{backing_login.inputText1}"

validator="#{backing_login.validateFields}" required="true"/>

BackingBean Code

public String validateFields(FacesContext context,UIComponent toValidate,Object value)

{

String val1 = (String) value;

System.out.println("inside Validate Fields");

if (val1.equalsIgnoreCase("") || val1.length() ==0)

{

((UIInput)toValidate).setValid(false);

FacesMessage message = new FacesMessage();

// message.setDetail("Some Required fields are Blank..");

context.addMessage(toValidate.getClientId(context), message);

}

return "error";

}

Can any one please help me on this.

Thanks in Advance.

Arthi

[1062 byte] By [Arthi.Konditia] at [2007-11-27 11:36:44]
# 1

What's the signature of the property behind #{backing_login.inputText1} ?

By the way, conditionally comparing with an empty string (which has a length of 0) *and* comparing the length with zero in one if-statement is fairly meaningless. They both will yield the same booleanvalue as result. Do the one or the other. Getting the length is faster than comparing with an empty string. You may also add trim() to trim whitespace from the string before getting the length.

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

Take a look at Lilya Jsf Widgets and Ajax Capabilities.

There is some Form validation examples.

Validation is very easy to implement.

http://qlogic.ma/lilya

Message was edited by:

loukiliScreen

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

Thanks for the reply.

In the Backing bean i defined inputText1 as

private HtmlInputText inputText1;

Arthi.Konditia at 2007-7-29 17:10:33 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> Thanks for the reply.

>

> In the Backing bean i defined inputText1 as

>

> private HtmlInputText inputText1;

If you want to bind the component with the backing bean, use the 'binding' attribute.

If you want to bind the value with the backing bean, use the 'value' attribute and a proper object type to store the value in. E.g. String or any Number. If you want to use a specific object type, then you have to create/supply/specify a converter for that.

So you have 3 options:

1) replace value="#{myBean.inputText1}" by binding="#{myBean.inputText1}"

or

2) replace HtmlInputText type by String type (for example).

or

3) supply a converter which converts between HtmlInputText and String (fairly meaningless option indeed, but it works)

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