JSF 2.0 无法从 primefaces 渲染对话框

发布于 2024-10-27 12:59:39 字数 8206 浏览 1 评论 0原文

最近我在使用 primefaces 组件时遇到了很多问题,我不知道为什么。我使用glassfishV3.0,我的primefaces版本是2.2.1 我现在的问题是,当我单击表格行时,我无法使 primefaces 的 p:dialog 呈现。我所做的几乎与他们的示例中所做的完全一样: http://www.primefaces.org /showcase/ui/datatableComplex.jsf

我认为我的问题与某些配置有关,因为我也遇到了其他 primefaces 组件的问题。有人可以帮我一下,告诉我我缺少什么才能毫无问题地使用像这样的 primefaces 组件吗? 下面是代码:

JSF:

<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
<ui:define name="resultsForm">
<h:form enctype="multipart/form-data">
    <h:inputText id="search" value="" /><h:commandButton value="search"/>               
<p:dataTable var="garbage" value="#{resultsController.allGarbage}"  dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"  
             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
             rowsPerPageTemplate="5,10,15" selection="#{resultsController.garbage}" selectionMode="single"  
            onRowSelectUpdate="display" onRowSelectComplete="fileDialog.show()">            

            <p:column sortBy="#{garbage.filename}" parser="string" filterBy="#{garbage.filename}" filterMatchMode="startsWith">  
            <f:facet name="header">  
            <h:outputText value="Filename" />  
            </f:facet>  
            <h:outputText value="#{garbage.filename}" />
             </p:column> 

            <p:column filterBy="#{garbage.description}" filterMatchMode="contains">  
            <f:facet name="header">  
            <h:outputText value="Description" />  
            </f:facet>  
            <h:outputText value="#{garbage.description}" />  
             </p:column> 

            <p:column sortBy="#{garbage.uploadDate}" parser="string">  
            <f:facet name="header">  
            <h:outputText value="Upload date" />  
            </f:facet>  
            <h:outputText value="#{garbage.uploadDate}" /> 
             </p:column>                
    </p:dataTable> 

    <p:dialog header="Modal Dialog" widgetVar="fileDialog" modal="true" height="200">    

    <h:panelGrid id="display" columns="2" cellpadding="4">  
        <h:outputText value="FileName:" />  
        <h:outputText value="#{garbage.filename}" />  

        <h:outputText value="Upload date:" />  
        <h:outputText value="#{garbage.uploadDate}" />  

        <h:outputText value="Description" />  
        <h:outputText value="#{garbage.description}" /> 
    </h:panelGrid>           

    </p:dialog> 

    </h:form>
</ui:define>
    </ui:composition>

    </html>

托管 bean

@ManagedBean
@ViewScoped
public class ResultsController implements Serializable{

@EJB
private ISearchEJB searchEJB;

private Garbage garbage;

public List<Garbage> getAllGarbage() {

    List<Garbage> tmpGarbage = new ArrayList<Garbage>();
    for(Garbage g :searchEJB.findAllGarbage()) {
        tmpGarbage.add(g);
    }
    return tmpGarbage;
}

public Garbage getGarbage() {
    return garbage;
}

public void setGarbage(Garbage garbage) {
    this.garbage = garbage;
}   

之前的 JSF 是我在此模板中使用的复合页面

      <!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">
      <h:head>
      <title>title</title>
      <script type="text/javascript">
       PrimeFaces.widget.Uploader.prototype._createPostParams = function() {
       var b = {};
         b[PrimeFaces.PARTIAL_REQUEST_PARAM] = true;
       b[PrimeFaces.PARTIAL_PROCESS_PARAM] = this.id;
       b[PrimeFaces.PARTIAL_SOURCE_PARAM] = this.id;
       b[PrimeFaces.VIEW_STATE] = PrimeFaces.ajax.AjaxUtils.encodeViewState();
       if (this.cfg.update) {
         b[PrimeFaces.PARTIAL_UPDATE_PARAM] = this.cfg.update
        }
        var a = PrimeFaces.getCookie("JSESSIONID");
        if (this.cfg.script.indexOf("jsessionid") == -1) {
        paramIndex = this.cfg.script.indexOf('?');
          if (paramIndex != -1) {
           this.cfg.script = this.cfg.script.substring(0, paramIndex)
           + ";jsessionid=" + a
           + this.cfg.script.substring(paramIndex);
      } else {
         this.cfg.script = this.cfg.script + ";jsessionid=" + a;
       }
       }
      b['cid'] = "#{javax.enterprise.context.conversation.id}";
     return b;
      };
     PrimeFaces.widget.Uploader.prototype.createPostParams =                  PrimeFaces.widget.Uploader.prototype._createPostParams;
     </script>
     <script type="text/javascript" src="/ primefaces_resource/2.1/yui/datasource/datasource-min.js"></script> 
     <script type="text/javascript"  src="/primefaces_resource/2.1/primefaces/paginator/paginator.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/yui/datatable/datatable-min.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/primefaces/datatable/datatable.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/yui/swf/swf-min.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/yui/charts/charts-min.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/primefaces/charts/charts.js"></script>
     </h:head>

     <body> 
 <ui:insert name="resultsForm"/>
     </body>
     </html>

我的 web.xml 配置

    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/pages/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>pages/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping> 
    <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter
    </filter-class>        
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

在上面的表中,一切都有效,只有 sortBy 函数和 p:dialog 不起作用。 这是当我刷新页面时在 Eclipse 控制台上显示的消息:

严重:第 1:61 行在字符“;”处没有可行的替代方案

我不明白这意味着什么,我认为我有某种配置问题而不是语法错误。如果有人能帮我解决这个问题,我会非常高兴。

Lately i am having lots of issues with primefaces components, i dot know why. I use glassfishV3.0 and my primefaces version is 2.2.1
My problem now is that i cant make the p:dialog of primefaces render when i click on a table row. I do almos exactly as it is done in their example: http://www.primefaces.org/showcase/ui/datatableComplex.jsf

I think my issue has something to do with some configuration, because i am also having troubles with other primefaces components. Can somebody give me a hand please and tell me what i am missing to be able to use primefaces components like thisone with no problems?
Here is the code:

THE JSF:

<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:p="http://primefaces.prime.com.tr/ui">
    <ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
<ui:define name="resultsForm">
<h:form enctype="multipart/form-data">
    <h:inputText id="search" value="" /><h:commandButton value="search"/>               
<p:dataTable var="garbage" value="#{resultsController.allGarbage}"  dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"  
             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
             rowsPerPageTemplate="5,10,15" selection="#{resultsController.garbage}" selectionMode="single"  
            onRowSelectUpdate="display" onRowSelectComplete="fileDialog.show()">            

            <p:column sortBy="#{garbage.filename}" parser="string" filterBy="#{garbage.filename}" filterMatchMode="startsWith">  
            <f:facet name="header">  
            <h:outputText value="Filename" />  
            </f:facet>  
            <h:outputText value="#{garbage.filename}" />
             </p:column> 

            <p:column filterBy="#{garbage.description}" filterMatchMode="contains">  
            <f:facet name="header">  
            <h:outputText value="Description" />  
            </f:facet>  
            <h:outputText value="#{garbage.description}" />  
             </p:column> 

            <p:column sortBy="#{garbage.uploadDate}" parser="string">  
            <f:facet name="header">  
            <h:outputText value="Upload date" />  
            </f:facet>  
            <h:outputText value="#{garbage.uploadDate}" /> 
             </p:column>                
    </p:dataTable> 

    <p:dialog header="Modal Dialog" widgetVar="fileDialog" modal="true" height="200">    

    <h:panelGrid id="display" columns="2" cellpadding="4">  
        <h:outputText value="FileName:" />  
        <h:outputText value="#{garbage.filename}" />  

        <h:outputText value="Upload date:" />  
        <h:outputText value="#{garbage.uploadDate}" />  

        <h:outputText value="Description" />  
        <h:outputText value="#{garbage.description}" /> 
    </h:panelGrid>           

    </p:dialog> 

    </h:form>
</ui:define>
    </ui:composition>

    </html>

THE Managed bean

@ManagedBean
@ViewScoped
public class ResultsController implements Serializable{

@EJB
private ISearchEJB searchEJB;

private Garbage garbage;

public List<Garbage> getAllGarbage() {

    List<Garbage> tmpGarbage = new ArrayList<Garbage>();
    for(Garbage g :searchEJB.findAllGarbage()) {
        tmpGarbage.add(g);
    }
    return tmpGarbage;
}

public Garbage getGarbage() {
    return garbage;
}

public void setGarbage(Garbage garbage) {
    this.garbage = garbage;
}   

The JSF before is a composite page that i use inside this template

      <!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:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">
      <h:head>
      <title>title</title>
      <script type="text/javascript">
       PrimeFaces.widget.Uploader.prototype._createPostParams = function() {
       var b = {};
         b[PrimeFaces.PARTIAL_REQUEST_PARAM] = true;
       b[PrimeFaces.PARTIAL_PROCESS_PARAM] = this.id;
       b[PrimeFaces.PARTIAL_SOURCE_PARAM] = this.id;
       b[PrimeFaces.VIEW_STATE] = PrimeFaces.ajax.AjaxUtils.encodeViewState();
       if (this.cfg.update) {
         b[PrimeFaces.PARTIAL_UPDATE_PARAM] = this.cfg.update
        }
        var a = PrimeFaces.getCookie("JSESSIONID");
        if (this.cfg.script.indexOf("jsessionid") == -1) {
        paramIndex = this.cfg.script.indexOf('?');
          if (paramIndex != -1) {
           this.cfg.script = this.cfg.script.substring(0, paramIndex)
           + ";jsessionid=" + a
           + this.cfg.script.substring(paramIndex);
      } else {
         this.cfg.script = this.cfg.script + ";jsessionid=" + a;
       }
       }
      b['cid'] = "#{javax.enterprise.context.conversation.id}";
     return b;
      };
     PrimeFaces.widget.Uploader.prototype.createPostParams =                  PrimeFaces.widget.Uploader.prototype._createPostParams;
     </script>
     <script type="text/javascript" src="/ primefaces_resource/2.1/yui/datasource/datasource-min.js"></script> 
     <script type="text/javascript"  src="/primefaces_resource/2.1/primefaces/paginator/paginator.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/yui/datatable/datatable-min.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/primefaces/datatable/datatable.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/yui/swf/swf-min.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/yui/charts/charts-min.js"></script> 
     <script type="text/javascript" src="/primefaces_resource/2.1/primefaces/charts/charts.js"></script>
     </h:head>

     <body> 
 <ui:insert name="resultsForm"/>
     </body>
     </html>

My web.xml configuration

    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/pages/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
    <welcome-file>pages/index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Resource Servlet</servlet-name>
<servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resource Servlet</servlet-name>
<url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping> 
    <filter>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <filter-class>org.primefaces.webapp.filter.FileUploadFilter
    </filter-class>        
</filter>
<filter-mapping>
    <filter-name>PrimeFaces FileUpload Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

In the table i above everithing works, just the sortBy function and the p:dialog doesnt work.
This is a messages that is displayed at the eclipse console when i refresh the page:

SEVERE: line 1:61 no viable alternative at character ';'

I dont understand what it means, i think i have some kind of configuration problem rather than a syntax error. Ill be really happy if somebody could help me fix this please.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜嗑 2024-11-03 12:59:39

嗯,我创建了你的代码的简化版本,我的工作完美。每次我单击该行时,都会弹出我的对话框。尝试在新项目上运行此代码,看看它是否有效。

<?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.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="themes/blitzer/skin.css?${config.startupTime}" type="text/css"/>

    </h:head>
    <h:body>
        <h:form enctype="multipart/form-data">
            <p:dataTable var="item" value="#{myBean.myList}"  dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowsPerPageTemplate="5,10,15" selection="#{myBean.selectedResult}" selectionMode="single"
                         onRowSelectUpdate="display" onRowSelectComplete="fileDialog.show()">
                <p:column>
                    <h:outputText value="#{item}"/>
                </p:column>
            </p:dataTable>            
        </h:form>
        <p:dialog widgetVar="fileDialog">
            <h:outputText value="Dialog open"/>
        </p:dialog>
    </h:body>
</html>

这是我的 bean

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.test;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author KingdomHeart
 */
@ManagedBean
@ViewScoped
public class MyBean {

    private List<String> myList;

    private String selectedResult;

    public MyBean() {
    }

    @PostConstruct
    public void init(){
        myList = new ArrayList<String>();
        myList.add("Test1");
        myList.add("Test2");
        myList.add("Test3");
        myList.add("Test4");
        myList.add("Test5");
    }

    public List<String> getMyList() {
        return myList;
    }

    public void setMyList(List<String> myList) {
        this.myList = myList;
    }

    public String getSelectedResult() {
        return selectedResult;
    }

    public void setSelectedResult(String selectedResult) {
        this.selectedResult = selectedResult;
    }    
}

由 sfrj 更新
在此处输入图像描述

正如您所看到的,我的行中不止一行是黄色的,这不应该是这样的。 SelectionMode="single" 无法正常工作。

由 Harry 更新

以下是如何将 Date 类型转换为 String

public String formatDate(Date date) {
    if (date != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy");
        return sdf.format(date);
    }
    return null;
}

那么你的 JSF 就会像这样

h:outputText value="#{resultsController.formatDate(garbage.uploadDate)}" /> 

由 sfrj 更新 2
在此处输入图像描述

这是全新的 JSF 页面:

<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:p="http://primefaces.prime.com.tr/ui">
     <ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
<ui:define name="resultsForm2">
<h:form enctype="multipart/form-data">              
    <p:dataTable var="garbage" value="#{resultsController.allGarbage}"  dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15" selection="#{resultsController.selectedGarbage}" selectionMode="single"
                     rowSelectListener="#{resultsController.rowIsSelected}">
            <p:column>
                <h:outputText value="#{garbage.filename}"/>
            </p:column>
        </p:dataTable>            
    </h:form>
    <p:dialog widgetVar="fileDialog">
        <h:outputText value="Dialog open"/>
    </p:dialog>   
</ui:define>
    </ui:composition>
    </html>

uhmmm I create a simplified version of your code and mine work perfectly. Every time I click on the row, my dialog pop up. Try to run this code on a new project and see if it worked.

<?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.prime.com.tr/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link rel="stylesheet" href="themes/blitzer/skin.css?${config.startupTime}" type="text/css"/>

    </h:head>
    <h:body>
        <h:form enctype="multipart/form-data">
            <p:dataTable var="item" value="#{myBean.myList}"  dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"
                         paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                         rowsPerPageTemplate="5,10,15" selection="#{myBean.selectedResult}" selectionMode="single"
                         onRowSelectUpdate="display" onRowSelectComplete="fileDialog.show()">
                <p:column>
                    <h:outputText value="#{item}"/>
                </p:column>
            </p:dataTable>            
        </h:form>
        <p:dialog widgetVar="fileDialog">
            <h:outputText value="Dialog open"/>
        </p:dialog>
    </h:body>
</html>

and here is my bean

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.test;

import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

/**
 *
 * @author KingdomHeart
 */
@ManagedBean
@ViewScoped
public class MyBean {

    private List<String> myList;

    private String selectedResult;

    public MyBean() {
    }

    @PostConstruct
    public void init(){
        myList = new ArrayList<String>();
        myList.add("Test1");
        myList.add("Test2");
        myList.add("Test3");
        myList.add("Test4");
        myList.add("Test5");
    }

    public List<String> getMyList() {
        return myList;
    }

    public void setMyList(List<String> myList) {
        this.myList = myList;
    }

    public String getSelectedResult() {
        return selectedResult;
    }

    public void setSelectedResult(String selectedResult) {
        this.selectedResult = selectedResult;
    }    
}

Update by sfrj
enter image description here

As you see more than one of my rows are yellow, that is not suposed to be like that. selectionMode="single" is not working correctly.

Update by Harry

Here is how to convert Date type into String

public String formatDate(Date date) {
    if (date != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("MMM dd yyyy");
        return sdf.format(date);
    }
    return null;
}

Then your JSF would be like this

h:outputText value="#{resultsController.formatDate(garbage.uploadDate)}" /> 

Update 2 by sfrj
enter image description here

Here is the brand new JSF page:

<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:t="http://myfaces.apache.org/tomahawk"
xmlns:p="http://primefaces.prime.com.tr/ui">
     <ui:composition template="WEB-INF/templates/BasicTemplate.xhtml">
<ui:define name="resultsForm2">
<h:form enctype="multipart/form-data">              
    <p:dataTable var="garbage" value="#{resultsController.allGarbage}"  dynamic="true" paginator="true" paginatorPosition="bottom" rows="10"
                     paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink}  {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                     rowsPerPageTemplate="5,10,15" selection="#{resultsController.selectedGarbage}" selectionMode="single"
                     rowSelectListener="#{resultsController.rowIsSelected}">
            <p:column>
                <h:outputText value="#{garbage.filename}"/>
            </p:column>
        </p:dataTable>            
    </h:form>
    <p:dialog widgetVar="fileDialog">
        <h:outputText value="Dialog open"/>
    </p:dialog>   
</ui:define>
    </ui:composition>
    </html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文