Struts 2 plugin <s:submit> render html expression in label

2k views Asked by At

I'm trying to render a submit button using HTML modifier tags

in ApplicationResources.properties file

label.ok=<u>O</u>K

then my JSP code is

<s:form class="form-group " method="POST" id="profileform" theme="bootstrap" cssClass="form-horizontal" action="go.asociate.addactivities.action">
......
    <div class="row">
        <div class="col-md-12 btn-toolbar">
            <button type="button" class="btn btn-default pull-right custombtn" accesskey="c" onclick="javascript:location.href='go.home.action';">
                <s:text name="label.cancel"></s:text>
            </button>
            <s:submit class="btn btn-default pull-right custombtn" accesskey="o" key="label.ok"></s:submit>
        </div>
    </div>
</s:form

The problem is that it renders literal key name value <u>O</u>K in the submit button. Does anybody know the right syntax to resolve this issue?

1

There are 1 answers

0
Andrea Ligios On BEST ANSWER

To use HTML in a submit button, it needs to be of type "button", because buttons have a body, while <input type="submit" /> don't;

<s:submit type="button" value="%{getText('label.ok')}" />

But this is not enough; it will be translated to

<button value="&lt;u&gt;O&lt;/u&gt;K" type="submit">
    &lt;u&gt;O&lt;/u&gt;K
</button>

because of the inbuilt escaping.

While in <s:property /> you can disable it by setting escapeHtml="false", <s:submit /> don't provide this option;

to workaround it, simply use <s:text /> in the body of the button:

<s:submit type="button">
    <s:text name="label.ok" />
</s:submit>

It is most likely the only way, but it will work, and will be trasnlated into

<button value="Submit" type="submit">
    <u>O</u>K
</button>