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

狂风中的少年 提交于 2019-12-13 12:08:49

问题


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?


回答1:


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.




回答2:


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

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


来源:https://stackoverflow.com/questions/11155028/how-can-i-put-a-placeholder-in-a-struts2-textfield-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!