• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

execute() issue in Action class

 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without any code, configuration, or anything else, it's impossible to help.
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
or debug that action class
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
vijay jamadade
Ranch Hand
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to pass through url my friend as i have replied onthe above post before submit.
 
Pradeep Adibatla
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic