Search code examples
javajspdatestruts2ognl

Date comparison in Struts2 Ognl tags


My requirement is to display a date from db and the status message to inform whether the date coming from db is past date, current date or a future date.

I'm displaying the date from db by

<s:property value="%{selObj.lastdate}"/>

Now how to get the current date in OGNL tags, I have tried

<s:propery value="%{new Date()}"/>

I need this current date to compare with selObj.lastdate and find out the date is passed?


Solution

  • If you can modify your action side:

    You can try to write a getter as like:

    public Date getCurrentDate(){
        return new Date();
    } 
    

    at your Java(Action) side.

    So you can get that value:

    <s:property value="currentDate"/>
    

    at your JSP side.