How exactly can I trigger display of a model and view from another model and view’s controller?
HTTP Request View --> HttpRequestController POST -> new HttpResponse POJO and a string of the POJO in XML as an Http Response msg to be sent back to the Requestor --> <what should I return from the POST handler?>
I have HttpRequestController() to handle a POST message with data from an input Form and populated an HttpRequest POJO with it. An HttpResponse POJO is composed and persisted along with the HttpRequest to a Db.
I made this HttResponse POJO an XML string as the @Responsebody to be sent back by the HttpRequestController() (as an actual HTTP Response message with header and body) and I want to present this HttpResponse POJO in a View.
I tried different things, none worked and I could not find a similar example anywhere.
HttpRequestControllerHttpRequest and HttpResponse POJOs:Code:public class HttpRequestController: //public @ResponseBody String createResponse(@Valid HttpRequest httpRequest, BindingResult result, ModelMap model) { public @ResponseBody ModelAndView createResponse(@Valid HttpRequest httpRequest, BindingResult result, ModelMap model) { if (httpRequest == null) throw new IllegalArgumentException("A HTTP Request Message is required"); httpRequest.setHttpResponse(httpRequest.createResponse()); if (httpRequest.getHttpResponse() == null) throw new IllegalArgumentException("Creation of the HTTP Response message failed!"); httpRequest.persist(); ModelAndView mav = new ModelAndView mav.addObject("HttpResponse", httpRequest.getHttpResponse()); model.addAttribute("httpresponse", httpRequest.getHttpResponse()); return mav; //return "redirect:/httpresponse/" + httpRspMsg1.getId(); //return httpRequest.httpRspMsg1; //return new ModelAndView("redirect:/httpresponse", "HttpResponse", httpRspMsg1); //return new ModelAndView("forward:/httpresponse", "HttpResponse", httpRspMsg1); //return new ModelAndView("/WEB-INF/views/httpresponse/show.jsp", "HttpResponse", httpRspMsg1);
I have an HttpResponse View (jspx) for ‘show’ and an unused HttpResponseController():Code:public class HttpRequest() { @Configurable @XStreamAlias("HttpRequest") @Entity public class HttpRequest { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; …. @OneToOne(cascade = CascadeType.ALL) @JoinColumn ( name = "rspId_fk", insertable = false, updatable=false) private HttpResponse httpResponse; // getter, setter } @Configurable @XStreamAlias("HttpResponse") @Entity public class HttpResponse { @Id @GeneratedValue(strategy = GenerationType.AUTO) private long id; ….. }
What should I return from the HttpRequestController().POST to trigger an HTTP Response message to be sent back and the data-sent-back to be shown on in an HTTP Response View?Code:@RequestMapping("/httpresponse/**") @Controller public class HttpResponseController { @RequestMapping(value="/httpresponse/{id}", method=RequestMethod.GET) public String show(@PathVariable("id") Long id, ModelMap modelMap) { if (id == null) throw new IllegalArgumentException("An Identifier is required"); modelMap.addAttribute("httpresponse", HttpResponse.findHttpRspMsg1(id)); return "httpresponse/show"; } } }
I desperately need help. I’d be quite grateful for any pointers, any info or any suggestions. Please kindly help.


Reply With Quote