Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

struts how do clear the html fields after inserting data.

Posted on 2006-06-02
5
Medium Priority
?
3,074 Views
Last Modified: 2011-09-20
I have a simple struts applications. when I submit the form it inserts into the table and go back to the input screen. I want the html fields to be cleared. They still contain the values that i entered.

I tried using reset() method in the form but no luck.

Thanks in advance.
0
Comment
Question by:muthiahmerchant
5 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 16819942
The reset method should work
0
 
LVL 1

Author Comment

by:muthiahmerchant
ID: 16819992
In my formbean this is what i have

public void reset(ActionMapping mapping, HttpServletRequest request){
        firstName = "";
        lastName = "";
}

in my .jsp page
 <td><html:text property="firstName" styleClass="field"/></td>
 <td><html:text property="lastName" styleClass="field"/></td>

is there anything else that needs to be done, cause reset is not working for me.

0
 
LVL 1

Author Comment

by:muthiahmerchant
ID: 16820444
I put a bunch of log messages and was able to figure this much.

the reset method is called in the begining before the page is loaded, but after I submit the form and mapping.getInputForward() is called it does not call the reset method, the form bean still has the values that it got from the form and hence it does not get cleared.

my customerformaction has the following

Customer customer = new Customer();
cFormBean.setCustomerId(customer.insertCustomer(customerDTO)) ;
return mapping.getInputForward();

Thanks
0
 
LVL 3

Accepted Solution

by:
runa_paathak earned 1000 total points
ID: 16822242
If you want the HTML fields to be cleared when the page is rendered again, you must set the fields in your form to null or "" in your Action once you are done using the field values.

Do this:

Customer customer = new Customer();
customer.insertCustomer(customerDTO) ;
cFormBean.setCustomerId(<null or "");
return mapping.getInputForward();
0
 
LVL 10

Expert Comment

by:radarsh
ID: 16828345
Hi muthiahmerchant,

If you don't have to keep the values of the input fields in case of validation errors,
you can simply set the scope of your formbean to request in the action tag in struts-config.xml.

Or else, follow runa_paathak's solution.

________
radarsh
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question