0

In my JSF view scoped form, I am using the poll tag to print minutes elapsed since the form was started, like this:

<h:outputText id="txt_count" value="You started #{mybean.timeElapsed} minutes ago" />

This is what I have in my backing bean. pollNumber is just an int. It works fine and prints minutes elapsed.

public String getTimeElapsed()
    {
        long diffInMinutes = java.time.Duration.between(startTime, LocalDateTime.now())
                .toMinutes();

        return String.valueOf(diffInMinutes);
    }

    public void increment(){
        pollNumber++;
    }

The problem is that I am using a custom date converter for a date in format MM/yyyy (a java.time.YearMonth). Every 5 seconds (the poll interval) the yearmonth date converter gets called, whether or not the date field is completely filled out. So one minute I am happily filling out my date field, the next I am redirected to a yucky stack trace:

Sorry, an error occurred Exception: Text '05/____' could not be parsed at index 3 Full stack trace: java.time.format.DateTimeParseException: Text '05/____' could not be parsed at index 3 at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851)

The problem goes away if I remove the p:poll tag. This is not a critical error. It's just weird. Any input would be appreciated. Thanks!

nettie
  • 628
  • 1
  • 11
  • 23
  • So, the `` also processes (submits/converts/validates) input fields even though they are not filled out yet and you appear to have an input field with a date mask? – BalusC Mar 09 '16 at 21:38
  • yes, that's exactly it. It's a p:inputMask with slotChar "__/____". Sorry I omitted that. – nettie Mar 09 '16 at 21:48
  • Then just tell `` to not process those input fields? E.g. `process="@this"`. Or do you already have that? Next time, please just post problematic code directly in MCVE flavor: http://stackoverflow.com/tags/jsf/info – BalusC Mar 09 '16 at 21:48
  • OK, I will. I added process=”@this” to the p:poll tag and it worked. The minutes are counted. The date fields work :-), and I can submit the form. However if there are validation messages, my messages output resets itself on the poll interval. – nettie Mar 09 '16 at 22:17
  • That new question is duplicated here: http://stackoverflow.com/q/17298913 – BalusC Mar 10 '16 at 08:15
  • yes this did the trick: thank you!! – nettie Mar 10 '16 at 13:53

0 Answers0