Question

I am having problems using Dates with the same name in different backing beans:

Backing 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;
    }
}

Backing 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;
    }
}

View 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>

View 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>

When I load any view it show the following ajax error:

Firefox:

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

Chrome:

Uncaught TypeError: Cannot read property '0' of null 

And finally, the template.xhml file:

<?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>

This happens only using fields of type java.util.Date When I have two attributes of type Date in two backing beans with the same name

Was it helpful?

Solution

It was fixed since primefaces 5.1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top