Note that there are some explanatory texts on larger screens.

plurals
  1. POHandling empty parameter from JSP view to a controller
    primarykey
    data
    text
    <p>I have a view that I want to use to display patient encounters selected from a range of two given date startDate an End date and display the result on the same page,however, I want to also when the page is loaded for the first time,to display all the result on that same page. As I am getting parameters from the request in my method,when the page is loaded for the first time,it throwing an empty params exception since the argument of those parameters ,startDate and End Date are empty when the page is loaded for the first time...here is my view</p> <pre><code>&lt;%@ include file="/WEB-INF/template/include.jsp"%&gt; &lt;%@ include file="/WEB-INF/template/header.jsp"%&gt; &lt;%@ include file="template/localHeader.jsp"%&gt; &lt;p&gt;Hello ${user.systemId}!Add Interface Implementation Code Here&lt;/p&gt; &lt;form action="/module/practicalexercise/manage" method="GET"&gt; From Date:&lt;openmrs_tag:dateField formFieldName="startDate" startValue=""/&gt; To Date:&lt;openmrs_tag:dateField formFieldName="endDate" startValue="" /&gt; &lt;br/&gt;&lt;input type="submit" value="Submit"&gt; &lt;/form&gt; &lt;br/&gt; &lt;b&gt;Total :${resultCount}&lt;/b&gt; &lt;br/&gt; &lt;b&gt;EncounterType Breakdown&lt;/b&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;#&lt;/th&gt;&lt;th&gt;Encounter Type&lt;/th&gt;&lt;th&gt;Total&lt;/th&gt;&lt;/tr&gt; &lt;c:forEach items="${EncTypeMap}" var="entry" varStatus="var"&gt; &lt;tr&gt;&lt;td&gt;&lt;c:out value="${var.count}" /&gt;&lt;/td&gt;&lt;td&gt;${entry.key}&lt;/td&gt; &lt;td&gt; ${entry.value}&lt;/td&gt; &lt;/tr&gt; &lt;/c:forEach&gt; &lt;/table&gt; &lt;%@ include file="/WEB-INF/template/footer.jsp"%&gt; </code></pre> <p>here is my controller</p> <pre><code>package org.openmrs.module.practicalexercise.web.controller; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.openmrs.EncounterType; import org.openmrs.Encounter; import org.openmrs.api.EncounterService; import org.openmrs.api.context.Context; import org.springframework.stereotype.Controller; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; @Controller public class PracticalExerciseManageController { protected final Log log = LogFactory.getLog(getClass()); @RequestMapping(value = "/module/practicalexercise/manage", method = RequestMethod.GET) public void manage(@RequestParam("startDate") String startDate,@RequestParam("endDate") String endDate,ModelMap model) { EncounterService encounterService = Context.getEncounterService(); SimpleDateFormat format = new SimpleDateFormat("dd MM YYYY "); Date from=null; Date to=null; try { from=format.parse(startDate) ; to = format.parse(endDate); } catch (ParseException e) { e.printStackTrace(); } List&lt;Encounter&gt; encounters = encounterService.getEncounters(null, null, from, to, null, null, null,true); List&lt;EncounterType&gt; encounterTypes = encounterService.getAllEncounterTypes(); Map&lt;String,Integer&gt; countMap=new HashMap&lt;String,Integer&gt;(); for(EncounterType encType:encounterTypes){ int encTypeCount=0; for(Encounter encounter:encounters){ if(encounter.getEncounterType().getId().equals(encType.getId())) encTypeCount++; } countMap.put(encType.getName(), encTypeCount); } model.addAttribute("user", Context.getAuthenticatedUser()); model.addAttribute("EncTypeMap", countMap); model.addAttribute("size", countMap.size()); model.addAttribute("resultCount",encounters.size()); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload