permaculture playing cards*
The moose likes Struts and the fly likes execute() issue in Action class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "execute() issue in Action class" Watch "execute() issue in Action class" New topic
Author

execute() issue in Action class

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
My Execute function in action class is getting executed twice...initially with all relavant output and then with all zero and null values...

What should be the issue??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Without any code, configuration, or anything else, it's impossible to help.
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

or debug that action class


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
This is my execute method...



and these are the action mappings...



The above one is rulesetAction class...

In the rulesets jsp...I select row and I pass the button value "rulesScreen " and a value to this action class.

So rulesscreen is true and it enters that loop but it happens twice...this is the output...

vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
It must be because you have used submit tag in jsp and also you will be calling the javascript submit again thats why it is getting submitted twice. Use html button tag and then submit the page using javascript.

I think that will probably solve else send your code in jsp.


Regards, Vijay Jamadade.
( Nothing is Impossible.)
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
This is that line in jsp...



I changed this to button it happens only once but the page isn't submitted!

This is the Javascript code on click...

vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
See there are two things when you use input type submit it by default gets submitted to the action that you have specified for that form in form tag. And when you are using the button tag it acts as a button only. Here you need to submit that form using javascript form.submit(); in the method (javascript). Here you are implementing ajax form will not get submitted in this case.

Why are you using the xmlhttp object?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

Where is this submit button of yours?? Wherever it is, in the containing form tag, include two hidden form fields, remove the AJAX request, in your javascript, set the selectedRSid and goToRulesScreen values to the hidden fields, and submit the form. Basically do this.

Add these two to your form element which contains the submit button

In your javascript, make the following changes

This should work...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
Ankit,

There is no need of hidden parameters and all. You are making it more complex. When you submit the form you will get every value on page that is in the form.

Simple way is just call javascript function and submit the form for the action you want using form.action=xyz.do and after that submit the form using form.submit()

thats it.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

vijay jamadade wrote:There is no need of hidden parameters and all. You are making it more complex. When you submit the form you will get every value on page that is in the form.

Maybe I'm making it more complex, but if you see, one of the parameters that he wants to send in the request is coming from the HTML content of a table cell
That won't be submitted with the form right?? So that's why I included three hidden form fields. I don't know from where the other two values being passed as a request are coming (rsSel and goToRulesScreen in the javascript code). So my code will work (hopefully) from wherever the values are coming...
vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
You can pass that value through url like form.action=test.do?Rs=true and get it in the action by request.getParameter("RS") . Else in any case the all the properties created on page can be accessed using name whether you create that using javascript it does not matters.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
This is the output i get...



========================================================================================================
in RulesetAction Execute() !!!
why is :--> 1
addRuleSet--->null
addrsok--->null
rsName--->
Now why is :--> 2
The tar in RS is :--> null

This is the new one and it should do ok...




I wonder why rsName isn't reaching to action class...

vijay jamadade
Ranch Hand

Joined: May 12, 2008
Posts: 241
You need to pass through url my friend as i have replied onthe above post before submit.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
My form is like this...



and I did this change in javascript method...





This should suffice right?

this is what I get now...


----------------------

========================================================================================================
========================================================================================================
in RulesetAction Execute() !!!
why is :--> 1
addRuleSet--->null
addrsok--->null
rsName--->null
in RulesetAction Execute() !!!
why is :--> 1
addRuleSet--->null
addrsok--->null
rsName--->pro2_RS


strange type... what else could be...
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

vijay jamadade wrote:You need to pass through url my friend as i have replied onthe above post before submit.

The URL solution that you gave will not work in case of a GET request. If you have a form element like this
Now here only one request parameter will be sent which is param2 and param won't be sent. This is why I suggested the hidden field solution. Since he is using a form with GET method, so your parameter won't be sent. This can be fixed if we use POST method but then what's the whole purpose of using POST request if you can see some request parameters in the request URL.

Coming to the problem, Pradeep where is rsName actually declared in your action class?? I can't see it declared as a class field with tar and why. Looking at the output that you showed earlier, the output shows rsName---> not rsName---> null. So the request parameter is getting sent. Are you sure the javascript code is working properly??
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Ankit,currently it looks like this....


in jsp...



in Javascript...





the above 2 are fetched perfectly(nam,rsSel have the have the values)...
As you could see I removed the AJax call and have 2 hidden fields...


in action class....



The output...
----------------------


==============================================================================================================
in RulesetAction Execute() !!!
why is :--> 1
addRuleSet--->null
addrsok--->null
rsName--->
rsSelId--->2
The size of rsName is :--> 0
The value rsSelID is :---> 2
----> size of ruleList is :--> 0
Exiting Rules screen !!!
Now why is :--> 2
The tar in RS is :--> successA



The Javascript code is just perfect,it's the action class that should be closely monitored I guess!


David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

That action class is really hard to follow, btw: its cyclomatic complexity is too high, it does way more than one thing. For the sake of whoever has to maintain it, I'd sure consider refactoring.
 
GeeCON Prague 2014
 
subject: execute() issue in Action class