Can we apply mask operation with

2019-08-01 14:15发布

<h:column>
    <f:facet name="header">
        <h:outputLabel value="#{label.asOfDate}" style="font-weight:bold" />
        <h:outputLabel value="*"
            style="font-weight:bold; color:red; font-size:150%" />
    </f:facet>

    <p:calendar id="date" required="true" navigator="true"
        mindate="#{utils.minDate}" pattern="#{label.dateFormat}"
        maxdate="#{utils.maxDate}" value="#{policy.asOfDt}"
        requiredMessage="#{label.asOfDateRequired}" showOn="button">
        <f:validator validatorId="CustomDateValidator" />
    </p:calendar>

</h:column>

I want date textfield should in masked format (11/11/2011) with calendar button. Can we apply mask operation with calendar?

6条回答
贼婆χ
2楼-- · 2019-08-01 14:57

apply datePattern attribute

datePattern="MM/dd/yyyy" 
查看更多
再贱就再见
3楼-- · 2019-08-01 15:01

INMO , If you must use additional jquery plugin to achieve this task , you better use jquery for both : calendar and mask (a really little additional code is needed to bind bean value to the input responsible for the calendar)

take a look at this solutions

Mask the date format when using jQuery UI datepicker

and

Small jsfiddle example

and another one

Using jQueryUI Datepicker And Input Masking Together

查看更多
Lonely孤独者°
4楼-- · 2019-08-01 15:01

You might address this problem by setting the input field to readonly to force users to select a date.

Here is the property to add to your input field to force this :

readonlyInput="true"
查看更多
男人必须洒脱
5楼-- · 2019-08-01 15:05

Since Primefaces 5.0, you can use the calendar's attribute mask:

mask="99/99/9999"
查看更多
一夜七次
6楼-- · 2019-08-01 15:11

As to this post, it is not possible. The question there is answered by the PF lead developer (so trust him ;-). He suggests to write a composite component in combination with jquery (http://digitalbush.com/projects/masked-input-plugin/).

查看更多
做自己的国王
7楼-- · 2019-08-01 15:15

You can use somehting like this: `

<script type="text/javascript" language="JavaScript">
          var $ = jQuery;
          $(document).ready(function() {
              $("input[id*='Date']").mask('99/99/9999');
          });
     </script>
     <p:calendar id="documentDate" />

`

查看更多
登录 后发表回答