• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

How to know the type of request coming from the form

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hie Friends,

I have a doubt...

I am working in a project in struts

I have a form with multiple button like ADD, UPDATE etc

Initially I am giving some path for action attribute in <html:form>.

Then whenever user is clicking the button in the form,I am trying to call different javascript functions in which I am overriding the action attribute of form to different actions.

BUT THE PROBLEM IS

I am not understanding how to know from which button the request came whether it is from ADD or UPDATE etc..

I have to write only one action class or I can write one action class for each button.

How to handle this situation in Action class.How to know which button the user has choosen..

Hope My doubt is understood.....

Plzz let me know if any confusion..

Thanks in advance
GYREDDY
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pass the value of the button name as a hidden parameter or a dispatch parameter. Google LookupDispatchAction.
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This link may be useful to you.
 
yerra reddy gatla
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got some idea now after reading your suggestions(LookupDispatch action).

But actually I have Javascript validation. I think In this situation,This option may not be useful.

When the button is pressed, I am validating javascript. If it returns true then I have to call ADD,UPDATE etc...


Can anybody please clearly tell me how to read the corresponding button value in ACTION class when I have Javascript for each button.

I am not getting any idea...

Please try to give me skeleton code for Action class for this problem..

I am very much thankful to you, If you give me a solution..

banghead:

Regards
GYReddy :
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Submit buttons pass a value to the server when pressed. For example, the following button:

<input type="submit" name="saveIt" value="Save">

You can know it has been pressed if the following statement is true:

"Save".equals(request.getParameter("saveIt"))

If it has not been pressed, the above statement will not be true.

With non-submit buttons (type="button")this is not the case. The best way to tell which button was pressed is to use JavaScript to maipulate a hidden field. Here's an example:

<form name="xyz" >
<input type="hidden" name="color" >

<input type="button" value="red" onklick="document.xyz.color.value = this.value;this.form.submit();" >

<input type="button" value="green" onklick="document.xyz.color.value = this.value;this.form.submit();" >

<input type="button" value="blue" onklick="document.xyz.color.value = this.value;this.form.submit();" >

In your Action class, you can tell which button was pressed by looking at the results of:

request.getParameter("color");
[ June 19, 2006: Message edited by: Merrill Higginson ]
 
yerra reddy gatla
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Thank You very much...

But If write like this,Is JavaScript will get called???

<input type="button" value="red" onklick="document.xyz.color.value = this.value;this.form.submit();" >


I have to call Javascript for each button I have..

Can you tell me, Is this method will work incase I have to call javascript validation() for a button..

What is the syntax to call javascript in onClick

Please clarify this doubt finally about this Issue..


Regards
GYReddy
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not entirely sure I understand your question, but here's some more information.

Yes, the above example calls JavaScript code.

I used "onklick" instead of "onclick" because javaRanch has a filter that won't allow me to put "onclick" inside a pair of brackets. The correct entry is "onclick".

Secondly, if you need to call multiple JavaScript statements from a single event, the best solution is to put the statements in a function and call the function.

For example:


If this doesn't answer your question, please explain in more detail what it is you don't understand.
[ June 20, 2006: Message edited by: Merrill Higginson ]
 
yerra reddy gatla
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much for trying to solve my problem..
I really need your help, as I have no collegues to help..

I tried the above said method(previous post) but still facing problem..

I will tell my doubt clearly.. please SPEND SOME TIME and do reply


I have a JSP page in which I am searching for a record for the given emailid. For this,I have a search button. When user press SEARCH button by entering the emailid, It should call the javascript and do clientside validation for email.After validation, If a record exists with the given mailid, I am REGENERATING the same form again by displaying the corresponding record values in the textboxes below. otherwise I have to give a new form.(For this I am Using If,Else)

After displaying the existing record for given mailid, I have to allow user to UPDATE or DELETE the record.. here I have to call javascript for UPDATE button..

If no record with the given(searching) mailid, I have to give a new form and the user can fill the form and ADD the record. Here I have to call Javascript again for the ADD button..

The thing is I completed the same task with general Jsp,servlet(web) application

Now I have to do it in struts..


Can u please tell me how to write the statements for SEARCH,ADD,UPDATE button by calling javascript..

and how to know the button the user chosen in ACTION class( ADD or UPDATE)


this is my doubt.I think it is clear..

Thank you again...

Regards,
GYReddy
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One way to do it would be to define a different action for each button:

<action name="registrationForm" path="/registrationAdd" class="com.mycompany.registrationAddAction" />
<action name="registrationForm" path="/registrationSearch" class="com.mycompany.registrationSearchAction" />
<action name="registrationForm" path="/registrationUpdate" class="com.mycompany.registrationUpdateAction" />
<action name="registrationForm" path="/registrationDelete" class="com.mycompany.registrationDeletAction" />


Then have each button use javaScript to change the form's action before submitting it.

something like this:


That way you don't have to worry about the action knowing which button was pressed because a different action will be called for each button.


If you don't understand this JavaScript code, it might be a good idea to take time out from your project and work through some JavaScript tutorials to get more familiar with JavaScript before proceeding.
 
yerra reddy gatla
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hiee

thanks for your valuable response..

I think you are getting bored with my doubts..

I understood the javascript. As I told you previosly, I was done the same application without struts(normal servlets/jsp application),it's not the problem with javascript..

I am writing button tag in jsp like this

<input type="button" name="searchButton" value="search" onKlick="isEmail(this)" >

and I am writing javascript like this

function isEmail(button) {
if(validate())
{
alert("gyreddy");
document.forms[0].action = 'vendor' + button.value + '.do';
document.forms[0].submit();
alert("gyreddy22222");
}
else
{
alert("invalid email");
}
}

I am writing the action tag in XML like this

<action name="vendorform" path="/vendorsearch" input="VendorSearch.jsp" scope="session" type="com.vj.action.VendorSearchAction">
<forward name="oldvendor" path="/OldVendor.jsp"/>
<forward name="newvendor" path="/NewVendor.jsp"/>
</action>

Now the problem is it is not performing any action..

when i enter the email id and press SEARCH button a new id dispalying like alert and saying that

A SCRIPT ON THIS PAGE IS CAUSING INTERNET EXPLORER TO RUN SLOWLY. IF IT CONTINUES TO RUN YOUR COMPUTER MAY BECOME UNRESPONSIVE.
DO YOU WANT TO ABORT THE SCRIPT?
yes no

If i choose NO my system getting strucked.. not responding and If i choose YES then no action is getting performed..it is displaying the same page with no response..

Can you please tell me what might be the problem.

Thank you once again

Regards
GYReddy
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The most likely cause of this error message is that your JavaScript is in an endless loop. Check to make sure that there is no "onsubmit" event coded in your <html:form> tag. Look for anything else that could put your code into an endless loop.
 
Do not threaten THIS beaver! Not even with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic