aspose file tools*
The moose likes Struts and the fly likes how should i remove the error message for the required text field once i move to another text field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how should i remove the error message for the required text field once i move to another text field " Watch "how should i remove the error message for the required text field once i move to another text field " New topic
Author

how should i remove the error message for the required text field once i move to another text field

Jyothi Sree
Ranch Hand

Joined: Jun 14, 2010
Posts: 41
Hi

I have a jsp form in a struts2 application , which has few strtus2 tag text fields and a submit button .
When i hit the submit button with out enterning the values in the textfields i get a error messages for the required fields saying that the " value is required "

validation is not a problem .. but once i enter the value in the textbox and move to the next textbox ,first fields error msg should disappear , i know this has to be done using ajax but how should i do that ?

Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please TellTheDetails.

Are you using Ajax validation? If you're not, then dynamically modifying the DOM to remove static error messages has nothing to do with Ajax. If you are, the simplest solution might just be to re-submit the form for validation.

Are you using client-side validation? If you're not, then this is more trouble than it's worth. If you are, then perhaps just setting up some onblur handlers and re-calling the validation would be the easiest way.
Jyothi Sree
Ranch Hand

Joined: Jun 14, 2010
Posts: 41
I am validating my Form Fields using the <actionclassname>-validation.xml which calls by itself when i submit the form .I dont think this is an ajax validation.

This is my Form

<body>
<s:fielderror />
<s:actionmessage/>
<hr>

<s:form action="contactus.action" method="post" name="ContactUs Form" >

<s:textfield id="fn" name="cust.fname" key="fname" size="25" maxlength="20" required="true" />
<s:textfield name="cust.lname" key="lname" size="25" maxlength="20" required="true" />
<s:textfield name="cust.title" key="title" size="25" maxlength="20" required="true"/>
<s:textfield name="cust.company" key="company" size="25" maxlength="50" required="true" />

<s:submit value="submit" align="center" method="addContact" />
</s:form>
</body>


With ContactUsAction-validation.xml as validation

Can You be more specific with the answer .

Thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

If you're not using Ajax or client-side validation in the first place then I don't really think this is a reasonable requirement, because the field hasn't been re-validated yet. That aside, use an onblur to clear the associated error message; I think it's in a span. I'm not sure what the current state of the generated HTML is; you might have to resort to some minor DOM traversal to find it unless you extend a theme to produce more semantic markup.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Cross Post...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Jyothi: Please BeForthrightWhenCrossPostingToOtherSites; if in had known the question was already answered I wouldn't have spent as much time answering it again.
Jyothi Sree
Ranch Hand

Joined: Jun 14, 2010
Posts: 41
I understand but i still did not get the answer ..
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What part don't you understand?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how should i remove the error message for the required text field once i move to another text field