Only display month and year in primefaces calendar

4

As remover os dias of the ? / p>

I tried the configuration below, but the days are displayed when the component is re-weighted.

<p:calendar id="dataTeste" pattern="MM/yyyy" />

Here is the rendered component image:

    
asked by anonymous 17.04.2014 / 17:12

2 answers

6

The Primefaces component does not support this natively.

Options would be:

  • Customize the component ( as in this SOEN response ).
  • Use a third-party plugin such as monthPicker (indicated in the question above) by applying it to a text box native to PrimeFaces.
  • Build your own JSF component (perhaps using the plugin from the previous item).

However, unless the visual question is very much needed, perhaps a simpler solution is the recommended one. Simply use a combo with the possible date range, each item containing mês/ano . Or two combos, one with month and one with year.

In particular, I do not see any advantage as a user in having to press arrows to move the month forward or backward, as it gives more work if I want to go to a date further.

    
17.04.2014 / 18:01
4

Old thread, but I'll leave a workaround that uses javascript and CSS to solve this problem ...

NOTE: Tested on Primefaces 5.2 ...

function setData(){
  ano = $("#data .ui-datepicker-year").val();
  mes = $("#data .ui-datepicker-month").val();
  $('#data_input').val(('0' + (++mes)).slice(-2)+'/'+ano);	  
}

$( "#data .ui-datepicker-month" ).change(function() {
  setData();   
});

$( "#daa .ui-datepicker-year" ).change(function() {
  setData();   
});
.ui-datepicker-inline .ui-datepicker-calendar{
  display: none;        
}
<p:calendar id="data" value="#{bean.data}" mode="inline" navigator="true" pattern="MM/yyyy"/>   

Result:

    
07.05.2015 / 14:39