0

I have a jsp page. In jsp page i have array of objects say history. In the jquery, i have got the index.Now i want to pass history[index] object to the action class in struts2. Here is the code which i have tried but it is showing error.

 $(document).ready(function() {
 $(function() {
     var rateDialog = $("#rateDialog").dialog({
         autoOpen: false,
         minHeight:250,
            width: 400,
            height: 265,  
         open: function( event, ui ) {
             $("#showDialogMessage").hide();
             $('#reviewArea').val('');
             }
         });

         $(".rate").on("click", function() {
             // Display the dialog
             rateDialog.dialog("open");
             alert( $(this).attr("id") );
             var index = $(this).attr("id");
             alert("${history.get(index)}");
         });
 });
 $("#submit").click(function(e) {
 $("#showDialogMessage").hide();
  var xmlhttp;
     $("#submit").prop('disabled',true);
     alert("called");
        var url="rate?object="+${history.get(index)};
        if (window.XMLHttpRequest)
        {
            xmlhttp=new XMLHttpRequest();
        }
        else
        {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {

            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                $("#submit").removeAttr('disabled');
                document.getElementById("showPasswordMessage").innerHTML=xmlhttp.responseText;
                $("#showPasswordMessage").show();
            }
        }

        xmlhttp.open("GET", url, true);
        xmlhttp.send();
 });
});
5
  • What is the error ? Is it on the browser or server side ? Commented Apr 7, 2015 at 7:54
  • This is the error SyntaxError: illegal character rl="rate?object="+com.markEffy.aggregator.TransactionDetails@6e0bbea6; Commented Apr 7, 2015 at 8:53
  • where is this error? browser or at server? Update your question with complete information. Commented Apr 7, 2015 at 9:38
  • 1
    You cannot pass whole object (at least not w/o some additional code). Pass uid of the object and retrieve it in the controller. Commented Apr 7, 2015 at 10:18
  • @AleksandrM Definitely Sir! But i just wanted to ask you.. is it a nice idea to keep the entire list of history object in the session and then i can pass the index to the action class. Based on the index i can retrieve the required object from the history list (i.e history[index]) which is stored in the session. Commented Apr 8, 2015 at 5:17

1 Answer 1

1
 var url="rate?object="+${history.get(index)};

This is not a java question, this is javascript. The above line is the culprit

${history.get(index)}

is jsp code executing on the server and it fetches an object. What is printed is the toString() representation of the object (com.markEffy.aggregator.TransactionDetails@6e0bbea6). You probably should be accessing a property on the object

${history.get(index).someProperty}
Sign up to request clarification or add additional context in comments.

1 Comment

Sir i tried. In the action class it is giving null. Here is my code var url="rate?index="+index+"&rating="+rating+"&review="+review+"&transactionId"+ ${history.get(index).transactionId}; and in action class getter and setter for transactionId

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.