Integrating jQuery with Struts2.0.9 - ajax

How can I integrating jQuery with Struts 2.0.9? Here I can not upgrade my Struts2 version. I want to leverage jQuery ajax functionality with Struts2. Not able to figure out how can I pass a valuestack object to jQuery.

I guess you can use either struts2-jquery-plugin
Struts2 does not care of you call its action by Normal page submit or by ajax calling using Jquery or any other javascript framework
Once you call you action value-stack and other critical parameters of Struts2 will be available at your disposal.
Still your question is not clear what is your requirements, more details can pour more valuable inputs

Though the question has been answered, there are some significant issues when we speak about struts2 jQuery plugin 2.5.0.
It is based on jQuery 1.4 which is outdated, multiple issues have been closed from 1.4 to 1.7
Multiple browser support issues especially with IE (if you want to have browser compatibility).
I found it much more easy to directly use jQuery with Struts2. As mentioned, calling via Ajax or non ajax has doesnt make any difference to Struts2 framework, request is handled in the same way.
If you want to use Struts2 jQuery Plugin you can either work on the source code and upgrade the jQuery to 1.7 and accordingly change newer API.

Related

TYPO3 v8 Form framework submitting form with ajax

Is there a way to configure the TYPO3 core Form framework to submit a form with ajax?
I already tried to submit the whole form, but i think that the honeypot or another security feature prevent it from submitting directly.
Is there any simple solution to fix this?
Since this question ranks fairly high when searching for 'typo3 forms framework ajax', this link might help you with this task, finally:
https://www.comuno.net/blog/detail/formular-mit-typoscript-rendering-per-ajax-verschicken/

AEM OOTB Form Component and AJAX Submission

I'm evaluating AEM 6.2 OOTB forms component to build a Newsletter signup form with AJAX submission, this is not AEM Forms that is licensed separately.
https://docs.adobe.com/docs/en/aem/6-2/develop/components/developing-forms.html
I have not used this component previously, can someone advise on the following:
Can I make the form submit request via AJAX and capture response from the server side / API (asynchronous)?
Is there limitation in terms of styling capability? I'm trying to achieve the same signup form at the bottom of this page https://westernstarbutter.com.au/en/recipes/ham_-cheese-and-veggie-bake.html
Any other limitations / gotchas that I should be aware of?
Would love to hear some advices on this, would be great if someone can share some implementations as well.
Thank you!
Can I make the form submit request via AJAX and capture response from the server side / API (asynchronous)?
I don't believe you can do this OOTB - it's certainly not part of the actions list but it wouldn't be too hard to create a custom action and add the necessary Javascript code to hook into the form submission.
Is there limitation in terms of styling capability?
Not really - just add your own CSS and off you go.
Any other limitations / gotchas that I should be aware of?
I remember the validation being very limiting, especially if validation of a field is dependent on another field.

Why does ajax and jsf work nicely together? How do Ajax lifecycle plug in with normal JSF lifecycle?

I have used JSF 1.2 but new to JSF 2.0 . It seems like JSF 2.0 seamlessly supports ajax functionality via <f:ajax> but I am not clear yet how ? I would like to understand what makes these two powerful technologies to work so nicely together ? How does the two lifecycles interact ?
P.S: I am familiar with ajax and javascript. So you can base your answer on that premise.
The question is really broad and I would suggest to search for the appropriate tags to understand its usage in real situations. BalusC has contributed much here on stackoverflow and has also written excellent tutorials that Xtreme Biker made a reference to.
Due to abscence of answers I would offer a basic vision of how ajax works within JSF. There is a special Javascript library in JSF which makes it possible to perform ajax calls to the server with jsf.ajax.request(...). To ease development, there are components that you may attach ajax behaviour to. Typically you will use <f:ajax> tag on the component of your choice, like <h:commandButton>, to add ajax functionality to it.
In the old times we would send an asynchronous XMLHttpRequest via get or post to the server and wait until server sends us postback data which we will get most typically in JSON or XML format for client'side processing and update the view via document.getElementById(...) or by more convenient methods introduced by modern Javascript libraries. I think that in the end this is what JSF does behind the scenes.
In JSF 2.0 <f:ajax> tag was introduced which helps partially submit data, process it on server and partially update your view. For this the ajax tag has the following most important features/attributes: <f:ajax execute="..." render="..." event="..." listener="..." onevent="..." />. Let's take a closer look on all of them.
execute attribute tells JSF about what elements should be updated/processed on the server during this request by specifying a list of element ids;
render attribute tells JSF which components shall be replaced after ajax call is finished - the new elements that were rendered on the server shall replace the old ones with specified ids after partial page update;
event attribute defines events on which an ajax call shall take place, for instance, in case of a command button the event may be a click event, in case of an input text field the event may be a keyup, or blur event;
listener attribute defines a binding to a managed bean method of type public void processAjaxRequest (AjaxBehaviorEvent event) { } that will be triggered on ajax request and executed on server, before partial page update is done;
onevent attribute defines a javascript function to call during different phases of ajax request.
You may consult another excellent tutorial written by Marty Hall on ajax here.
I didn't intend to make an overview of ajax features in JSF 2.0, but rather to make a short introduction to get a basic grasp of ajax functionality.

Cakephp 2.x and Jquery Ajax - Cake doesn't think request is ajax

I am working on a little cakePHP application and am trying to AJAX it up a bit with JQuery to make it work a bit nicer for users.
I have just followed this tutorial: Cakephp Jquery AJAX Tutorial but for some reason it isn't working.
One great bit about the tutorial is that functionality falls back to normal CakePHP if the request isn't an AJAX request so my app still works but it doesn't work the AJAX way...
It looks like in my Controller, the request doesn't pass the test:
if($this->request->is('ajax'))
and so continues onto the normal $this->redirect(...) of the non-AJAX way.
Could it be something to do with the if statement for 'ajax'? In the tutorial the author is using a version of cakePHP before 2.0 and so uses $this->RequestHandler->isAjax() but this was deprecated as of cakePHP 2.0.
Thanks for your time.
JsHelper::link might do what you want.
As I think you have discovered, it's nothing to do with Cake. It's because in the tutorial he tells you to make a link, then you are clicking the link to run the action. This causes the AJAX request to fire, but also the actual link gets followed.
You need preventDefault() in your jQuery click event, to stop the browser from following the link in the normal way. This will not affect the link if the user doesn't have JavaScript... because they won't have the click event occur in the first place :)

Dwr and script session invalidation

We are using reverse ajax with polling in our DWR 2.0.6 based application. The problem is that when we move away from a page where reverse ajax was set to true, we want that ScriptSession to be invalidated. It does not happen by default.
In the docs for DWR 3.0 it is mentioned that we can call dwr.engine.setNotifyServerOnPageUnload(true); in our js file
But this is not available in 2.0.6.
Any ideas suggestions etc.?
You could write this manually, using an "onbeforeunload" handler.

Resources