我在不同的备用bean中使用具有相同名称的日期遇到问题:

支持bean 1:

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

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class MenuLink1BB implements Serializable {

    private static final long serialVersionUID = 4070538070773061768L;

    private String value1;

    private Date value2;

    @PostConstruct
    public void init() {
        value1 = "value 1_1";
        value2 = new Date();
    }

    public String loadView() {
        return "/test/menuLink1";
    }

    public void testMenuLink1(String value) {
        System.out.println(value);
    }

    public String getValue1() {
        return value1;
    }

    public void setValue1(String value1) {
        this.value1 = value1;
    }

    public Date getValue2() {
        return value2;
    }

    public void setValue2(Date value2) {
        this.value2 = value2;
    }
}
.

支持bean 2:

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

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

@ManagedBean
@ViewScoped
public class MenuLink2BB implements Serializable {

    private static final long serialVersionUID = -5872644335654136327L;

    private Date value2;

    private String value3;

    @PostConstruct
    public void init() {
        value2 = new Date();
        value3 = "value 2_3";
    }

    public String loadView() {
        return "/test/menuLink2";
    }

    public void testMenuLink2(String value) {
        System.out.println(value);
    }

    public Date getValue2() {
        return value2;
    }

    public void setValue2(Date value2) {
        this.value2 = value2;
    }

    public String getValue3() {
        return value3;
    }

    public void setValue3(String value3) {
        this.value3 = value3;
    }
}
.

视图1:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/WEB-INF/template/template.xhtml">
    <ui:define name="bodyContent">
        <h:form id="form">
            <p:panelGrid columns="1">
                <h:outputText value="BackingBean 1 Value 1: #{menuLink1BB.value1}" />
                <h:outputText value="BackingBean 1 Value 2: #{menuLink1BB.value2}" />
                <h:outputText value="BackingBean 2 Value 2: #{menuLink2BB.value2}" />
                <h:outputText value="BackingBean 2 Value 3: #{menuLink2BB.value3}" />
            </p:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>
.

视图2:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/WEB-INF/templates/template.xhtml">
    <ui:define name="bodyContent">
        <h:form id="form">
            <p:panelGrid columns="1">
                <h:outputText value="BackingBean 2 Value 2: #{menuLink2BB.value2}" />
                <h:outputText value="BackingBean 2 Value 3: #{menuLink2BB.value3}" />
                <h:outputText value="BackingBean 1 Value 1: #{menuLink1BB.value1}" />
                <h:outputText value="BackingBean 1 Value 2: #{menuLink1BB.value2}" />
            </p:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>
.

当我加载任何视图时,它会显示以下Ajax错误:

firefox:

TypeError: (intermediate value).exec(...) is null
.

chrome:

Uncaught TypeError: Cannot read property '0' of null 
.

最后,template.xhml文件:

<?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:p="http://primefaces.org/ui">
<f:view contentType="text/html">
    <h:head>
    </h:head>
    <h:body>
        <p:panelGrid>
            <p:row>
                <p:column>
                    <h:form id="menuForm">
                        <p:panelMenu id="menuPM">
                            <p:submenu label="Menu">
                                <p:menuitem action="#{menuLink1BB.loadView}" value="Menu link 1" />
                                <p:menuitem action="#{menuLink2BB.loadView}" value="Menu link 2" />
                            </p:submenu>
                        </p:panelMenu>
                    </h:form>
                </p:column>
                <p:column>
                    <ui:insert name="dialogs" />
                    <p:messages autoUpdate="true" closable="true" redisplay="false" />
                    <ui:insert name="bodyContent" />
                </p:column>
            </p:row>
        </p:panelGrid>
    </h:body>
</f:view>
</html>
.

当我在具有相同名称的两个备份bean中有两个类型的日期属性时,才会使用类型的字段发生,这只是使用相同的名称

有帮助吗?

解决方案

它是固定的,因为primefaces 5.1

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top