Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 514
Pigueiras Avatar asked Dec 01 '22 22:12

Pigueiras


2 Answers

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.

like image 140
javiercbk Avatar answered Jan 03 '23 19:01

javiercbk


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

<s:textfield placeholder="%{#email}" ... etc ... />
like image 37
Dave Newton Avatar answered Jan 03 '23 20:01

Dave Newton