0

I have the jsp code as :

    <s:url value="add" var="addUrl"/>
    <form:form name="add" action="${addUrl}" modelAttribute="content" method="post">
        <input type="hidden" name="add" value="" />
        <form:select path="id" class="dClass" onchange="submit()">
        <form:options items="${list}" /></form:select>
        <input type="submit" class="btn" value="Refresh Content" />
   </form:form>

And I have one controller method for both this call, is there any way to differentiate that from where the form is submitted? Either from the drop down or from the submit button?

@RequestMapping(value = "/add", method = RequestMethod.POST)
    public String getContentById(Model model, String id,Content content,HttpServletRequest request) {

if(call by onChange)

else if(call by submit button)

}
Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
Arpan Das
  • 1,015
  • 3
  • 24
  • 57
  • you have to make some unique sign to differentiate them, like add extra post param to `onchange()` – farmer1992 Nov 06 '13 at 08:22
  • how to add post param here? as i cant call the submit from javascript. because my controller returns a tiles name to render, and i dont have the ajax based view resolver for tiles in my project – Arpan Das Nov 06 '13 at 11:47
  • I mean change js of `submit()`. add something in the function. – farmer1992 Nov 06 '13 at 11:50
  • but i dont have any submit() function in my .js file, its calling the default sumbit() method. – Arpan Das Nov 06 '13 at 11:58

2 Answers2

1

Kindly note that, onchange="submit()" will not submit your page. It will look for the function with name submit. Inside that function you can use code like this $('form#form_id').submit(); to submit. Check submit-a-form-using-jquery for more details.

Community
  • 1
  • 1
Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
0

@Vinoth Krishnan Thanks for your answer , its working now :) added a filed in my form as "dropDownSubmit"

function submitForm(formId){
        var input = $("<input>").attr("type", "hidden").attr("name", "dropDownSubmit").val("true");
        $("#" + formId).append($(input));
        $("#" + formId).submit();
    }

Then in controller:

if("true".equalsIgnoreCase(form.getDropDownSubmit()){
 ..
}
else{
 .. button submit
}
Arpan Das
  • 1,015
  • 3
  • 24
  • 57