0
votes

in my form I have table to show some of customer data.user can click on row to see all of customer data.

<div class="container">
    <table class="table table-bordered" style="direction: rtl">
        <thead>
        <tr>
            <th style="text-align: center">customer name</th>
            <th style="text-align: center">customer ID</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${customers}" var="customer" varStatus="loop">
            <tr onclick="retrieveCustomer('${loop.index}')">
                <td id="id-${loop.index}">${customer.customerId}</td>
                <td>${customer.customerName}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>

<script>
    function retrieveCustomer(id) {
        debugger;
        $.ajax({
            url: "<%=request.getContextPath()%>/show_selected_customer",
            data: {customerId: $('#id-' + id).text()},
            type: "GET",

            success: function (response) {
            },
            error: function (xhr, status, error) {
                alert(error);
            }
        });
    };
</script>

and in my controller:

@RequestMapping(value = "/show_selected_customer", method = RequestMethod.GET)
public ModelAndView showSelectedCustomer(@RequestParam("customerId") String customerId) {
    Map<String, Object> model = new HashMap<>();
    Customer customer = coreService.getCustomer(customerId);
    model.put("customer", customer);

    return new ModelAndView("showCustomerData", model);
}

tiles:

<definition name="showCustomerData" extends="base.definition">
    <put-attribute name="title" value="customer data"/>
    <put-attribute name="content" value="/WEB-INF/jsp/show_customer_data.jsp"/>
</definition>

until now every thing work correctly. enter image description here

my problem is, it doesn't show show_customers.jsp page,and even I have no error in my log. what is my problem,Is because of ajax call? I did`t use @responsebody and want to show customers.jsp page with return modelandview. thank you

1
Can you show your Controller class defination?Arpit Aggarwal
@Controller public class AdminController { private final Logger logger = ..farhad

1 Answers

0
votes

Use the response body annotation and convert your entity to JSON and return it instead.