• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Struts 2: how to set response for ajax function call?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am calling an ajax function from jsp page. The execute method of action class is getting called.

now, i want to set response parameter in execute methood for xmlhttp.responseText in ajax function call. i implemented ServletResponseAware and in setServletResponse method i set response parameter. but the response param value is over-written by return page of execute method. please suggest me a way to set response param.

please find below my ajaxcall in javascript:



here is my action class:



Thanks.
 
Sheriff
Posts: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You must be talking about this piece of code. When your action sends the request to a JSP page, this content will be ignored. If you don't want to send the request to the JSP, then return null from the execute method. You can't send response from action and JSP both...
 
Ramesh Babu Essampalli
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot ankit it works after returning null from action class.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why aren't you using a JavaScript library for the client side functionality?

Why are you using the parameter map when Struts 2 provides the means to avoid all those machinations?
 
Ramesh Babu Essampalli
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
david,

i am trying to create dynamic textfields on ajax function call. it was suggested in the link below:

https://coderanch.com/t/468632/Struts/null-pointer-exception-struts

but was facing problem in returning values into response. that is now solved after returning null from the action class.

but now, i have another issue related to it.

i have a list of textfields in the jsp shown below:



i have added mylist variable into my action class. and adding a value to mylist on ajaxcall. please refer my modified action class below:



but the change in value of mylist is not adding a textfield into the jsp page. please give me some direction to add the textfield dynamically using ajax. thanks.
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,

Ramesh, I copied your code(1st time you posted) and run. It works great. First of all thanks, Actually I was looking for the similar kind of code for my requirements. Now A small modification in that program. In your original program when I click on the submit button, The page getting refresh every time. I don't want to refresh the page when I click on submit button. I've requirement like, I'm Having a JSP page, Contains *User-Info* like name, age, address, country, zip, gender etc., (Using struts-2 and ajax tags). In the same page, I've HTML-Table contains these *User-Info* as headers. When the user clicks on submit button, All the data, what he entered in the form should populate on the Html table in the first row(always, without refreshing the page) and when he clicks on particular row in the table, the information should re-populate on the form( for these two process Action should call but page reload should not). The HTML-table contains maximum of 5 rows. If he entered sixth row, then pagination required. I want to do this in struts 2 - ajax. I'm new to Ajax and jQuery. I'm thinking to do this using ajax(server side), jQuery(client side). But I've no exact vision how to do this. Can you please tell me how to do this. If possible please send me a sample code. My mail-id is ramakrishna.kc@dioxe.com.


Ankit, I really din't get what you said. Please can you explain in detail.


David, Is that really necessary to use JavaScript library for the client side functionality?


Thanks:
Ramakrishna k.c
 
Their achilles heel is the noogie! Give them noogies tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic