Results 1 to 2 of 2

Thread: Redirect to show ModelAndView from another Controller???

  1. #1

    Default Redirect to show ModelAndView from another Controller???

    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.

    HttpRequestController
    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);
    HttpRequest and HttpResponse POJOs:
    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;
    	…..
    }
    I have an HttpResponse View (jspx) for ‘show’ and an unused HttpResponseController():
    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";
    		    }	  	
    	
    	}
    }
    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?

    I desperately need help. I’d be quite grateful for any pointers, any info or any suggestions. Please kindly help.
    Last edited by mtam; Jun 11th, 2010 at 09:44 AM.

  2. #2
    Join Date
    Jun 2010
    Posts
    2

    Default

    Maybe try using response.setRenderParameter("page", "events"), and then add @RenderMapping ("page=events") to the controller

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •