Announcement Announcement Module
No announcement yet.
How can I use Spring MVC “form” tag instead of my “input” tags? (JSP page) Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • How can I use Spring MVC “form” tag instead of my “input” tags? (JSP page)

    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}"/>                                        
    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.


    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 !

  • #2
    I have managed to solve it using <spring:bind>. Thank you anyway!