开发者

Read-only (print) version of JSP form using Spring 2.0.x and form tags?

Is there a way to easily create a readonly version of JSP form in Spring?

i.e., I have a command object that's filled and if I show it as a form it works great, all the selects and radiobuttons get bound properly. However, my command object only holds id's of properties, not labels (i.e. and id from a select or a radiobutton list that gets bound on JSP load).

What I'd like to do is make a read only version where there'd be just a label - value list, without html objects such as inputs, selects and such.

So basically, in an edit version, there'd be something like

<form:select path="type.id" id="type">
    <form:options items="${types}" itemLabel="name" itemValue="id"/>
</form:select>

but in the read only version I'd like to be able to automatically print only the exact type.name that got selected, i.e.

<c:out开发者_如何学运维 value="${commandName.type.name}"/>

Is there such a possibility, or do I have to mess with this in controller?


Ok so I guess there's no elegant way of matching IDs and values from model with IDs in command. Instead of doing extra work in controller, I matched the IDs on JSP, i.e.

<c:forEach var="type" items="${types}">
    <c:if test="${type.id == commandName.type.id}">
        <c:out value="${type.name}"/>
    </c:if> 
</c:forEach>

It's a bit extra work, but I'd rather do this than have a number of iterations over a List in my controller.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜