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
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.
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 :)
I'm looking to pass data from a form into an iFrame, but I have a slight problem.
The form page I can edit with no restrictions
The page I send the data to I cannot edit unless its html or JavaScript
The data needs to end up in an iframe within this page, which I can edit with no restrictions
I'm incorporating a search function into a CMS system which is why I cannot edit the iframe's parent page, and why I am using iframes at all.
At the moment the data sends to the parent page but is not picked up within the iframe, I am sending via the POST method.
I got it..
Added and extra page which converted the post data into session data,
if anyone knows a better way i would like to hear it though.
And they are the same domain, but editing the CMS system would have taken ages to look through as its not mainstream or developed by me.
Maybe I'm oversimplifying the problem, but can't you use the "target" attribute of the form tag to post to the Iframe?
I need to update an element on the page based on what the user is typing, while the user is typing (i.e. without having the user to click submit buttons). Similar to how StackOverflow does the preview of the question, but I need data from the server to update the element, hence the postback requirement.
What is the best way to get this done? Thanks!
There is no postback in MVC. Instead of postback you should make an ajax request using jquery to get data from server.
Examples of MVC + jquery JSON ajax request can be found here and here.
I would like to have a user redirected to an external credit card gate. Of course I have to POST some user info to that gate, but I don't know how exactly can I do this.
I know that I could do this by generating a html form with hidden or read-only fields and have a user click "Submit" button. But this solution is not perfect, because all the form data could be easily changed using e.g. Firebug. I think you cannot do this using $this->_redirect(...). But maybe there is some other solution?
Many thanks for any tips or suggestions.
I would like to have a user redirected to an external credit card gate. Of course I have to POST some user info to that gate, but I don't know how exactly can I do this.
Using a form is the only method available. The RFC states that the user should explicitly agree to sending a POST (i.e. click on a submit button).
I know that I could do this by generating a html form with hidden or read-only fields and have a user click "Submit" button. But this solution is not perfect, because all the form data could be easily changed using e.g.
It is no more secure that using a redirect as the header data can be modified without too much of a problem. There are even Firefox plugins to do it.
use cURL to post data
http://framework.zend.com/manual/en/zend.http.client.adapters.html