简体   繁体   English

如何将占位符放在struts2 textfield标记中?

[英]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: 我正在使用struts2标签,并希望将占位符放在<s:textfield>标记中,如下所示:

<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" . emailglobal.properties定义为“Correoelectrónico”。

My problem is that when I see the jsp page, instead of seeing the value of email I see %{email} . 我的问题是,当我看到jsp页面时,我看到%{email} ,而不是看到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. 我读到这是版本2.3.1中解决的Struts2的错误: https//issues.apache.org/jira/browse/WW-3644 ,但我使用的是Struts2 2.3.4并且我一直在使用它问题。

Anyone knows any solution to this problem or any other way for putting the placeholder in the textfield? 任何人都知道这个问题的解决方案或任何其他方式将占位符放在文本字段中?

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. 我需要更新我的Struts 2 OGNL jar。 My OGNL jar is ognl-3.0.5.jar . 我的OGNL jar是ognl-3.0.5.jar

您应该在堆栈命名空间中创建但未推送的变量使用#前缀:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM