Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

MappingDispatchAction's JSP CODE

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help!

Background
==========
I have a class that extends the new
MappingDispatchAction
class
. This class has two methods, namely getCustomer and
updateCustomer.

The corresponding mapping for each method are below:

<action path="/getCustomer"
type="com.fujimitsu.cargo.gen.CustomerAction"
name="cargoForm"
scope="request"
validate="false"
input=".customerDef.jsp"
parameter="getCustomer">
<forward name="success" path=".customerDef.jsp" />
</action>

<action path="/updateCustomer"
type="com.fujimitsu.cargo.gen.CustomerAction"
name="cargoForm" scope="request"
validate="true"
input=".customerDef.jsp"
parameter="updateCustomer">
<forward name="success" path=".customerDef.jsp" />
</action>



my jsp has three buttons, namelygetCustomer,
updateCustomer and cancel.

JSP CODE
========
The works with DispatchAction. However, due to the limitations of DispatchAction, I want to use the new MappingDispatchAction class.

<html:form action="/Customer">
<%-- onsubmit="return validateCargoForm(this);"--%>
<table width="500" border="0">
................
................
other fields....
................
................
<html:hidden property="methodToExecute" value="unknownMethod"/>
<SCRIPT>function set(target) {document.forms[0].methodToExecute.value=target;}</SCRIPT>
<html:submit on click="bCancel=true; set('getCustomers')">Get Customer</html:submit>
<html:submit on click= "set('updateCustomer')">Update Customer</html:submit>
<html:cancel/>
</html:form>



My question:
============
1. In my JSP, what what should be the value of the
ACTION attribute of html:form
i.e. <html:form action="???"> (i.e. which
mapping should be specified here)?

2. what should the code of the button for excuting
a. getCustomer and updateCustomer method be?
i.e. <html:submit ???

b. cancel be i.e. <html:cancel ???

Thank you.
 
Ranch Hand
Posts: 415
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The action will be the same as what u give in ur <action path="". no need to pass anything here just the diff between Dispatchaction and mappingda is taht here u need not pass that parameters value in query string that u can directly write in conig files paramter attribute
 
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the form bean type is the same for both getCustomer and updateCustomer, you can put any one in the form action.
Lets say you use "getCustomer". Your form would then look like this.


Note the submit button for update, first updates the form's action to "updateCustomer". You could also leave the set ('getCustomer') call on click of the "Get Customer" button (I have removed that here). In that way, only your set() javascript function would change.

Remove the hidden control, it is not required anymore.
<html:hidden property="methodToExecute" value="unknownMethod"/>

What do you want to do on the "Cancel" event?

Sheldon Fernandes
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your suggestions. What you suggested is exactly is what I did and it works.

Regarding the cancel button, I want all fields to be empty after the button is clicked. Your suggestion will be appreciated.

Thank you.

Ola.
 
Sheldon Fernandes
Ranch Hand
Posts: 157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<html:reset> should do the trick
OR
you could directly use an html input control of type reset.
<input type="reset" value="Reset" />

Sheldon Fernandes
[ October 11, 2004: Message edited by: Sheldon Fernandes ]
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, this also worked. It was staring me in the face all the while.

One final question: Is there a trigger in Javaranch that I can switch on, so that when I log in, all my postings and the ones that I have responded to will automitically come up?

Regards.

Ola.
 
Tokunbo Oke
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just noticed that the reset button - HTML:RESET only clears unsubmitted data. It does not clear data retrieved from the database. Can you please shed some light on why this is the case?

I am wondering if I have to add an on click event to the reset button that forward to a mapping-->class.method-->formBean that sets all the fields to null in the formBean.

Thank you.

Ola.
 
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic