使用日历时未调用Primefaces commandButton actionListener

时间:2017-08-29 13:49:23

标签: jsf primefaces jsf-2

我很久以前就开始使用JSF和primefaces(Primefaces 6.1.4,Mojarra 2.1.8,JBoss AS 7.1.1)。

使用primefaces calendar和commandButton actionListener()方法时遇到问题。使用日历组件时,commanButton的actionListener()永远不会被调用。在xhtml中注释日历将导致commandButton的actionListener()再次被调用。

我有什么简单的东西可以忽略,或者这两者是否彼此不相容?

提前感谢您提出任何意见或建议!

以下是显示问题的示例代码:

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"));
    }
}

0 个答案:

没有答案