Prevent page reloading in Struts 2 - ajax

I am currently working on a small web app and this is the first time i am using Struts2. Here is what i am trying to achieve.
A Struts2 JSP page on form post, calls a struts action. Once this action completes it task, I need to return to the calling JSP with out any page reloading (avoid postback).
how can i achieve.can any one please help me?.

It is called AJAX (no kidding).
In Struts2 you can use Struts2-jQuery Plugin to achieve that pretty easily.

As AndreaLigios said, you can achieve this using struts-j query plug-in.
Create a remote page to display your result.
use
<sj:sbmit targets="[div_id]" />
on your main page to submit the form
Add a div to your main page to display the remote page.
<div id="[div_id]" />
In your struts.xml, just return the remote page as a result of your action.

Related

Trigger custom JSP tag manually

Lets pretend that we have custom JSP tag somewhere on page:
<myTag:loadList data=${asyncData} />
When a page starts loading, asynchronous AJAX call to server is made. As a result of this call the data for asyncData parameter should be provided.
The question is - how can I "trigger" my custom tag for rendering manually based on successful AJAX request? Thank you!

How to migrate to a specific part of a html page after a struts action forward?

I am using Struts 1. I wonder how I can show a particular part of a html page after mapping.findForward("success"); is returned and a jsp is processed.
For example, I can use this url to show a part of html with id="contact" even if it is way below on a page.
http: //www.mycompany.com/generalInfo#contact
But how can I do it after a struts action forward?

Spring MVC Application (Back button)

On my MVC spring application I send a form to a page using GET method to perform a search. The results of the search is a list and, for every entry is possible to navigate to a details page. It works fine.
Now, I want to have a back button on the detail page which should take back to the searched list.
I can call the same controller method to reevaluate but it performs Data Base calls, which I don't want to do.
What is the best solution?
You want it to perform database calls don't you ? What if the data has been changed by a differet user?
If not you can use javascript :
<input action="action" type="button" onclick="history.go(-1);" />

How do I programmatically refresh a view page with AJAX?

I wrote a custom link in my page which created by views module, I want to click it to do something, then the page will refresh by ajax, how do I implement this?
I am sorry I didn't express myself clearly, I use Drupal 7, and the Views module to custom my own page.
You can use this module https://www.drupal.org/project/views_refresh or just use the code below in your JS to refresh the view.
$('.view-dom-id-403402eee35f68cd32fe87b45702dc63').triggerHandler('RefreshView');
Attach an event to the link, and when that is fired, execute an AJAX request.

Form submission inside ajax

In my application on a button onClick, I am loading a form in an overlay using ajax. But this for submission is not redirecting to the required page.
I have tried the same form element without ajax and overlay, then it is working fine. So there is no problem with the form element. I think I am missing some settings to invoke form submission inside ajax.
I am using Web2py application.
I would greatly appreciate any suggestions.
EDIT:
I have one more similar question. I am displaying a web2py SQLFORM for a db-table in an overlay using ajax. The form submission and data update is working fine. But after the form submit I want to close the overlay and reload the page. Right now, it is showing 'Server Error' inside the overlay. I am using LOAD() to load the form on overlay.

Resources