Re: Reset button does not clear JSP fields

2004-11-29 Thread aris
Instead of a reset you could use a simple button and the related onClick
event to call a javascript that sets all field to .
What do you think about this workaround?
Take note that it isn't an expected behaviour for a reset button. I suggest
you to name such a button with a value different from reset. What do you
think about wipe or erase?
Bye,
aris.

- Original Message - 
From: O. Oke [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, November 29, 2004 3:01 PM
Subject: Reset button does not clear JSP fields


 Please help!

 Background
 ==
 I retrieve data from the database, copy the data into
 an Action Form, the data is then automatically entered
 into corresponding fields.


 After viewing the data, I want the RESET button to
 empty all fields whenever it is clicked.  Presently,
 after clicking the RESET button, all fields still have
 data.  I believe the fields are repopulated with the
 data in the Action Form.

 Does the RESET button have to forward to an Action
 class that in turn replaces the relevant Action Form
 in the relevant scope with an Action Form that has no
 data? If not, can you please tell me the conventional
 Struts way of setting all JSP fields to empty.

 Note:  In the reset method of the Action form, I set
 all fields to  .

 Thank you.

 O. Oke



 ___
 Moving house? Beach bar in Thailand? New Wardrobe? Win £10k with Yahoo!
Mail to make your dream a reality.
 Get Yahoo! Mail www.yahoo.co.uk/10k

 -
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Reset button does not clear JSP fields

2004-11-29 Thread Pilgrim, Peter

 -Original Message-
 From: aris [mailto:[EMAIL PROTECTED]
 
 
 Instead of a reset you could use a simple button and the 
 related onClick
 event to call a javascript that sets all field to .
 What do you think about this workaround?
 Take note that it isn't an expected behaviour for a reset 
 button. I suggest
 you to name such a button with a value different from 
 reset. What do you
 think about wipe or erase?
 Bye,
 aris.
 
 - Original Message - 
 From: O. Oke [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, November 29, 2004 3:01 PM
 Subject: Reset button does not clear JSP fields
 
 
  Please help!
 
  Background
  ==
  I retrieve data from the database, copy the data into
  an Action Form, the data is then automatically entered
  into corresponding fields.
 
 
  After viewing the data, I want the RESET button to
  empty all fields whenever it is clicked.  Presently,
  after clicking the RESET button, all fields still have
  data.  I believe the fields are repopulated with the
  data in the Action Form.
 
  Does the RESET button have to forward to an Action
  class that in turn replaces the relevant Action Form
  in the relevant scope with an Action Form that has no
  data? If not, can you please tell me the conventional
  Struts way of setting all JSP fields to empty.
 

There is no conventional method. I recommend that you 
avoid html:cancel because it is slightly confusing.

The way I did is, is assume that RESET or REVERT button
is just same behaviour to a SUBMIT button in terms of Struts

See below

  Note:  In the reset method of the Action form, I set
  all fields to  .
 
  Thank you.
 
  O. Oke


====

What kind of reset functionality do you need ?

1. Reset as in Clear

Clear all the input fields in a HTML Form to be blank.

2. Reset as in Revert

Change all the input fields back to their original values,
before the user edited the form.


With (1) you can write a function with JavaScript to navigate
your around the DOM for your HTML Form element. You can
make an Struts Action that clears the ActionForm for you
(the so-called going back to the server option).

With (2) you can program it with JavaScript, quick tricky
to do but not impossible. It is much easier to do this
inside server side Java. You will need to make the ActionForm
session scope. It will have to have to duplicate beans or
delegated beans inside, but if you know Commons BeanUtils
you can copy the value of one bean to another easily.

I would use delegated beans for this to implement (2) revert

class EmployeePayrollBean { ... }

class SomeDahForm extends ActionForm {

EmployeePayrollBean payroll = ... ;
EmployeePayrollBean payroll_backup = ... ;

// assume getter/setter methods exists
}

In the Action itself  

class SomeTypeOfAction extends Action {

public void execute( ... ) {

if ( button.equals(REVERT) {

BeanUtils.copyProperties( 
yourform.getPayroll(), 
yourform.getPayrollBackup() );
// forward request back to JSP/view
}
}
}

Because of the nested properties in Struts/Commons BeanUtils/JSTL the
above shouldn't be a problem for creating a JSP.

It is trivial to take the Common BeanUtils API to write a ``GenericBean''
resetter that will reset all properties of a POJO to 
either  0, 0.0F, 0.0,  , null 
(but be very careful list Java Collections!!!)

HTH

--
Peter Pilgrim
Operations/IT - Credit Suisse First Boston, 
10 South Colonnade, London E14 4QJ, United Kingdom
Tel: +44-(0)207-883-4497


==
This message is for the sole use of the intended recipient. If you received
this message in error please delete it and notify us. If this message was
misdirected, CSFB does not waive any confidentiality or privilege. CSFB
retains and monitors electronic communications sent through its network.
Instructions transmitted over this system are not binding on CSFB until they
are confirmed by us. Message transmission is not guaranteed to be secure.
==


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Reset button does not clear JSP fields

2004-11-29 Thread fzlists
I'm not sure how tricky it is in JavaScript...

function doit(obj) {
  obj = obj.form;
  i = 0;
  while (obj.elements[i] != null) {
if (obj.elements[i].type.toLowerCase() != button) {
  obj.elements[i].value = ;
}
i++;
  }
}

Attach this to the onClick event of a button in the form you want to clear, 
passing this as the argument, and that should do the trick.  You might have 
to tweak it a little bit (for instance, I'm not sure it will clear file type 
input fields, checkboxes or radios), but it's probably close.  Depends on your 
requirements and whether the round-trip to the server is acceptable or not.  I 
tend to want to avoid any server trips I can, and something like this seems 
like a purely GUI function, so strikes me as a place whether the server doesn't 
need to be involved.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com

On Mon, November 29, 2004 11:25 am, Pilgrim, Peter said:
 
 -Original Message-
 From: aris [mailto:[EMAIL PROTECTED]


 Instead of a reset you could use a simple button and the
 related onClick
 event to call a javascript that sets all field to .
 What do you think about this workaround?
 Take note that it isn't an expected behaviour for a reset
 button. I suggest
 you to name such a button with a value different from
 reset. What do you
 think about wipe or erase?
 Bye,
 aris.

 - Original Message -
 From: O. Oke [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, November 29, 2004 3:01 PM
 Subject: Reset button does not clear JSP fields


  Please help!
 
  Background
  ==
  I retrieve data from the database, copy the data into
  an Action Form, the data is then automatically entered
  into corresponding fields.
 
 
  After viewing the data, I want the RESET button to
  empty all fields whenever it is clicked.  Presently,
  after clicking the RESET button, all fields still have
  data.  I believe the fields are repopulated with the
  data in the Action Form.
 
  Does the RESET button have to forward to an Action
  class that in turn replaces the relevant Action Form
  in the relevant scope with an Action Form that has no
  data? If not, can you please tell me the conventional
  Struts way of setting all JSP fields to empty.
 
 
 There is no conventional method. I recommend that you
 avoid html:cancel because it is slightly confusing.
 
 The way I did is, is assume that RESET or REVERT button
 is just same behaviour to a SUBMIT button in terms of Struts
 
 See below
 
  Note:  In the reset method of the Action form, I set
  all fields to  .
 
  Thank you.
 
  O. Oke
 
 
 ====
 
 What kind of reset functionality do you need ?
 
 1. Reset as in Clear
 
 Clear all the input fields in a HTML Form to be blank.
 
 2. Reset as in Revert
 
 Change all the input fields back to their original values,
 before the user edited the form.
 
 
 With (1) you can write a function with JavaScript to navigate
 your around the DOM for your HTML Form element. You can
 make an Struts Action that clears the ActionForm for you
 (the so-called going back to the server option).
 
 With (2) you can program it with JavaScript, quick tricky
 to do but not impossible. It is much easier to do this
 inside server side Java. You will need to make the ActionForm
 session scope. It will have to have to duplicate beans or
 delegated beans inside, but if you know Commons BeanUtils
 you can copy the value of one bean to another easily.
 
 I would use delegated beans for this to implement (2) revert
 
 class EmployeePayrollBean { ... }
 
 class SomeDahForm extends ActionForm {
 
   EmployeePayrollBean payroll = ... ;
   EmployeePayrollBean payroll_backup = ... ;
 
   // assume getter/setter methods exists
 }
 
 In the Action itself
 
 class SomeTypeOfAction extends Action {
 
   public void execute( ... ) {
 
   if ( button.equals(REVERT) {
 
   BeanUtils.copyProperties(
   yourform.getPayroll(),
   yourform.getPayrollBackup() );
   // forward request back to JSP/view
   }
   }
 }
 
 Because of the nested properties in Struts/Commons BeanUtils/JSTL the
 above shouldn't be a problem for creating a JSP.
 
 It is trivial to take the Common BeanUtils API to write a ``GenericBean''
 resetter that will reset all properties of a POJO to
 either  0, 0.0F, 0.0,  , null
 (but be very careful list Java Collections!!!)
 
 HTH
 
 --
 Peter Pilgrim
 Operations/IT - Credit Suisse First Boston,
 10 South Colonnade, London E14 4QJ, United Kingdom
 Tel: +44-(0)207-883-4497
 
 
 ==
 This message is for the sole use of the intended recipient. If you
 received
 this message in error please delete it and notify us. If this message was
 misdirected, CSFB does not waive any confidentiality or privilege. CSFB