Search code examples
javajqueryspringdatatables

Exception: org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'params' is not present


When i clicked the edit button the values from dataTable should display in form. But somehow it doesn't work. Below are my codes for reference.

Call DataTable:

$("#tranTable").on("click", "#edit", function(){
    var row = $(this).closest("tr");

    $("#Own-Account").removeClass("hidden");
    $("fieldset#addToListMethod").addClass("hidden");
    $("fieldset#Own-Account #templateTrxId").val( row.find("[name$=templateTrxId]").val() )
    $("fieldset#Own-Account #templateId")   .val( row.find("[name$=templateId]").val() )
    $("fieldset#newFT #fromAccNo")          .val( row.find("[name$=fromAccNo]").val() ), 
    $("fieldset#newFT #methodOfTransfer")   .val( row.find("[name$=methodOfTransfer]").val() ), 
    $("fieldset#Own-Account #toAccNo")      .val( row.find("[name$=toAccNo]").val() ), 
    $("fieldset#Own-Account #paymentRef")   .val( row.find("[name$=paymentRef]").val() ),
    $("fieldset#Own-Account #amount")       .val( row.find("[name$=amount]").val() ),

    //hidden
    $("fieldset#Own-Account #otherPaymentDetail").val( row.find("[name$=otherPaymentDetail]").val() ),
    $("fieldset#Own-Account #email1").val( row.find("[name$=email1]").val() ),          
    $("fieldset#Own-Account #email2").val( row.find("[name$=email2]").val() ),
    $("fieldset#Own-Account #sms1").val( row.find("[name$=sms1]").val() ),
    $("fieldset#Own-Account #sms2").val( row.find("[name$=sms2]").val() ),
    $("fieldset#Own-Account #purpose").val( row.find("[name$=purpose]").val() )
    $("fieldset#Own-Account #isEdit").val(1);
    $("fieldset#Own-Account #dataTableRowId").val(row.data("row-id"));


});

Solution

  • From the exception, your problem likely occurs because the @RequestMapping doesn't find the parameter being sent from previous the page.

    In this case, it is likely like this:

    @RequestMapping(value = "/check")
    public String getID(@RequestParam(value = "params") String params){
    //your logic code here
    }
    

    From here, the exception occurs when the @RequestMapping doesn't find "params":

    @RequestParam(value = "params") String params
    

    This happens because, by default, @RequestParam tries to get the value. It then returns an exception when the value is not found.

    So you have two ways to resolve this,

    1. You can supply the URL /check with a params variable or,

    2. You can change the @RequestParam requirement to false like this:

      @RequestParam(value = "params", required = false) String params

    Take note that this is an example to reflect your scenario and problem. Gud luk.