Search code examples
jspif-statementstruts2ognlstruts-tags

Contains Or Index of in <s:property> tag Struts2?


I have been looking for use <s:property> in struts2 if condtion...and I found the solution but Contains or IndexOf doesn't works in my case can someone help me on syntax....

<s:iterator value="DirList" status="DirSTS" var="Dir">
    <s:if test="#DetailsStatus.index==#DirSTS.index">
        <s:if test="%{#Dir.indexOf(':'}!= -1">
            <a href='<s:property/>'><small>Click Here </small></a>
        </s:if>                     
    </s:if>
</s:iterator>

Here DetailsStatus is main list status variable...here I want to check if <s:property> have : symbol


Solution

  • First thing that your syntax missing ) closing bracket. Second make sure you have correct values in list which have : Symbol(You have already commented that it have wrong values)

    here is your code

    <s:iterator value="DirList" status="DirSTS" var="Dir">
    <s:if test="#DetailsStatus.index==#DirSTS.index">
        <s:if test="%{#Dir.indexOf(':'}!= -1">
            <a href='<s:property/>'><small>Click Here </small></a>
        </s:if>                     
    </s:if>
    

    change your code to like this....

    <s:iterator value="DirList" status="DirSTS" var="Dir">
    <s:if test="#DetailsStatus.index==#DirSTS.index">
        <s:if test="#Dir.indexOf(':')!= -1">
            <a href='<s:property/>'><small>Click Here </small></a>
        </s:if>                     
    </s:if>