How to get a live search feature using Jquery, AJAX, and Servlets? - java

I have been following this guide: http://veerasundar.com/blog/2008/12/implementing-ajax-in-java-web-application-using-jquery/
When a user types a keyword in the search and presses the search button, I am able to get results back. Now, how do I make it so when the user starts typing any character, there is a post request. Right now, it uses the click function. I want to be able to get rid of the search button and let the post request occur whenever the user starts to type in a letter in the search bar.
Thanks.

One that uses jQuery
http://docs.jquery.com/Plugins/autocomplete
Plain js
http://www.brandspankingnew.net/archive/2006/08/ajax_auto-suggest_auto-complete.html
http://articles.sitepoint.com/article/life-autocomplete-textboxes

You can use much of the same code. Just replace
$("#getWeatherReport").click(function(){
by
$("#cityName").keyup(function(){
To learn more about jQuery, I'd warmly recommend their own tutorials.

Related

prompt() in wicket components

I try to find pattern how to return 'prompt()' result in java like http://www.mysticcoders.com/blog/wicket-ajax-confirmation-modal-window/ (but in this case author using 'confirm' instead of 'prompt' and doesn't return anything from javascript). Now I am using hidden field in form and update this field before submit, but maybe you know how to solve this problem more elegant (for example using AJAX components in wicket). Thank you for your time.
If you just want so submit the prompted value within your form, your hidden field approach looks adequate to me. If you want to call some Wicket code on the server with the prompted value independently of the form submission, see How do I call Java code from JavaScript code in Wicket?

How to restrict double click on button in struts /Java?

I have created a web form. On Click of button, database query would be fired. The Problem is that when user clicks on button twice, query would be fired 2 times. I want to prevent that. Any help?
Take a look here
Struts2 has a built in mechanism for stopping double form submission that works on the server side instead of the client. You may need to add the TokenInterceptor if its not on the defaultStack you're using.
Here is a quick tutorial
If you are happy to use jQuery you could consider using
http://jquery.malsup.com/block/
onclick or onsubmit call $.blockUI();
Some Demos for your reference
http://jquery.malsup.com/block/#demos
The belt and braces approach is to set a JavaScript flag variable when the button is clicked and block subsequent submits "onclick". Then, on the server, implement the "synchronizer token pattern" (you can just Google that term to find out about it).

Multipage environment in GWT

I have been developing an AJAX web application using GWT. I've read several blogs and forums about this question and left with no clear idea. I understand that GWT is an AJAX application, that supports only stand-alone web application. By stand-alone, I meant GWT to be a single web page that would suffice the user requirements. However the use case I have is pretty complex and I'm stuck in this use case that doesn't let me proceed.
My usecase(s) goes like this:
Usecase #1: There is an order entry form where user will enter a search string to search for a particular item. With GWT, I could display the result in a table (say celltable). However, when I click a column in the cellTable, I want the value of the column to be sent to the server and display another page that will display only the details of the selected column. I'm not sure how to accomplish this.
Usecase #2: Let's say the web application I develop is called "InventoryControl" and I have different requirements such as:
display Available stock
display Order stock
display Manufactured unit
and Using Java servlets, I could just type http://localhost/availableStock?stockId=1234 on my browser to get the "Display available stock" for the given stockId and then http://localhost:orderStock?stockId=1234 to get the "display order stock" and similarly "display manufactured unit". Is the same possible using GWT? i.e. when I type http://localhost/availableStock?stockId=1234, is it possible to read the parameter being passed and then display the corresponding page?
If these are not meant to be guaranteed by GWT, should I stick with Plain old JAVA servlets/JSP?
Thanks in advance.
Ashok - Please note, what filip suggests above does not require multiple "pages" in the sense of additional html host pages. You can build a panel holding your display of the details, and swap it into the rootpanel of your host in the onSuccess() of your rpc call. The GWT history mechanism allows you to assign anchors to these "places" and provide a mechanism to map these anchors to specific display classes in your code.
GWT already has a mechanism for handling multiple page applications. Have a look at Activities and Places. You can define each page as a place in your application, and use the GWT mechanism to go from place to place at any time. Using places also allows you to easily add tokens/query parameters to each "page", in an OO manner, without having to worry about populating/querying the URL directly. Have a good read of the link!

manipulating the website action through external java code

There is a website,and it has a button on click checks for the value in the textbox and searches for it and displays the result.
How can i with my java code,prove the input and display the appropriate result on my java code.
On seeing the source of the website,i get to know the methods that gets called on the button click.But what and how to further trigger the event and pass the value to textbox and obtain the resut !!
Use a programmatic web browser like HtmlUnit.
I'm not 100% clear on what you're asking for, but it sounds to me like you're trying to get some sort of client-interaction emulation/automation.
Check out Selenium's Java API

Clear HTTP Session

I am trying to clear everything on my HTML form when I visit it from a hyperlink entry.
Any ideas? My development language is java.
are you using session-scoped data? if so, close your browser and open it again.
I'm not sure the application is, but one way to accomplish this would be to use JavaScript. For example, if it is acceptable to clear the form every time that page is visited you could write a quick function that clears the form when the page is loaded (i.e., using the onload event).
If you only want to clear the form when the page is hit from that link you could add a param to the URL (e.g., clearForm=true) and use JavaScript to pick up the query string and clear the form when that parameter is present.
This is, of course, a purely client-side solution. For a server-side solution it would be helpful to know what framework you are using.

Categories