Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC Form static text

Tags:

java

forms

spring

I'm trying to make form with Spring MVC for editing some object. Some fields of this object are set at the moment of creation and then can not be edited, so they must be shown on editing form like plain text, not like an input. I was very suprised when I didn't find smth like spring:output in spring forms tag library. How can do it? Please help :) Here is the code of my form:

    <?xml version="1.0" encoding="UTF-8" ?>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
    <%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
    <%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
    <%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>

    <h1><spring:message code="Information" /></h1>

    <form:form commandName="shop" method="POST">
        <table>
            <tr>
                <td><spring:message code="ShopCompanyName"/>
                <td colspan="2">**HERE MUST BE A STATIC TEXT 
FILLED WITH THE VALUE OF SOME FIELD FROM OBJECT**</td>
            </tr>
            <tr>
                <td colspan="3"><h2><spring:message code="Contacts"/></h2></td>
            </tr>
            <tr>
                <td><spring:message code="ShopUserLN"/></td>
                <td><form:input path="user.lastName"/></td>
                <td><form:errors path="user.lastName" cssClass="error"/></td>
            </tr>
            <tr>
                <td><spring:message code="ShopUserFN"/></td>
                <td><form:input path="user.firstName"/></td>
                <td><form:errors path="user.firstName" cssClass="error"/></td>
            </tr>
            <tr>
                <td><spring:message code="ShopUserMN"/></td>
                <td><form:input path="user.middleName"/></td>
            </tr>
            <tr>
                <td><spring:message code="ShopUserPhone"/></td>
                <td><form:input path="user.phone"/></td>
                <td><form:errors path="user.phone" cssClass="error"/></td>
            </tr>
        </table>
        <input type="submit" value="Save">
    </form:form>
like image 393
vmk_student Avatar asked Feb 24 '26 16:02

vmk_student


1 Answers

<c:out value="${someObject.someProperty}"/>

Or even

${someObject.someProperty} 

if XML-escaping is not necessary.

like image 180
JB Nizet Avatar answered Feb 26 '26 08:02

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!