简体   繁体   English

如何在Struts 2中将两个布尔值与OGNL连接起来?

[英]How to concatenate two Boolean values with OGNL in Struts 2?

I have two variables set like this: 我有两个变量设置如下:

<s:set var="A" value="true" />
<s:set var="B" value="false" />

I want to generate the HTML below with a custom attribute info like this : 我想使用如下自定义属性info生成下面的HTML:

<td info="truefalse">&#160;</td>

I tried the following lines in my JSP file but I can't get true next to false : 我想在我的JSP文件中以下行,但我不能让true旁边false

<td info="<s:property value="#A?'true':'false'+#B?'true':'false'""/>&#160;</td>

outputs: <td info="true">&#160;</td> 输出: <td info="true">&#160;</td>

<td info="<s:property value="#A" /><s:property value="#B" />">&#160;</td>

outputs: <td info="false">&#160;</td> 输出: <td info="false">&#160;</td>

OGNL uses + to concatenate strings. OGNL使用+来连接字符串。 Having boolean values to convert to string, you should do something like 有了布尔值来转换为字符串,你应该做类似的事情

<s:property value="%{''+#A+#B}"/> 

Use <s:if> Try this 使用<s:if>试试这个

<s:set var="A" value="true" />
<s:set var="B" value="false" />

<td info="<s:if test="%{#A==true}">true</s:if><s:else>false</s:else><s:if test="%{#B==true}">true</s:if><s:else>false</s:else>">&#160;</td>
 OR
<td info="<s:property value="#A" /><s:property value="#B" />">&#160;</td>

outputs: 输出:

<td info="truefalse">&#160;</td>

Reason: You can not concatenate Boolean . 原因:您无法连接Boolean You need to convert Boolean to string and you can concatenate strings only. 您需要将Boolean转换为string并且只能连接strings

试试这个可能对你有帮助..

<td info="<s:property value="A"></s:property><s:property value="B"></s:property>">&#160;</td>

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

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