How can I use Spring MVC "form" tag instead of my "input" tags?

What I have:

I have a generic JSP page that is used throughout my application for displaying certain entities. The code that I am interested in goes like this:

<form:form modelAttribute="object"/>
    <core:forEach items="${sections}" var="section" varStatus="itemStat">
        <core:forEach items="${section.fields}" var="fieldDef">
            <form:input path="${fieldDef.fieldName}"/>                                        
        </core:forEach>
    </core:forEach>
<form:form>

For each section, and for each field in that section, I have an input having the path fieldName, which is what I want to display from each field.

What I want:

I would like instead of the input to be a simple text, like a label.

What I have tried:

I am most certain that I can do it somehow with <form:label> but I can't really make it work. Making a <form:label path="${fieldDef.fieldName}" /> just tells the browser for which field I need the label, but doesn't get the actual value from it.

I have also tried something like ${object.fieldDef.fieldName}, but in order for this to work I would have to first analyze the value of ${fieldDef.fieldName}, which would give me the name of the column, and then do a ${object.column}, but column being a variable I haven't been able to make this work in any way.

Alternative:

An alternative would be to just make the inputs as disabled and remove the border with CSS, but that would be a dirty way and from what I saw it is also tricky for IE different versions. I am sure that I can handle it directly.


I am a little intrigued by the fact that <form:input path="..."> puts into the input what it finds corresponding to that path (same goes for other form elements), but with label it works different.

So, what I want is basically simple, but I haven't managed to find a way. If someone could shed some light, that would be great. Thanks in advance !

Answers


You could look into the spring bind tag. I haven't tried using it before but this may work for you, in place of the input tag

<spring:bind path="fieldDef.fieldName">
 ${status.value}
</spring:bind>

reference: http://static.springsource.org/spring/docs/1.1.5/taglib/tag/BindTag.html


Instead of

<form:input path="${fieldDef.fieldName}"/>

use

<c:out value="${fieldDef.fieldName}"/>

It would display whatever value is there instead of creating a input field. Hope this helps you. Cheers.


Using the spring form tab, one option would be to use

<form:input disabled="true" path="${fieldDef.fieldName}"/>

To further make it not look like an input you could use CSS to style it to your preference.

Some css styles you could use:

background-color:#EEEEEE;border: 0px solid;

Update: You could look into the spring bind tag. I haven't tried using it before but this may work for you, in place of the input tag

<spring:bind path="fieldDef.fieldName">
     ${status.value}
</spring:bind>

Need Your Help

Get time difference with DST considered

c++ boost

I am using Boost.Date_time to get the time difference between two dates. I want the code to consider DST change as well during these days and give me the correct interval.