I'm quiet new to this JSTL and JSP programming, and cannot figure out how this scenario should be solved. Thats why I hope any of one can inlight me and help me towards the right direction.
I have a button on a page. If the user click a second time on that button within 5 minutes from the last click, then I want to prompt the user with a confirm dialog, asking them if they are sure about this action.
JSP:
<c:choose>
<c:when test="${actionBean.warningDialog}">
<!-- Show warning dialog -->
<stripes:submit name="send" value="Send" style="height:20%;"
onclick="return confirm('Last click is lesser than 5 minutes ago.\nAre you sure you want to click again?','Are you sure you want to click?')" />
</c:when>
<c:otherwise>
<!-- Don't show any warnings -->
<stripes:submit name="send" value="Send" style="height:20%;" />
</c:otherwise>
ActionBean:
public boolean isWarningDialog(){
ClickBean bean = getClickSettings();
return isClickExpired(bean.getLastClick(), new Date());
}
private boolean isBroadcastExpired(Date lastSentDate, Date currentDate) {
this.differenceInMilliseconds = currentDate.getTime()- lastSentDate.getTime();
return differenceInMilliseconds < minimumBroadcastWarningTime;
}
@HandlesEvent("broadcast")
public Resolution send(){
//...Send message and return ForwardResolution...
}
So my problem currently is that the isWarningDialog is calculated when the page is loaded, and NOT on click. The idea is that when the user click on the button, then the page should calculate if a warning should be prompted or not.
When the user click send, it will end with a ForwardResolution to the same page, which means that the following scenario will occur:
- User clicks the button, no dialog shown, and the user will be forwarded to the same page.
- Now, after forwarded, the isWarningDialog is calculated and LastClick will be lesser than 5 mins.
- The user waits 6 mins, until he click on the button 2nd time.
- The user should not get any warning dialog, but currently he would, be cause the time is calculated right after the previous click <-- This is the issue.