File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Struts and javascript  problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts and javascript  problem" Watch "Struts and javascript  problem" New topic

Struts and javascript problem

Krishna Mohan V

Joined: Mar 16, 2004
Posts: 20

I am developing a web application using tomcat 5.0.30 , struts and backend as iBatis framework.
Becuase of being JSTL as new to me , I went for javascript.
In the main form, I have two fields for Username and Password.

Because I am not using validations using struts, in my struts-config.xml,I have set validate="false", line beginning with input was removed.

I have written javscript, which is taking care of these validations.

The problem is , if I enter a value for username, not for password,
javascript is displaying "Password is mandatory", but when I click "OK" button,

username and password are showing blank.

The requirement is it should retain the value entered by me in username field.

Can any of you help me please?

Although this may look simple, but in my next screens , I have nearly 25 Textboxes and I dont want all these field values being set to blank, if a alert message comes up.

Thanks in advance,
Junilu Lacar

Joined: Feb 26, 2001
Posts: 6529

Please post your JavaScript code so we can have a better idea of what's happening. Also, JavaScript validation should be used as a front-line defense only. You have no control over the client browsers and they could easily have JavaScript turned off. Don't rely on the JavaScript validation; you should also validate on the server-side to ensure that the data processed is valid.

Junilu - [How to Ask Questions] [How to Answer Questions]
Sham Grandhe
Ranch Hand

Joined: Dec 16, 2003
Posts: 73
Hi Krishna Mohan,
I think the problem is simple, even if the form is being validated by javascript, the data will move to the ActionForm bean, hence try with the request parameter method. hope this could help you.

<html:text property="username" value="<%= request.getParameter("username")==null?"":request.getParameter("username")%>" />

I agree. Here's the link:
subject: Struts and javascript problem
It's not a secret anymore!