java 如何在 struts2 文本字段标签中放置占位符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11155028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 04:00:00  来源:igfitidea点击:

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

javahtmlstruts2placeholder

提问by Pigueiras

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>

emailis defined in global.propertiesas "Correo electrónico" .

email被定义global.properties为“Correoelectricrónico”。

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

我的问题是,当我看到 jsp 页面时,而不是看到emailI 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.

我读到这是 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?

任何人都知道此问题的任何解决方案或将占位符放入文本字​​段的任何其他方式?

回答by javiercbk

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 andOGNL jars. My OGNL jar is ognl-3.0.5.jar.

我需要更新我的 Struts 2OGNL jar。我的 OGNL 罐子是ognl-3.0.5.jar.

回答by Dave Newton

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

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

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