Results 1 to 4 of 4
  1. #1
    shashib09 is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default autocomplete using ajax

    Hi guys,
    I am new to ajax and java technologies. From last 2 months i m working in java and other technologies.
    I want to write code for autocomplete textbox in ajax using struts. i
    i want fetch values frm database using struts.
    in jsp page i hv to write ajax and related function of javaascript and in struts page i hv to write database connection & other related things.
    Plz help me..
    Its urgent!!

  2. #2
    shashib09 is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default i tried ajax in jsp

    Hi,
    i tried ajax code in jsp and struts. i m getting data frm DB but it is not displaying in textbox(displaying below textbox).
    below my code in jsp page:
    function showData(value){
    var name1;

    xmlHttp=GetXmlHttpObject();
    var url="<%=request.getContextPath()%>/beforeModifyAsset.do?parameter=autoCmplete";
    url=url+"&asset="+value;

    xmlHttp.onreadystatechange=stateChanged ;
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }

    function stateChanged() {
    if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    var showdata = xmlHttp.responseText;
    document.getElementById("mydiv").innerHTML= showdata;
    }
    }
    function GetXmlHttpObject(){
    var xmlHttp=null;
    try {
    xmlHttp=new XMLHttpRequest();
    }
    catch (e) {
    try {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    }
    return xmlHttp;
    }
    <body class="background" id="bodycontent" onload="assetId()">
    <html:form action="/beforeModifyAsset.do">
    <br>
    <center>
    <span class="pageHeading"><bean:message key="LS0305" /></span>
    </center>
    <br>
    <logic:messagesPresent>
    <table width="450" border="0" cellpadding="0" cellspacing="0" align="center">
    <html:messages id="error">
    <tr>
    <td align="center" width="95%" class="BodyTextMed">
    <font color="red">
    <li>
    <span class="alertMsgs"><bean:write name="error" /></span>
    </li>
    </font>
    </td>
    </tr>
    </html:messages>
    </table>
    </logic:messagesPresent>
    <logic:messagesPresent message="true">
    <table border="0" width="450" cellpadding="0" cellspacing="0" align="center">
    <html:messages id="message" message="true">
    <tr>
    <td align="center" align="center">
    <font color="red">
    <li>
    <span class="alertMsgs"><bean:write name="message" /></span>
    </li>
    </font>
    </td>
    </tr>
    </html:messages>
    </table>
    </logic:messagesPresent>
    <table width="60%" align="center" class="table">
    <tr>
    <td>
    <table width="98%" align="center" cellSpacing=0 cellPadding=0 border=0 id="bodycontent" >
    <tr>
    <td align="left" class="td">&nbsp;&nbsp;Asset Identification Number&nbsp;<font color="red">*</font>:</td>
    <td align="left" id="asset" >&nbsp;
    <html:text property="assetId" onkeyup="showData(this.value);"></html:text>
    <div id="mydiv"></div>
    </td>
    </tr>
    <tr>

    Note: i want to display in textbox similar to google search.
    plz help me.. wat to do next

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,751
    Rep Power
    19

    Default

    Have you debugged it?
    Does it get to the server?
    Does it make it into the stateChanged() method on javascript?

    Come on, we can't debug this for you...

  4. #4
    foo123 is offline Member
    Join Date
    May 2011
    Posts
    10
    Rep Power
    0

    Default struts 2 ajax

    struts 2 has built in ajax support with specific tags
    (check them out in documentation of struts 2)
    this is for JSP part
    for action part you write an action which accepts parameters from request
    does the processing (accessing DB, logic , formatting etc)
    and writes back (using functions from ActionServletContext or even System.println) and encodes them eg JSON format.

    Check the struts 2 documentaion (online or with struts package) for ajax examples i think it even has a complete ajax example but there can be variations which are not in the struts documentation but valid nevertheless.

Similar Threads

  1. Replies: 2
    Last Post: 01-05-2011, 10:30 PM
  2. JList autocomplete with Vector
    By nik_meback in forum AWT / Swing
    Replies: 0
    Last Post: 01-01-2011, 12:31 PM
  3. JList/ListDataListener Autocomplete functionality
    By take2hikes in forum AWT / Swing
    Replies: 2
    Last Post: 11-09-2010, 04:56 PM
  4. autocomplete in text file
    By Markus1 in forum New To Java
    Replies: 0
    Last Post: 08-06-2010, 04:57 PM
  5. AutoComplete for jtextfield
    By pinks_70986 in forum New To Java
    Replies: 2
    Last Post: 02-12-2009, 06:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •