Announcement Announcement Module
Collapse
No announcement yet.
form - processSubmit Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • form - processSubmit

    I have contoller in which GET method creates a list(psUserUnitMbrExcpList) and add it to a model. Also I have @ModelAttribute("units") which is used for dropdown list in jsp form. In jsp user selects unit form drop down list(units and click submit. I tried few things with path it does not work. Right now it is "" <form:select path=""> .it displays view but when I select and click submit i get null pointer exception.Controller should able to do processing based on selected item.


    I am not able to retrive selectedItem in post method in controller.

    1) Controller

    @Controller
    @RequestMapping("/searchUnitMbrExceptionsForm.do")
    @SessionAttributes("psUserUnitMbrExcpList")
    public class SearchUnitMbrExceptions {

    private final Log logger = LogFactory.getLog(this.getClass());

    @Autowired
    private PsUnitService psUnitService;

    @Autowired
    private PsUserUnitMbrExcpService psUserUnitMbrExcpService;

    @ModelAttribute("units")
    public Collection<PsUnit> populateUnits() {
    return psUnitService.findAllPsUnits();
    }

    @RequestMapping(method = RequestMethod.GET)
    public String populateForm(ModelMap model) {
    List<PsUserUnitMbrExcp> psUserUnitMbrExcpList = psUserUnitMbrExcpService.findAllPsUserUnitMbrExcp( );
    model.addAttribute("psUserUnitMbrExcpList", psUserUnitMbrExcpList);
    return "browseUserUnitMbrExcps"; // view name
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processSubmit(@ModelAttribute("unit")PsUnit unit, BindingResult result, SessionStatus status, ModelMap model) {
    System.out.println("findUnitMbrExceptionsByUnitId" + " Unit:" + unit.getUnitKey() + unit.getUnitName());
    logger.info("findUnitMbrExceptionsByUnitId" + " Unit:" + unit.getUnitKey() + unit.getUnitName());
    List<PsUserUnitMbrExcp> psUserUnitMbrExcpList = psUserUnitMbrExcpService.findPsUserUnitMbrExcpByUn itKey(unit.getUnitKey().longValue());
    model.addAttribute("psUserUnitMbrExcpList", psUserUnitMbrExcpList);
    return "browseUserUnitMbrExcps"; // view name
    }
    }

    2) View

    <form:form modelAttribute="psUserUnitMbrExcpList" action="searchUnitMbrExceptionsForm.do">
    <table>
    <tr>
    <td><s:message code="label.searchForUnit"></s:message>:</td>
    <td>
    <form:select path="">
    <form:option value="0" label="--Select All Unit--"/>
    <form:options items="${units}" itemValue="unitKey" itemLabel="unitName"/>
    </form:select>
    </td>
    <td><p class="submit"><input type="submit" value="Submit"/></p></td>

    </tr>
    </table>
    </form:form>
    <a href="unitMbrExceptionForm.do"><s:message code="label.button.addMbrExcp"/></a>
    <table>
    <tr></tr>
    <thead>
    <th>&nbsp</th>
    <th>&nbsp</th>
    <th><s:message code="label.unitKey"></s:message></th>
    <th><s:message code="label.userKey"></s:message></th>
    <th><s:message code="label.effDate"></s:message></th>
    <th><s:message code="label.termDate"></s:message></th>
    <th><s:message code="label.exceptionDesc"></s:message></th>
    <th><s:message code="label.changedBy"></s:message></th>
    </thead>
    <tr></tr>
    <c:forEach var="execution" items="${psUserUnitMbrExcpList}">
    <tr>
    <td>
    <a href="unitMbrExceptionForm.do?unitKey=${execution. id.unitKey}&userKey=${execution.id.userKey}&effDat e=${execution.id.effDate}"><s:message
    code="label.button.edit"/></a></td>
    <td>
    <a href="unitMbrExceptionDelete.do?unitKey=${executio n.id.unitKey}&userKey=${execution.id.userKey}&effD ate=${execution.id.effDate}"><s:message
    code="label.button.delete"/></a></td>
    <td>${execution.id.unitKey}</td>
    <td>${execution.id.userKey}</td>
    <td>${execution.id.effDate}</td>
    <td>${execution.termDate}</td>
    <td>${execution.excpDesc}</td>
    <td>${execution.userChg}</td>
    </tr>
    </c:forEach>
    </table>

    3) It display view with dropdown and other list

    4) When I click submit

    java.lang.NullPointerException at com.hlite.prosurvhier.web.SearchUnitMbrExceptions. processSubmit(SearchUnitMbrExceptions.java:51)
Working...
X