Announcement Announcement Module
Collapse
No announcement yet.
Ask for help, first experience with jquery and Ajax in connection with Spring MVC. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ask for help, first experience with jquery and Ajax in connection with Spring MVC.

    Hi profs,
    I've little experience in Spring MVC and no in Ajax. Before a form is submitted and the onsubmit-method of my controller should be called, the input of a date-binded field should be compared with a date property of another object. Here's the Ajax-Code of my jsp:

    function isNewMainCCAValidBeginAfterLatestMainCCAValidBegin () {
    var retVal = false;
    setWaitCursor();
    $.ajax({
    type: "POST",
    url: '<c:url value="/function/compareCostCenterAssignmentDates.do" />',
    data: { positionId: "${currentEntity.id}", costCenterId: "${mainCostCenterAssignmentWrapper.latestMainCostC enterAssignment.id}", comparingDate: $("#beginDate").val() },
    success: function(retVal) {
    },
    complete: function(){
    resetWaitCursor();
    },
    dataType: "json",
    async: false
    });
    return retVal;
    }

    And here's the code of my controller:

    @InitBinder
    public void initBinder(final WebDataBinder binder) {
    binder.registerCustomEditor(java.util.Date.class, DateFormatUtil.getCustomDateEditor(DateFormatUtil. DATE, true));
    }

    @RequestMapping(method = RequestMethod.POST)
    public String compareCostCenterAssignmentDates(@RequestParam("po sitionId") String positionId,
    @RequestParam("costCenterId") String costCenterId, @RequestParam("comparingDate") Date comparingDate, Model model) {
    boolean isDateAfterCCADate = false;
    Position position = positionDao.getPositionById(positionId);
    CostCenterAssignment costCenter = position.getCostCenterAssignmentById(costCenterId) ;
    if (comparingDate != null && comparingDate.after(costCenter.getValidBegin())) {
    isDateAfterCCADate = true;
    }
    model.addAttribute("retVal", isDateAfterCCADate);

    return "/function/COSTCENTER_ORG_DATA_STORE";
    }

    In the end the Ajax-Post should call the controller, which should return true/false to my function, which itself would use it as return value.

    Problem is: my controller is not called.
    Do you see the error. Could you explain what I've forgotten. I'm getting a little bit desperate at the moment.

    lg Xanatos84

  • #2
    don't take it as spam dear, i just comment here for your post answer. i have few problem with ajax. if any one reply your problem, i think he/she might be very helpful to me also. For that reason i comment here. Sorry for your disturbing.
    Last edited by saloman65; Sep 17th, 2011, 09:41 AM.

    Comment


    • #3
      Many things could happen:
      1. Does your controller map correctly a request when the form render? If not, check your xml or controller annotation.
      2.
      Code:
      url: '<c:url value="/function/compareCostCenterAssignmentDates.do" />'
      .
      In your case, you have to put whole path...
      If possible, post your configuration (*.xml ) or your controller annotation.

      Comment

      Working...
      X