Primefaces数据表onrowselect事件在IE 8中不起作用

时间:2015-09-07 14:12:35

标签: java primefaces internet-explorer-8

我正在尝试让以下代码在IE 8中运行而没有结果(虽然它可以在Google Chrome中正常工作):

XHTML:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <h:head>
    </h:head>

    <h:body>
        <h:form id="form">

            <p:dataTable id="eventsDT" var="answer" value="#{verify.answers}" rowKey="#{answer.id}"  selectionMode="single" >
                <p:ajax event="rowSelect" listener="#{verify.onRowSelectTest}" />
                <p:column headerText="Id">
                    <h:outputText value="#{answer.id}" />
                </p:column>
                <p:column headerText="Text">
                    <h:outputText value="#{answer.text}" />
                </p:column>
            </p:dataTable>

        </h:form>
    </h:body>
</html>

Answer.java:

package ru.trust.appVerification;

    public class Answer {

        private int id;
        private String text = "Undefined";

        public Answer(int id, String text) {
            this.id = id;
            this.text = text;
        }

        public int getId() {
            return id;
        }

        public String getText() {
            return text;
        }

        public void setId(int id) {
            this.id = id;
        }

        public void setText(String text) {
            this.text = text;
        }
    }

Verify.java

   package ru.trust.appVerification;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.*;
import java.util.stream.*;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import org.primefaces.event.SelectEvent;

@ManagedBean
@ViewScoped

public class Verify implements Serializable {

     public List<Answer> getAnswers() {
        List<Answer> answers = new ArrayList<Answer>();

        answers.add(new Answer(1, "Yes"));
        answers.add( new Answer(2, "No"));
        return answers;
    }

    public void onRowSelectTest(SelectEvent event) {
        Answer answer = (Answer)event.getObject();

    }
}

我的代码有什么问题,或者Internet Explorer 8根本不支持它吗?

1 个答案:

答案 0 :(得分:1)

尝试在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:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui"
          xmlns:f="http://java.sun.com/jsf/core">
        <h:head>

        <f:facet name="first">
          <meta http-equiv="X-UA-Compatible" content="IE=edge" />
         <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
        </f:facet>
       // other head code goes here

       </h:head>

取代:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:f="http://xmlns.jcp.org/jsf/core">

    <h:head>
    </h:head>

我有一个类似的问题。添加这个对我来说很好。