My aim is to display customer info by costumer id by calling my strus2 action change of selectbox value.
My problem is: what should i return from my action class to get the value in json format
I tried the following code, but i don't know what is wrong with it
<script type="text/javascript">
$(function()
{ alert("This function is calling, on change event of selectbox and customer id="+$(this).val());
$("#customersjsonlstid").change(function(e)
{
$.ajax({
url: 'showCustomerInfoById.action', //action name
data: "customerid=" + $(this).val(),
dataType: "json",
success: function(data) {
// Set the inputs from the json object , json output : {"price": "123.40", "distributor": "XYZ Inc."}
$('#autocompleter_div_result1').val(data.distributor); //showing data on particular div
$('#autocompleter_div_result2').val(data.price); //showing data on particular div
}
});
});
});
</script>
Selectbox:
<sj:select
id="customersjsonlstid"
name="editionType"
href="%{customerJsonselecturl}"
list="lstcust"
listValue="name"
listKey="id"
autocomplete="false"
/>
<div id="autocompleter_div_result">`
struts.xml
<action name="showCustomerInfoById" class="v.esoft.actions.customerdetails.CustomerSelectAction" method="CustomerdetailsById">
<result name="success" type="json"/>
</action>
Action class
public class CustomerSelectAction extends ActionSupport {
private String customerid;
//---------------------------------------------------------
public String CustomerdetailsById()
{
System.out.print("--------Method called, customer id-----------"+customerid);
return customerid;
}
//---------------------------------------------------------
public String getCustomerid() {
return customerid;
}
public void setCustomerid(String customerid) {
this.customerid = customerid;
}
}