I have the next doubt about the <s:if> tag. I have a variable which is a string and I have to use the <s:if> tag to compare a piece of this string. Can I do it?, I mean with an example:
<s:iterator value="datosPedido" status="itStatus">
<s:set name="datosPedidoServV" value="%{descripcion[#itStatus.index]}" />
<s:if test="%{descripcion!='Servidor Virtual ('}">
Hola
</s:if>
.
.
This descripcion is longer than Servidor Virtual (…., but I have to check if the descripcion has this part of the string, is it right in this way?.
Thanks
You can compare with
==and with!=as well.You can compare with Java methods too, with
.equals("")or.equalsIgnoreCase("")for example.In your case, you are checking if one string is containing another, then you should use
.indexOf("")or
.contains("")NOTE that there is one limitation when working with ONE character long Strings. In that case you MUST use double quotes instead of single quotes, or OGNL will think that it is a Char and will try to compare a char with a String, failing.
More details here: http://struts.apache.org/2.3.4/docs/why-wont-the-if-tag-evaluate-a-one-char-string.html