0

I started working with JSF and primefaces a short time ago (Primefaces 6.1.4, Mojarra 2.1.8, JBoss AS 7.1.1).

I have a problem using the primefaces calendar and commandButton actionListener() method. When the calendar component is used, then the commanButton's actionListener() never gets called. Commenting out the calendar in the xhtml will cause the commandButton's actionListener() to get called again.

Is there something simple I'm overlooking or are these two not compatible with each other?

Thank you in advance for any comments or suggestions!

Below is the sample code for showing the problem:

advancedsearch.xhtml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:p="http://primefaces.org/ui">

<h:head>
</h:head>

<h:body>
    <h:form>
        <p:separator />

        <h:panelGrid columns="2" cellpadding="5">
            <p:outputLabel for="from_cal" value="From:" />
            <p:calendar id="from_cal" value="#{dtAdvancedSearch.from_cal}" />
            <p:outputLabel for="to_cal" value="To:" />
            <p:calendar id="to_cal" value="#{dtAdvancedSearch.to_cal}" />
        </h:panelGrid>

        <p:separator />

        <p:messages id="messages" showDetail="true" autoUpdate="true" closable="true" />
        <p:commandButton value="Submit Request"
            actionListener="#{dtAdvancedSearch.info}" />
    </h:form>
</h:body>
</html>

AdvancedSearch.java:

package com.test.outage;

import java.util.Date;
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

@ManagedBean(name = "dtAdvancedSearch")
@SessionScoped
public class AdvancedSearch implements Serializable {

    private static final long serialVersionUID = 1L;

    private Date from_cal;
    private Date to_cal;

    public AdvancedSearch() {

    }

    public Date getFrom_cal() {

        return from_cal;
    }

    public Date setFrom_cal(Date value) {

        return from_cal = value;
    }

    public Date getTo_cal() {

        return to_cal;
    }

    public Date setTo_cal(Date value) {

        return to_cal = value;
    }

    public void info() {

        FacesContext.getCurrentInstance().addMessage(
            null, new FacesMessage(
            FacesMessage.SEVERITY_INFO, "Info", "submit button request"));
    }
}
Parkash Kumar
  • 4,710
  • 3
  • 23
  • 39
Roy
  • 1
  • 1
    I was able to reproduce your issue. Just setting `process` attribute on the `p:commandButton` resolves it. In my case, I set it to `process="@this"` as I didn't want to process any element of the form. – Parkash Kumar Aug 29 '17 at 14:42
  • Works for me too. Thank you Parkash! Enjoy your day. – Roy Aug 29 '17 at 15:41
  • Then the calendar values are not submitted... So it is sort of identical to them not being there... Sure there are no validation errors? I'd think that the info method signature is wrong (https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value #11) – Kukeltje Aug 29 '17 at 19:58

0 Answers0