Announcement Announcement Module
Collapse
No announcement yet.
What is the best view technology for use with Spring? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is the best view technology for use with Spring?

    What view technology currently has the best integration with spring? I have done mostly JSP/JSTL development, but I find the lack of good taglibs for Spring annoying. Do any of the other technologies have better support/integration?

    Are there any switchers here, going from JSP to Velocity or Freemarker? What is your experience? Did it make things easier?

    S.

  • #2
    What view technology currently has the best integration with spring
    Do you mean Spring MVC ? The support of different views is really consistent with Spring MVC thanks to its clean separation between model and views. I'm using JSP, tiles and pdf views and they are all fine. I like very much tiles support.
    I find the lack of good taglibs for Spring annoying
    I have to disagree with you. When I used to use struts I was really frustrated by the complexity of its taglib. It took me a lot of effort and time to learn it. Spring's taglib is really simple to use and straight forward. It's very useful when the pages are provided by a designer. You just have to add Sprnig's binding tags around the inputs without modifying them.

    Comment


    • #3
      I went from JSP to Velocity. I spent some time with PHP and Smarty and I can say that the Smarty guys must have come through Velocity themselves.

      I started with JSP because of all the Java stuff you could do in it, I left JSP because .... of all the Java stuff you could do in it.

      Velocity requires a very clean separation of Model and View, and spring supports this superbly. I can let the look-and-feel guys deal with the web UI and graphics and all that, we only have to talk about the objects I stuff into their pages.

      Comment


      • #4
        I'm currently switching to FreeMarker. I agree you can do too much with it (JSP). My JSPs ended up looking like tag-hell:

        Code:
        <?xml version="1.0" encoding="UTF-8"?>
        <jsp&#58;root version="2.0" xmlns&#58;jsp="http&#58;//java.sun.com/JSP/Page" xmlns&#58;c="http&#58;//java.sun.com/jsp/jstl/core" xmlns&#58;fmt="http&#58;//java.sun.com/jsp/jstl/fmt"
        xmlns&#58;spring="http&#58;//www.springframework.org/tags"
        xmlns&#58;input="urn&#58;jsptagdir&#58;/WEB-INF/tags/input">
        	<jsp&#58;directive.page contentType="text/html; charset=utf-8" pageEncoding="UTF-8"/>
        
        	<!-- Be sure URLs are rewritten -->
        	<c&#58;url var="submitUrl" value="/change-password.jspa"/>
        	<c&#58;url var="registerUrl" value="/register.jspa"/>
        	<c&#58;url var="closeAccountUrl" value="/close-accoount.jspa"/>
        
        	<fmt&#58;message var="buttonContinueLabel" key="button.continue.label" />
        	<fmt&#58;message var="title" key="page.css.passwordassistant.title"/>
        
        	<fmt&#58;message var="stepOne" key="label.step.label">
        		<fmt&#58;param value="1"/>
        		<fmt&#58;param><fmt&#58;message key="page.css.passwordassistant.step1.title"/></fmt&#58;param>
        	</fmt&#58;message>
        
        	<fmt&#58;message var="description" key="page.css.passwordassistant.step1.description"/>
        
        	<fmt&#58;message var="newAccountNote" key="page.css.passwordassistant.newaccountnote">
        		<fmt&#58;param value="$&#123;registerUrl&#125;"/>
        	</fmt&#58;message>
        	<fmt&#58;message var="closeAccountNote" key="page.css.passwordassistant.closeaccountnote">
        		<fmt&#58;param value="$&#123;closeAccountUrl&#125;"/>
        	</fmt&#58;message>
        
        	<html>
        		<head>
        			<title>$&#123;title&#125;&#58; <fmt&#58;message key="page.css.passwordassistant.step1.title"/></title>
        		</head>
        
        		<body id="selfservice">
        			<content tag="headinfo">
        				<h1>$&#123;title&#125; <span> <fmt&#58;message key="page.css.passwordassistant.step2.title"/></span></h1>
        				<h2>In order to shop at cdbuddy.de you need to create an account. <a href="#" title="TODO" class="more">Learn more</a></h2>
        			</content>
        
        			<c&#58;if test="$&#123;not empty status&#125;">
        				<div class="popin">
        					<div class="successmsg"><fmt&#58;message key="$&#123;status&#125;"/></div>
        				</div>
        			</c&#58;if>
        			<spring&#58;bind path="command.*">
        				<c&#58;if test="$&#123;status.error&#125;">
        					<div class="note">
        						<div>
        							<span class="error"><fmt&#58;message key="ume.err.ui.formerror"><fmt&#58;param value="$&#123;status.errors.errorCount&#125;"/></fmt&#58;message></span>*<a href="javascript&#58;void&#40;0&#41;" class="more" onclick="toggleVisibility&#40;'errordetails'&#41;">more</a>
        							<ul id="errordetails" style="display&#58;none;">
        								<c&#58;forEach items="$&#123;status.errorMessages&#125;" var="error">
        									<li>$&#123;error&#125;</li>
        								</c&#58;forEach>
        							</ul>
        						</div>
        					</div>
        				</c&#58;if>
        			</spring&#58;bind>
        
        			<h3>? $&#123;stepOne&#125;</h3>
        			<p>$&#123;description&#125;</p>
        			<form id="RequestPasswordChangeForm" method="POST" action="$&#123;submitUrl&#125;">
        				<dl><input&#58;text path="command.email" title="TODO" labelkey="ume.lab.youremail" required="false" size="30" maxlength="60"/></dl>
        				<input type="submit" name="continue" value="$&#123;buttonContinueLabel&#125;" /> to Step 2.
        			</form>
        
        			<p class="note">$&#123;newAccountNote&#125;*$&#123;closeAccountNote&#125;</p>
        		</body>
        	</html>
        
        </jsp&#58;root>
        Ugly, isn't it. Yeah, i started to create tag macros for JSP, but that makes it not much better

        It's also cool that I don't need yet another technology for mail-templates and I can easiely store my freemarker templates in the database if i'd need to. Having used Smarty intensively FreeMarker/Velocity is just sooooo good. I do not need to wait until my JSPs are compiled during development (that's a huge plus) and the View-Approach is much cleaner than with JSP.

        The ad hoc localization support of freemarker also shines. You can have your normal template say "main.ftl" and localized versions i.e. "main_de.ftl" and freemarker chooses them automatically based on the set locale (no need for localized views.properties, views_de etc..). That rocks. Little problem though, in case of parsing errors the exception messase always shows the root ftl file (i.e. error in main_de.ftl shows: error in line xy of main.ftl).

        The only thing i wish to have is the JSP taglib support the new freemarker has (i use displaytag quite a lot, so this would make it easier to switch).

        And, if you're working with a seperate design team: desingers understand the language of smarty or freemarker much better than XML. Strange - but that was almost everytime my experience.

        -andi

        Comment


        • #5
          Re: What is the best view technology for use with Spring?

          Originally posted by Stefan Arentz
          ... but I find the lack of good taglibs for Spring annoying.
          There are some jsp 2.0 tag macros that are in development right now which are more like struts tags and reduce the amount of code in your jsps.

          See:
          http://opensource.atlassian.com/proj...browse/SPR-310
          http://forum.springframework.org/viewtopic.php?t=2656

          Comment


          • #6
            Yes, but the for FreeMarker there are also some tags. And writing your own set is easy. And they're much more readable. i.e. the JSP above uses a quick and dirty written input tag (<input:text ../>):

            JSP:
            Code:
            <?xml version="1.0" encoding="UTF-8"?>
            <jsp&#58;root version="2.0" xmlns&#58;jsp="http&#58;//java.sun.com/JSP/Page" xmlns&#58;c="http&#58;//java.sun.com/jsp/jstl/core" xmlns&#58;fmt="http&#58;//java.sun.com/jsp/jstl/fmt">
            	<jsp&#58;directive.page contentType="text/html; charset=utf-8" language="java"/>
            
            	<jsp&#58;directive.attribute name="path" required="true"/>
            	<jsp&#58;directive.attribute name="title" required="true" />
            	<jsp&#58;directive.attribute name="labelkey" required="true" />
            	<jsp&#58;directive.attribute name="required" required="true" type="java.lang.Boolean"/>
            	<jsp&#58;directive.attribute name="size" required="true" type="java.lang.Integer"/>
            	<jsp&#58;directive.attribute name="maxlength" required="true" type="java.lang.Integer"/>
            
            	<spring&#58;bind path="$&#123;path&#125;" xmlns&#58;spring="http&#58;//www.springframework.org/tags">
            		<jsp&#58;element name="dt">
            			<jsp&#58;body>
            				<label for="$&#123;status.expression&#125;" title="$&#123;title&#125;"><fmt&#58;message key="$&#123;labelkey&#125;"/><c&#58;if test="$&#123;required eq true&#125;"><em>*</em></c&#58;if><c&#58;if test="$&#123;!required eq true&#125;">&#58;</c&#58;if></label>
            				<c&#58;if test="$&#123;status.error&#125;">*
            					<c&#58;forEach items="$&#123;status.errorMessages&#125;" var="error">
            						<em>$&#123;error&#125;</em><br />
            					</c&#58;forEach>
            				</c&#58;if>
            			</jsp&#58;body>
            		</jsp&#58;element>
            		<jsp&#58;element name="dd">
            			<jsp&#58;body>
            				<input type="text" size="$&#123;size&#125;" maxlength="$&#123;maxlength&#125;" title="$&#123;title&#125;" id="$&#123;status.expression&#125;" name="$&#123;status.expression&#125;" value="$&#123;status.value&#125;" />
            			</jsp&#58;body>
            		</jsp&#58;element>
            	</spring&#58;bind>
            </jsp&#58;root>
            The same thing in Freemarker looks like this:
            Code:
            <#import "/spring.ftl" as spring />
            
            <#macro text path,labelkey,required,title,size,maxlength>
            	<@spring.bind path/>
            	<dt>
            		<label for="$&#123;spring.status.expression&#125;" title="$&#123;title&#125;"><@spring.message labelkey/><#if required==true><em>*</em></#if></label>
            		<#list spring.status.errorMessages as error>
            			<em>$&#123;error&#125;</em><br/>
            		</#list>
            	</dt>
            	<dd><input type="text" size="$&#123;size&#125;" maxlength="$&#123;maxlength&#125;" title="$&#123;title&#125;" id="$&#123;spring.status.expression&#125;" name="$&#123;spring.status.expression&#125;" value="$&#123;spring.status.value&#125;" /></dd>
            </#macro>
            There's certainly a difference in readability and amount of code

            And you can put more than one tag in one file. But really, the main benefit of using FreeMarker here is performance (at least during develpment). It really sucks to wait 30 seconds or more if your container starts compiling 30 tags or so. With FM it's there with almost no delay.

            I used JSPs exclusively, but I'm sold on FreeMarker now and only use JSP if some requirement (or marketing) dictates it.

            -andi

            Comment


            • #7
              Has anyone tried Cold Fusion?

              Right now we're a Cold Fusion shop. I'd like to start moving us toward a Java platform, if only to boost performance and get better automated testing.

              But I'm not sure the company would drop CF to do it. A complete re-write is not realistic right now, so there would have to be a period (could be forever) of coexistence/collaboration.

              Since it's Java-based and can call Java objects directly, I wondered if anyone had ever tried it with Spring?

              Or if anyone's switched from CF to Spring, I'm curious to hear about the experience.

              Thanks
              Scott

              Comment

              Working...
              X