Question

In a Spring MVC application using hibernate, I am encountering an error when the user tries to specify the location (entity is FacilityAddress) of an appointment (entity is Encounter) using a JSP. Specifically, the property Encounter.location needs to be set by the JSP. The list of possible locations is given to the user by a model attribute praddrs, which is correctly populated in the JSP form by the GET method in the controller.

Can someone show me how to get this functionality to work properly without throwing an error?

I can create the 400 error when I add the following line of code to my JSP:

<form:select path="location" items="${praddrs}" size="3" style="min-width:200px"/>  

The 400 error states:

The request sent by the client was syntactically incorrect.  

There is no stack trace in the eclipse console.

I have read a number of other stack overflow postings on this, and have done google searches along with tinkering with my code, but I cannot seem to isolate the solution for my unique situation. Can someone show me how to get past this error?

Here is the form in the JSP:

<form:form modelAttribute="encounter" method="${method}" class="form-horizontal">
    <div class="control-group" id="patient">
        <label class="control-label">Patient </label>
        <c:out value="${encounter.patient.firstName} ${encounter.patient.lastName}"/>
    </div>
    <div class="control-group" id="datetime">
        <label class="control-label">Date and Time </label>
        <joda:format value="${encounter.dateTime}" style="SM"/>
    </div>

    <div class="control-group">
        <label class="control-label">Office</label>
        <form:select path="location" items="${praddrs}" size="3" style="min-width:200px"/>
    </div>

    <petclinic:inputField label="Duration (mins)" name="numMins"/>

    <td>
    </td>
    <div class="form-actions">
        <c:choose>
            <c:when test="${encounter['new']}">
                <button type="submit">Add Encounter</button>
            </c:when>
            <c:otherwise>
                <button type="submit">Update Encounter</button> <h3>    Link to delete will go here.</h3>
            </c:otherwise>
        </c:choose>
    </div>
</form:form>

Here is the controller method for handling the POST for this JSP:

//THIS IS THE METHOD THAT HANDLES THE FORM
@RequestMapping(value = "/patients/{patientId}/encounters/new", method = RequestMethod.POST)
public String processCreationForm(@ModelAttribute("encounter") Encounter encounter, @RequestParam("providerId") int providerId, BindingResult result, SessionStatus status) {
    System.out.println("inside processCreationForm() ");
    System.out.println("encounter.getDateTime() is: "+encounter.getDateTime());
    new EncounterValidator().validate(encounter, result);
    Provider myprovider = this.clinicService.findProviderById(providerId);
    encounter.addProvider(myprovider);
    if (result.hasErrors()) {
        System.out.println("about to return errors. ");
        return "encounters/createOrUpdateEncounterForm";
    } else {
        System.out.println("about to save encounter ");
        this.clinicService.saveEncounter(encounter);
        System.out.println("done saving encounter.");
        status.setComplete();
        System.out.println("finished status.setComplete()");
        return "redirect:/encounters?encounterID={encounterId}";
    }
}

For reference, the controller method for handling the JSP's GET is:

@RequestMapping(value = "/patients/{patientId}/encounters/new", method = RequestMethod.GET)
public String initCreationForm(@PathVariable("patientId") int patientId, @RequestParam("providerId") int prid, org.springframework.web.context.request.WebRequest webRequest, Map<String, Object> model) {
    Patient patient = this.clinicService.findPatientById(patientId);
    LocalDate theday = new LocalDate(webRequest.getParameter("day"));
    LocalTime thetime = new LocalTime(webRequest.getParameter("time"));
    DateTime thedatetime = theday.toDateTime(thetime);
    this.clinicService.findFacilityAddressByProviderId(prid);
    Encounter encounter = new Encounter();
    encounter.setDateTime(thedatetime);
    patient.addEncounter(encounter);
    ArrayList<FacilityAddress> praddrs = (ArrayList<FacilityAddress>) this.clinicService.findFacilityAddressByProviderId(prid);
    Provider pr = clinicService.findProviderById(prid);
    model.put("encounter", encounter);
    model.put("praddrs", praddrs);
    model.put("pr", pr);
    return "encounters/createOrUpdateEncounterForm";
}

I HAVE POSTED THE ENTITY CODE TO A FILE SHARING SITE SO THAT THIS POSTING CAN BE EASIER TO READ. You can read the entity code by clicking on the following links:

The Encounter entity code can be read at this link.
The FacilityAddress entity code can be read at this link.
The BaseEntity code can be read at this link.

No correct solution

OTHER TIPS

How about changing "location" to "location.id"?

<form:select path="location.id" items="${praddrs}" size="3" style="min-width:200px"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top