Click to See Complete Forum and Search --> : jsf default required field validation message seems funny?


sirpelidor
06-03-2009, 03:41 AM
hi, i have a following tags in my jsf page wrapped in a <h:form> tag:


<h:outputText value="#{msg.username}" />
<h:inputText id="txt_username" value="#{loginBean.username}" required="#{true}"/>
<h:outputText value="#{msg.password}" />
<h:inputSecret id="txt_pwd" value="#{loginBean.password}" required="#{true}" />
<h:commandButton id="cmd_login" value="#{msg.login}" action="#{loginBean.action}"></h:commandButton>
<h:messages layout="list"></h:messages>


when i purposely -not- to enter any value and hit the login button, i get the following error message on my page:


j_id_jsp_1302903026_1:txt_username: Validation Error: Value is required.
j_id_jsp_1302903026_1:txt_pwd: Validation Error: Value is required.



where's that extract "j_id_jsp_1302903026_1" come from and how to take it away from the page?

thank you

chazzy
06-03-2009, 08:21 PM
those are the real id's of the components that are generated. you'll see them in the rendered HTML file.

how are you doing the validations?

sirpelidor
06-04-2009, 04:06 AM
hi chazzy,

i'm very new to jsf (and jsp) and i haven't done any validation yet. i thought by setting require=true will auto validate the field for me (coming from .net background perspective).

do i have to write my own validation for required field?

thanks!

chazzy
06-04-2009, 07:56 AM
ok, then let's back up a bit. which jsf implementation are you using?

sirpelidor
06-04-2009, 03:46 PM
hum... i don't believe i'm using any implementation at the moment

(the truth is, i don't even know which implementation to choose from, the number of web frameworks and implementations available in java cause quite a bit of confusion for beginner).

all i have right now is jsf-impl.jar and jsf-api.jar from mojarra-1.2.12.

I also have jsf-facelets.jar and el-api.jar in my classpath, but i doubt its doing anything since I can't see any additional tags from eclipse.

this sure is a learning curve for me, but i've been picking up new knowledge everyday :)

chazzy
06-04-2009, 06:15 PM
ah

basically, those are the rendered id fields. different implementations work different (e.g. richfaces/icefaces have nonstandard control over it, but then you end up working w/ that jsf implementation only).

i think this might help you figure out how to replace those messages.

http://www.netbeans.org/kb/articles/jAstrologer-validate.html

(for the record, you get the j_id_jsp_1302903026_1 because you're using jsp's and you're using global messages. if you used local messages for each component, you'll only get the txt_name part).

sirpelidor
06-04-2009, 08:47 PM
that link does the trick, thank you chazzy :)