2013-08-29 3 views
2

작동하지 내가 어떤 행을 선택하고 경우에, 나는 (primefaces 인스턴트 행 선택의 예에서와 같이 동일) 아약스 호출에 갈거야 여기에 데이터 테이블DataTable의 행 선택

<p:dataTable id="db" 
    value="#{notificationBox.notificationsList}" 
    var="notificationForm" 
    rows="15" 
    emptyMessage="${msgs.getMessage('table.empty.message')}" 
    paginator="true" 
    paginatorPosition="bottom" 
    rowKey="#{notificationForm}" 
    selection="#{notificationBox.notification}" 
    paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} (${notificationBox.notificationsList.size()} ${msgs.getMessage('table.records')})" 
    selectionMode="single" 
    tableStyle="height:430px"> 

    //Rest of the code 

있습니다. Ajax는 Datatable 안에 있습니다.

<p:ajax event="rowSelect" listener="#{notificationBox.onRowSelect}" 
    oncomplete="carDialog.show();" /> 

내 백업 빈 클래스는 - 내가 어떤 행을 선택하면, "통지"에 null오고있다

private List<NotificationForm> notificationsList; 
public NotificationForm notification; 
public void onRowSelect(SelectEvent event) { 
    LOGGER.info("Here. +"+notification); 
} 

//Setter and Getters. 

문제가된다. 더 이상 처리 할 수 ​​없습니다. 도와주세요. 다른 방법도 환영합니다.

편집 : -

내 관리 빈의 범위 -

<managed-bean> 
    <managed-bean-name>notificationBox</managed-bean-name> 
    <managed-bean-class>com.comviva.workflow.ui.notification.NotificationBox</managed-bean-class> 
    <managed-bean-scope>view</managed-bean-scope> 
    <managed-property> 
     <property-name>notificationDao</property-name> 
     <value>#{notificationDaoService}</value> 
    </managed-property> 
    <managed-property> 
     <property-name>userInfoDao</property-name> 
     <value>#{userInfoDaoProxy}</value> 
    </managed-property> 
</managed-bean> 
+1

관리 빈의 범위는 무엇입니까? –

+0

당신의'rowKey'는 의심스럽게 이상합니다. PrimeFaces가 그것을 먹을 수 있습니까? 그것은 equals/hashcode가 구현되어 있습니까? 나는 그런 식으로 한번 시도한 적이 없지만, 여기서'# {entity.id}'를보기를 기대합니다. – BalusC

+0

@LuiggiMendoza,보기 범위에 있습니다. 세부 사항을 업데이트했습니다. – theGamblerRises

답변

5

당신이 가진 마십시오 p:dataTableh:form 태그에 싸여? 이것은 실제로 나를 위해 작동 :

NotificationBox (@ViewScoped)를 JQuery와 라이브러리하여 ​​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:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core"> 

<h:head> 
</h:head> 

<h:body> 

    <h:form> 
     <p:dataTable id="db" value="#{notificationBox.notificationsList}" 
      var="notificationForm" rows="15" 
      emptyMessage="${msgs.getMessage('table.empty.message')}" 
      paginator="true" paginatorPosition="bottom" 
      rowKey="#{notificationForm.notificationId}" 
      selection="#{notificationBox.notification}" 
      paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} (${notificationBox.notificationsList.size()} ${msgs.getMessage('table.records')})" 
      selectionMode="single" tableStyle="height:430px"> 

      <p:ajax event="rowSelect" listener="#{notificationBox.onRowSelect}" /> 

      <p:column> 
     #{notificationForm.name} 
     </p:column> 
     </p:dataTable> 
    </h:form> 
</h:body> 
</html> 
+0

감사합니다. 내 하루를 저장했습니다. :) – Sertage

0

같은 문제가 발생할 수 있습니다

package com.mycompany; 

import java.util.Arrays; 
import java.util.List; 

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

import org.primefaces.event.SelectEvent; 

@ManagedBean 
@ViewScoped 
public class NotificationBox { 

    public class NotificationForm { 

     Integer notificationId; 

     String name; 

     public NotificationForm(Integer id, String nam) { 
      notificationId = id; 
      name = nam; 
     } 

     public String getName() { 
      return name; 
     } 

     public Integer getNotificationId() { 
      return notificationId; 
     } 

     @Override 
     public String toString() { 
      return "NotificationForm [notificationId=" + notificationId 
        + ", name=" + name + "]"; 
     } 
    } 

    private List<NotificationForm> notificationsList; 

    public NotificationForm notification; 

    public NotificationBox() { 
     notificationsList = Arrays.asList(new NotificationForm(1, "Form1"), 
       new NotificationForm(2, "Form2")); 
    } 

    public NotificationForm getNotification() { 
     return notification; 
    } 

    public List<NotificationForm> getNotificationsList() { 
     return notificationsList; 
    } 

    public void onRowSelect(SelectEvent event) { 
     System.out.println(event.getObject()); 
    } 

    public void setNotification(NotificationForm notification) { 
     this.notification = notification; 
    } 

} 

index.xhtml. 나는 그것을 제거하고 선정은 효과가 있었다.