0

I'm developing a screen with JSF using PrimeFaces implementation, I have a requirement that the date should not contain the 00:00 or the 24:00 part in the time selection

My page:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui" template="/templates/main.xhtml">
     <h:form id="form">
        <p:calendar value="#{controller.arrivalDate}" showOn="both" 
            pattern="dd MMM yyyy HH:mm"  />
    </h:form>
</ui:composition>

My Controller:

@ManagedBean
public class Controller{

    Date date;

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }
}

In the Calendar control I use a slider to detect time, I need ANY acceptable way to stop the 00:00 as the 24:00 is already not valid choice

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • Why don't you play with `minHour`,`maxHour` attributes? – Aritz Aug 27 '13 at 07:45
  • if I put minimum Minute=1 the user will not be able to use 08:00 for example, so it does not help – Mohamed Wagdy Khorshid Aug 27 '13 at 08:00
  • Then your best is to use a [custom validator](http://stackoverflow.com/questions/6846882/how-to-validate-a-date-from-a-calendar). However, that validation will perform at server side, so it'll be notified to you when form submits. If you want to avoid the user selecting that value at prime calendar component, you'll probably need to hack a bit component's javascript/jquery. – Aritz Aug 27 '13 at 08:25
  • I guess so, I tried the validator thing, but actually the validator validates on the date not the string, where the date is already affected with the timezone conversions so 25 Jul 2007 00:00 can be a date with 25 Jul 2007 2:00 in another time zone, so it will be hard to detect if the user entered 00:00 or not, what do you think ? – Mohamed Wagdy Khorshid Aug 27 '13 at 09:00
  • Then it could be a lack in your requirement. Do you really need not to store that times referring to your timezone or just not letting the user introduce them? The goal of `p:calendar` input is to work with dates not with text, so makes sense for it to handle timezone conversions. I think you should refer to your timezone, if not you should not accept neither 1:00, 2:00, 3:00.. times, should you? – Aritz Aug 27 '13 at 09:23
  • I didn't justify the rejection of 00:00 and 24:00 from the client requirements, it's to avoid the conflict from the user prespective, it's not related to the timezones, it's just me (the developer) trying to handle it – Mohamed Wagdy Khorshid Aug 27 '13 at 09:42
  • As a rapid alternative, you can forget about `p:calendar`. Just provide a basic input(you can add a [mask](http://www.primefaces.org/showcase/ui/inputMask.jsf) to force the user use a pattern) and parse the date manually. When the form is submitted, check the date against a validator. – Aritz Aug 27 '13 at 13:31
  • this caould be a change more than an alternative, and I will go losing calendar contorl, which may be the last thing I want to do – Mohamed Wagdy Khorshid Aug 27 '13 at 14:34

0 Answers0