Can we invoke ATG FormHandler thu AJAX ?Do I have a hope ?
Generally: Yes :-)
But the possibilities may be limited or require some weird hacks to get them running, so it may depend on what exactly you want to do.
There are several different approaches:
You cannot directly send requests to a form handler, like you could do it with a servlet or a controller in frameworks like Struts or Spring MVC, but instead you always have to have a form in the JSP page (created using the DSP taglib), and then submit that form. This means that you cannot trigger a form handler without having an according form for it in your JSP page. But if you have that form in your page, you can submit it via an AJAX request. Your AJAX request will then trigger the form handler and get the result back, in the same way as a normal form submission would. This approach is possible and generally works. If you don't want to have a form for your AJAX request visible in the page, you could hide it e.g. using CSS.
Another approach would be using ATG'S REST Web Services module, which allows you to expose any component as a RESTful web service. This also allows you to invoke form handlers without the need to have a form for them or first render a JSP page. The document titled "ATG Web Services and Integration Framework Guide" (from Oracle's ATG documentation) has a whole chapter on how to invoke a form handler as a REST Web Service.
Or you could write a small custom servlet that receives your AJAX request and then uses the received data to invoke the form handler, just like it would lookup and invoke any other Nucleus component...
yes, invoke the handle method in the page you are making the ajax request to.
I have done this using APIs.
You need to use APIs to populate the form data required and then call the handle method from the API. You can use ATG's REST APIs or Spring if you want.
Just make a simple JSP no need of complex code to call handle method,create a JSP and just add the dsp:setvalue tag and the bean attribute should point to your handle Method ,now call this JSP through simple ajax
<dsp:setvalue bean="TestFormahandler.submit" value="" />
this will invoke the handleSubmit of formhandler
and there is always a hope friend :)
Related
I'm pretty new to Play Framework.
My problem is that when a user clicks on the register link, he will instantly see validation errors.
The problem is that the method that serves the form also validates the form. So when the user clicks on the register link, gets to the validation without any input and then gets validation errors.
One solution would be to have an extra method to only serve the register form. But this would require an extra form and an extra route.
Another solution would be to disable validation on empty forms.
Is this possible? If not is there an other way?
You are on the way to a good solution. Make a second method.
GET /register controllers.RegistrationController.showRegistration()
POST /register controllers.RegistrationController.register()
The first is to display the registration page with the form, the latter to handle the form submit.
A method should stick to do one thing: either to show a registration page or to handle a post. Generally it's not a good idea to write a single method with a lots of if-then-else flow control statements.
Play framework also supports REST principles: in a simplified way GET is to retrieve a resource (=an empty registration page here), POST is to submit data(=do the registration).
Have a good look at Play framework's examples, I think the computer-database is very simple and a good starting point for you.
I have a textarea that I first print some values coming from a request.getParameter("some_textarea_name"). The user is allowed to modify those values and then I want to get the new values and replace the old ones with the new ones so as to query the new ones and get the results from my database tables. Can I do that without redirecting the user to a new page e.g without using the <form method> and the request.getParameter()
Can I do that without redirecting the user
Yes, you can implement an ajax call that will submit the form without redirecting the user and you can do something with the response (perhaps add it to the page).
If you need help using ajax follow this tutorial, but be aware that it implements AJAX in pure javascript (its a bit more bloated / complicated). If you want to keep it simple look into jQuery ajax, and here is a tutorial too.
without using the
No, you need to use the form to be submitted, however if you use ajax you wont need to redirect the user.
I have a jsp form which takes in user details. On submit button it goes to a jsp page where the details are entered into the database. But before that I would like to check if the username is available as soon as the user clicks the check availability button. How can this be done?
2 ways:
Just redisplay the same page after submitting the form wherein you conditionally display the validation message. This is rather trivial and already covered in the Hello World example in our Servlets wiki page.
Use Ajax to send an asynchronous HTTP request and manipulate the HTML DOM based on the response of the request. This requires a bit more in depth understanding of how websites really work and what JavaScript is. You can find some concrete examples in How to use Servlets and Ajax?
Use AJAX(Asynchronous Javascript and Xml). Its the best web2.0 technology. You can manipulate DOM based on the answer from server
I want to create login form in CQ5 using normal JSP & AJAX request with database. Can any one tell me the steps how to use normal JSP and AJAX in CQ5?
At the server-side, an AJAX handler can be implemented the same way as an HTML handler, in CQ5. Create your CQ template with a standard backing component. In your component, code your JSP as your normally would, following CQ best practices such as including "/libs/foundation/global.jsp" (or your overridden version of this). You'll have access to all normal JSP objects such as request and response. global.jsp also includes JSTL, so you've got access to standard taglibs.
As for connecting to a database, see my other answer, External Database with Adobe CQ5.
I've been using wicketTester.getServetResponse.getDocument to get the text of the current page for testing, only to find that after an ajax request it is set to the ajax response, not the whole page.
Is there any way to get a representation of the whole rendered page, as the browser would be seeing it after the ajax manipulation?
With WicketTester, you can simulate an Ajax call and see that your app sends the correct Ajax response. But it doesn't really exercise the ajax.
So I don't believe there's a way to get that from WicketTester.
If you actually need to test the app all the way to the UI including Ajax/javascript effects on the rendering, you likely need to use something like Selenium for that portion of your testing.
Thinking the Wicket way I hope the following approach should work:
#startPage(YourPage.class)
do some Ajax calls
#startPage(wicketTester.getLastRenderedPage())
wicketTester.getLastRenderedPageAsString()
The idea is: you start a page for testing, the first response is complete page response, then you do some Ajax calls which change some models around, then you start the last rendered page as an instance - this way it will render the page with the updated models from the Ajax calls.
The trouble is that you can put any Javascript in the response to an Ajax call. But if you don't want to deal with that, you can save the original full-page DOM, iterate through the objects in the Ajax response, find them by id in the full DOM and replace them with the new versions.
How useful this would be, I don't know, my guess would be not very. so I'd probably go with Selenium too.