spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.64k stars 38.14k forks source link

New spring:nestedPath Tag [SPR-220] #4951

Closed spring-projects-issues closed 20 years ago

spring-projects-issues commented 20 years ago

Seth Ladd opened SPR-220 and commented

For the form simplification macros, a new tag will be needed. This new tag, , allows for simplification of creating JSTL pages. It will allow for easy including of common JSP Fragments without knowledge of the actual bean, or child bean, that the properties are from.

For example, common elements such as Address fields, may be isolated inside a JSP Fragment. This allows for any page to include the file and to display address fields.

The including page would wrap the include with a tag to declare what bean, or child bean, the include's properties are from.

The tag will need to be updated to optionally understand if it's being used inside the tag to append the nestedPath variable to the field being bound.

The example below details a full JSP 2.0 Taglib implementation of and the edited , plus a form simplication macro. It's assumed that the final version of would be a Java class, and the modifications would be made to the Java class.

Example:


address_include.jspf

\

\ \ \
\
\ \ \



new_account.jsp

\

\ \ \
\
\ \<%@ include file="/WEB-INF/jspf/address_include.jspf" %> \</spring:nestedPath> \



text.tag (referenced from address_include.jspf)

<%@ tag body-content="empty" dynamic-attributes="dynattrs" %> <%@ attribute name="name" required="true" %> <%@ include file="/WEB-INF/jspf/taglibs.jspf" %>

${a.key}="${a.value}" /> --- --- springx:bind.tag (understands the nestedPath if it exists) <%@ tag body-content="scriptless" %> <%@ attribute name="path" required="true" %> <%@ include file="/WEB-INF/jspf/taglibs.jspf" %> --- --- **Affects:** 1.1 RC2 **Attachments:** - [nested_tag_tests.patch](https://jira.spring.io/secure/attachment/10151/nested_tag_tests.patch) (_6.43 kB_) - [nested_tag.patch](https://jira.spring.io/secure/attachment/10150/nested_tag.patch) (_6.86 kB_)
spring-projects-issues commented 20 years ago

Seth Ladd commented

The new nested tag + tld modifications page. Plus, modification to bind tag.

spring-projects-issues commented 20 years ago

Seth Ladd commented

The tests.

spring-projects-issues commented 20 years ago

Seth Ladd commented

The patches have been tested with the unit tests, plus with modification to the webapp-minimal:

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

If you're seeing this, your minimal Spring web application was deployed successfully!

\

The time is now <%=new java.util.Date()%>. --- and --- public ModelAndView handleRequest( HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Test t = new Test(); t.setName("HELLO, WORLD"); Test t2 = new Test(); t2.setName("HELLO, WORLD AGAIN"); BindException errors = new ServletRequestDataBinder(t, "tb").getErrors(); BindException errors2 = new ServletRequestDataBinder(t2, "tb2").getErrors(); Map model = new HashMap(); model.put(BindException.ERROR_KEY_PREFIX + "tb", errors); model.put(BindException.ERROR_KEY_PREFIX + "tb2", errors2); return new ModelAndView("/test.jsp",model); }
spring-projects-issues commented 20 years ago

Juergen Hoeller commented

Finally, we have a nestedPath tag :-) Thanks for the patch, Seth! Now, let's think about JSP 2.0 input tag files for 1.1 final...

Juergen