2

In a browser I have a box where I can enter multiple inputs something like PQRS-CD-12345(PQRS-CD come by default only the numbers 12345 keep changing) separated by a comma. When I click on enter it should say successfully submitted.

The problem is that I can see a success message only when I enter values like below PQRS-CD-12345,PQRS-CD-56478,PQRS-CD-75631 (without any spaces after comma).

If I enter something like PQRS-CD-12345, PQRS-CD-86452, PQRS-CD-22551(with enter and spaces between values) it then gives me an error message saying that:

An unknown error has occurred. Message:org.springframework.dao.EmptyResultDataAccessException: No entity found for query No entity found for query.

My current part of code is

@PreAuthorize("hasAnyRole('jobdetail_admin')")
    @RequestMapping(value="/hub/showBulkResendPage")
    public ModelAndView showBulkResendPage(HttpServletRequest request, HttpServletResponse response)

    {
        ModelMap map = new ModelMap();
        map.put("maxLimitOrdTextarea", maxLimitOrderTextarea);

        return new ModelAndView("bulkResend", map);
    }

    @PreAuthorize("hasAnyRole('jobdetail_admin')")
    @RequestMapping(value="/hub/bulkResendStatus")
    public ModelAndView bulkResendStatus(HttpServletRequest request, HttpServletResponse response) throws ServletRequestBindingException
    {
         String successView = "redirect:/ipod/hub/searchOrderOrJob";
         ***String[] prtrOrdLocs = ServletRequestUtils.getRequiredStringParameter(request, "prtrOrdLocs").split(",");*** (i added this part commenting the below line)
         // String[] prtrOrdLocs = request.getParameter("prtrOrdLocs").split(","); 

        System.out.println(prtrOrdLocs);
        ModelAndView modelAndView = null;

        ModelMap map = new ModelMap();

        try 
        {
            for(String orderLocator : prtrOrdLocs)
            {
                orderLocator = orderLocator.replaceAll("[\\n\\s]", ""); // i added this line
                orderService.resendStatus(orderLocator);
            }
            map = new ModelMap();
            map.put("success", "resendstatus.hub.success");
            modelAndView = new ModelAndView(successView, map);    
        } 
        catch(IPODException e) 
        { e.printStackTrace();
            modelAndView = handleException(e,"resendstatus.hub.error");         
        } 
        catch(Exception e)
        {
            e.printStackTrace();
        }

        return modelAndView;
    }

In spite of adding those new lines I still get the same output. Can anyone help me?

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<head>
<script type="text/javascript">
setupValidateBulkResendTextbox();
</script>
<link rel="stylesheet" type="text/css" href="/css/menuItem-utilities.css" />
</head>
<%@include file="/jsp/layout/submenu-utilities.jsp"%>
<div id="main-content">
<h2>Bulk Resend Status</h2>
<div align="center">
<div align="center" class="errortxt" id="error-message">${usermsg}</div>
<div align="center" id="success-message">${success}</div>
<sec:authorize access="hasAnyRole('jobdetail_admin')" >
<form name="formBulkResendPrtrOrdLocator" id="formBulkResendPrtrOrdLocator" action="/ipod/hub/bulkResendStatus" method="post">
Enter valid, distinct partner order locator IDs separated by commas:
<br /><input type="hidden" name="maxLimitOrdTextarea" value="${maxLimitOrdTextarea}" /> 
<textarea id="prtrOrdLocs" name="prtrOrdLocs" rows="20" cols="40" /></textarea><br />
<div id="errors" class="errortxt"></div>
<input type="submit" value="Bulk Resend" class="inputbutton" />
</form>
</sec:authorize>
</div>
</div>
  • I suspect your data is not being sent to the server in a standard way. Can you show the HTML/Javascript of the form and what happens when the submit button is clicked? – RealSkeptic Jun 27 '15 at 15:47
  • Not in the comments, please add it to your question. – RealSkeptic Jun 27 '15 at 15:52
  • i have added the javascript in the question and when the submit button is clicked this page is displayed searchOrderOrJob?success=resendstatus.hub.success – Harika Garikapati Jun 27 '15 at 16:16

1 Answers1

0

Change orderLocator = orderLocator.replaceAll("[\\n\\s]", "");

with orderLocator = orderLocator.replaceAll("\\s","");

Alternatively you can also give .replaceAll("\\s+", ""); a shot!

More about removing whitespaces here

Community
  • 1
  • 1
Sudhansu Choudhary
  • 3,322
  • 3
  • 19
  • 30