Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Struts and javascript problem

Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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,
Posts: 15733
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 was her plaything! And so was this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic