Pigueiras
Pigueiras

Reputation: 19356

How can I put a placeholder in a struts2 textfield tag?

I'm using struts2 tags and want to put a placeholder in a <s:textfield> tag like this:

<s:set name="email" value="getText('email')" />
...

<s:form action="Login">
    <s:textfield key="email" theme="simple" placeholder="%{email}" 
         cssClass="span3"/>
    ...
</s:form>

email is defined in global.properties as "Correo electrónico" .

My problem is that when I see the jsp page, instead of seeing the value of email I see %{email}.

I read that it was a bug of Struts2 solved in version 2.3.1 here: https://issues.apache.org/jira/browse/WW-3644, but I'm using Struts2 2.3.4 and I keep having the same problem.

Anyone knows any solution to this problem or any other way for putting the placeholder in the textfield?

Upvotes: 4

Views: 13811

Answers (2)

javiercbk
javiercbk

Reputation: 470

I had the same problem and I solved it like this:

<s:textfield name="user.email" placeholder="%{getText('settings.email')}" />

I needed up update both my Struts 2 and OGNL jars. My OGNL jar is ognl-3.0.5.jar.

Upvotes: 17

Dave Newton
Dave Newton

Reputation: 160261

You should be using the # prefix for variables created in the stack namespace but not pushed:

<s:textfield placeholder="%{#email}" ... etc ... />

Upvotes: 2

Related Questions