在不同的支持bean中具有相同名称的日期

时间:2014-07-31 20:44:23

标签: jsf primefaces view-scope

我在使用不同支持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错误:

火狐:

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

铬:

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>

仅使用java.util.Date类型的字段发生这种情况当我在两个具有相同名称的支持bean中有两个Date类型属性时

1 个答案:

答案 0 :(得分:0)

自从第5.1节以来它被修复了