开发者

Is there a Grails equivalent for the jsp form tags?

I have an (as yet) simple Spring 3 MVC web-app using JSP as the view technology. I am considering rewriting it in Grails before I get too far along.

One thing I like about Spring is the "form" tags provided in the spring-form.tld tag-library. Given a model property "myFormModel" with the "myProperty" property, this allows me to write something like: -

<form:form commandName="myFormModel">
    <form:input path="myProperty" cssErrorClass="error"/>

The key here is that the form:input tag automatically does all the binding to the property in the command object, so generating (roughly) in HTML: -

<form>
    <input type="text" name="myProperty" value="xyz"/>

Spring MVC开发者_如何学Python will bind the form parameters to the class and pass the object to the controller. Less to go wrong.

(Please excuse the JSP and HTML, it's indicative, possibly slightly incorrect)

As I understand the GSP form tags: -

<g:form name="myForm" url="[controller:'myController', action:'foo']">
    <g:textField value="${myFormModel.myProperty}" class="${...blah to select error}"/>
  1. I cannot specify a "path" attribute: I must manually generate the name. When the path becomes complex (say a property of a item from a list), this can become hairy and noisy.
  2. I cannot automatically specify both "normal" and "error" CSS classes: I must put EL into the <input> class attribute. Messy!

I must admit I am surprised that GSP is (what I consider) behind Spring, I thought it was all about making the obvious things simple and the hard things possible. Easy-to-read/implement forms would seem a no-brainer.

So, my questions: -

  1. am I missing something?
  2. should I (and can I) use the spring-form.tld in my GSP?

It makes me wonder what other gotcha's I will run into...


The beanFields plugin does everything the Spring form tags do and more. It makes working with forms about as concise as possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜