Announcement Announcement Module
Collapse
No announcement yet.
How to change from rendering a fragment in tiles with ajax to a whole new error page? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to change from rendering a fragment in tiles with ajax to a whole new error page?

    Hi all!

    I have a question about error handling with Spring MVC, Tiles and SpringJS. I have some pages that have fragments to be reloaded using ajax calls. That is working fine, the problem is I want to change that behaviour when an error is thrown.
    I have defined a HandlerExceptionResolver which intercepts every exception and redirect to the correct error page. If the exception occurs in a RequestMapping call within Spring MVC this is working fine but I can't make it work with ajax calls because it just tries to render the page inside the fragment is told to in the first place.
    This is my code:

    servlet-context.xml. Here I define the tiles view resolver and the exception handler among other things. The view resolver has some caching code inside, that's why it's extended by another class. Maybe I could put something here to get the behaviour I want?

    Code:
    <bean id="viewResolver"    class="com.bbvacompass.monarch.web.servlet.view.custom.CustomAjaxUrlBasedViewResolver">
    		<property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView" />
    		<property name="mappings" ref="custom-redirect-views"/>
    </bean>	
    
    <bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    	<property name="definitions">
    		<list>
    			<value>/WEB-INF/**/tiles.xml</value>
    			<value>classpath*:/WEB-INF/**/*.tiles.xml</value>
    		</list>
    	</property>
    </bean>
    
    <bean class="com.bbvacompass.monarch.web.servlet.interceptor.CustomHandlerExceptionResolver"/>
    This is the jsp where the call is made

    Code:
    <form id="tfilter" action="<c:url value="/custom/summary/postedTransactions" />" >
    	<label id="lposted" for="posted" class="checked"><fmt:message key="account_summary.custom.posted" />  </label>
    	<input type="radio" id="posted" name="table_type" />
    	<label id="lpending" for="pending"><fmt:message key="account_summary.custom.pending" /></label>
    	<input type="radio" id="pending" name="table_type" />
    	<input type="hidden" name="transfersType" id="transfersType" >
    	<input type="hidden" name="selected_account" id="selected_account">
    </form>
    					
    <script type="text/javascript">
    	Spring.addDecoration(new Spring.AjaxEventDecoration({elementId: "posted" ,event:"onclick",formId:'tfilter',params: { fragments: "transactions"}}));
    	Spring.addDecoration(new Spring.AjaxEventDecoration({elementId: "pending",event:"onclick",formId:'tfilter',params: { fragments: "transactions"}}));
    </script>
    					
    <form id="select_actions" action="<c:url value="/custom/summary/updateSlider" />">
    	    <select id="s_actions">
    	    	<option value="0"><fmt:message key="account_summary.custom.actions" /></option>
    	        <option id="option1" value="within"><fmt:message key="account_summary.custom.action.transfer.within" /></option>
    	        <option id="option2" value="between"><fmt:message key="account_summary.custom.action.transfer.between" /></option>
    	        <option id="option3" value="billpay"><fmt:message key="account_summary.custom.action.billpay" /></option>
    	        <option id="option4" value="simple_payments"><a href="<c:url value="/popMoney?origin=popMoneyMenu"/>"><fmt:message key="account_summary.custom.action.simple" /></a></option>
    	        <option id="option5" value="download"><fmt:message key="account_summary.custom.action.download" /></option>
    	    </select>
    </form>
    
    <tiles:insertAttribute name="transactions" />
    This is the tiles.xml
    Code:
    	<definition name="summary-body" template="/WEB-INF/views/custom-monarch/account-summary/account-summary.jsp" >
    		<put-attribute name="script" value="/WEB-INF/views/custom-monarch/account-summary/script-account-summary.jsp" />
    		<put-attribute name="slider" value="/WEB-INF/views/custom-monarch/account-summary/slider.jsp" />
    		<put-attribute name="search" value="/WEB-INF/views/custom-monarch/account-summary/search.jsp" />
    		<put-attribute name="transactions" value="/WEB-INF/views/custom-monarch/account-summary/transactions.jsp" />
    	</definition>
    The mapping for the /custom/summary/postedTransactions uri now just throws an exception
    Code:
    @RequestMapping(value="/postedTransactions", method={RequestMethod.GET})
    	public String getPostedTransactions(HttpServletRequest request, ModelMap model,
    @ModelAttribute("iteProfile") String iteProfile,
    @ModelAttribute("searchForm") SearchCmd searchForm,
    @ModelAttribute("selectedAccount")AccountListAdapterBean selectedAccount) throws Exception{
          throw new Exception("asdfdsafsdf");
    }
Working...
X