month difference between two date in java

 int monthsDiff = today.get(Calendar.MONTH) 
                                - birthDay.get(Calendar.MONTH);
Advertisements

How to call a function on Page Reload in JSF

To my surprise, I didn’t need the Javascript bit. The final solution simply captures the PreRenderViewEvent or – in JSF 2.2 and above – a viewAction:

1
2
3
<f:metadata>
   <f:viewAction action="#{f5Detector.checkF5}" onPostBack="true"/>
</f:metadata>

The F5Detector class is simpler than I expected, too. There’s no need to check for postbacks. Nor did I have to check for AJAX requests. ViewActions aren’t triggered by AJAX requests.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
@SessionScoped
@ManagedBean
public class F5Detector {
  private String previousPage = null;
  public void checkF5() {
    String msg = "";
    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    String id = viewRoot.getViewId();
    if (previousPage != null && (previousPage.equals(id))) {
       // It's a reload event
    }
    previousPage = id;
  }
}

how to use loading indicator for h:commandButton(Non-Ajax) request

<h:commandButton

validateClient=”true”

onclick=”PF(‘statusDialog’).show()”

action=”#{myBean.generate}” value=”generate”

title=”Generate”

class=”btn bg-success heading-btn  font-iconmoon m-r-0″>

</h:commandButton>

 

put in your layout.xhtml page : 

<p:dialog widgetVar=”statusDialog” modal=”true” draggable=”false” closable=”false” resizable=”false” showHeader=”false”> <img src=”#{request.contextPath}/assets/images/preloader.gif” /> </p:dialog>