Tuesday, April 26, 2011

workaround for sitemesh decoration of servlet error

Reference : workaround for sitemesh decoration of servlet error

workaround filter :

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) 
 throws ServletException, IOException { 
        HttpServletRequest request = (HttpServletRequest)servletRequest; 
        request.removeAttribute("com.opensymphony.sitemesh.APPLIED_ONCE"); 
        filterChain.doFilter(servletRequest, servletResponse); 
} 

web.xml :

<filter> 
        <filter-name>clearSiteMeshAppliedOnce</filter-name> 
        <filter-class>ClearSitemeshAppliedOnceFilter</filter-class> 
</filter> 
<filter-mapping> 
        <filter-name>clearSiteMeshAppliedOnce</filter-name> 
        <url-pattern>*</url-pattern> 
        <dispatcher>ERROR</dispatcher> 
</filter-mapping>

Thursday, April 14, 2011

Damn easy Spring MVC complex object binding within collection

During the development of our web application using Spring MVC, we wanted to allow the modification of some data such as an Actor which has an id and a name. We didn't want to show the id, only the name.

The problem is how to bind back the modified name ? We tried using PropertyEditor but this is handy to transform some data to String and back. I searched the web but at last, I understood how to do that very easily.


<ul>
    <c:forEach items="${form.actors}" var="actor" varStatus="status">
        <li>
            <form:hidden path="actors[${status.index}].id" />
            <form:input path="actors[${status.index}].name" />
        </li>
    </c:forEach>
</ul>

Et voilĂ  !

The id is bound back to the Actor as the modified name.

Note : the actors collection must be a List or an Array.