2015-04-10 6 views
0

Я показываю данные в datatable in primefaces.I имеет 5 столбцов. В последнем столбце я показываю Edit & Кнопка Delete.On нажав кнопку редактирования, я показываю всплывающее окно, но я не могу отображать данные выбранных строка в всплывающем диалоговом окне?Невозможно показать значения в диалоговом окне «Всплывающие окна» в «Перформах»?

Кодекс XHTML

<!DOCTYPE html> 
<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" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
<h:head> 
    <title>Sale Item</title> 
    <link rel="stylesheet" href="css/style.css" media="screen" 
     type="text/css" /> 

</h:head> 
<h:body> 

    <h:form id="form1"> 
     <p:dataTable var="transection" value="#{trans.getTransections()}" 
      paginator="true" rows="10" 
      paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}" 
      paginatorPosition="bottom"> 
      <p:column headerText="number"> 
       <h:outputText value="#{transection.number}" /> 

      </p:column> 

      <p:column headerText="Amount" width="200"> 
       <h:outputText value="#{transection.amount}" /> 
      </p:column> 

      <p:column headerText="Type" width="200"> 
       <h:outputText value="#{transection.type}" /> 
      </p:column> 

      <p:column headerText="Date/Time" width="200"> 
       <h:outputText value="#{transection.date}" /> 
      </p:column> 
      <p:column headerText="Action" width="200"> 
       <h:panelGrid columns="2" border="0"> 
        <p:commandButton oncomplete="PF('TransDialog').show()" 
         icon="edit-icon"> 

         <f:setPropertyActionListener value="#{transection}" 
          target="#{trans.selectedTrans}" /> 
        </p:commandButton> 
        <p:commandLink> 
         <p:graphicImage value="images/delete.png"></p:graphicImage> 
        </p:commandLink> 

       </h:panelGrid> 

      </p:column> 
     </p:dataTable> 
     <p:dialog header="Transection Detail" widgetVar="TransDialog" 
      resizable="false" width="400" showEffect="explode" 
      hideEffect="explode"> 

      <p:panelGrid id="display" columns="2"> 
       <h:outputText value="Number:" /> 
       <p:inputText value="#{trans.selectedTrans.number}"/> 

       <h:outputText value="Amount:" /> 
       <p:inputText value="#{trans.selectedTrans.amount}"/> 

       <h:outputText value="Type:" /> 
       <p:inputText value="#{trans.selectedTrans.type}"/> 
      </p:panelGrid> 
      <h:panelGrid style="margin:0 auto" columns="1"> 
      <p:commandButton value="Update" actionListener="#{trans.printcal()}"></p:commandButton> 

      </h:panelGrid> 
     </p:dialog> 

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

Кодекс ManagedBean

package com.loteria.controller; 

import java.util.ArrayList; 

import javax.faces.bean.ManagedBean; 
import javax.faces.bean.RequestScoped; 
import javax.faces.bean.SessionScoped; 
import javax.servlet.http.HttpSession; 

import com.loteria.beans.Transection; 
import com.loteria.model.DBaction; 
import com.loteria.util.Util; 
@ManagedBean(name="trans") 
@SessionScoped 
public class TransController { 

    ArrayList<Transection> list; 
    public ArrayList<Transection> getList() { 
     return list; 
    } 

    public void setList(ArrayList<Transection> list) { 
     this.list = list; 
    } 

    private Transection selectedTrans; 

    public Transection getSelectedTrans() { 
     return selectedTrans; 
    } 

    public void setSelectedTrans(Transection selectedTrans) { 
     this.selectedTrans = selectedTrans; 
    } 

    public ArrayList<Transection> getTransections() 
    { 
    list=new ArrayList<Transection>(); 
     DBaction db=new DBaction(); 
     HttpSession session = Util.getSession(); 
     int uid=Integer.parseInt(session.getAttribute("uid").toString()); 
     list=db.getAllTransections(uid); 
     return list; 

    } 
    public void printcal() 
    { 
     System.out.print("princal"); 
    System.out.print("num is:"+selectedTrans.number); 
     System.out.print("amount is"+selectedTrans.amount); 
     System.out.print("type is"+selectedTrans.type); 

    } 
} 

Codce фасолевый Calss

package com.loteria.beans; 

public class Transection 
{ 

    public String amount; 
    public String number; 
    public String date; 
    public String type; 
    public String status; 
    public String tran_num; 

    public String getAmount() { 
     return amount; 
    } 
    public void setAmount(String amount) { 
     this.amount = amount; 
    } 
    public String getNumber() { 
     return number; 
    } 
    public void setNumber(String number) { 
     this.number = number; 
    } 
    public String getDate() { 
     return date; 
    } 
    public void setDate(String date) { 
     this.date = date; 
    } 
    public String getType() { 
     return type; 
    } 
    public void setType(String type) { 
     this.type = type; 
    } 
    public String getStatus() { 
     return status; 
    } 
    public void setStatus(String status) { 
     this.status = status; 
    } 
    public String getTran_num() { 
     return tran_num; 
    } 
    public void setTran_num(String tran_num) { 
     this.tran_num = tran_num; 
    } 



} 

я получаю исключение

javax .el.PropertyNotFoundException: /User/Records.xhtml @ 63,57 значение = "# {} trans.selectedTrans.number": Target Недоступен 'selectedTrans' возвращается нуль

+0

Прекрасно работает в витринах Primefaces. Найдите различия – Kukeltje

+1

О, и сделайте свой getTransactions() ленивым ... см. Http://stackoverflow.com/questions/2090033/why-jsf-calls-getters-multiple-times – Kukeltje

+0

Используйте debug для уверенности в 'public void setSelectedTrans (Transection selectedTrans) 'получать не нулевое значение – 0x5a4d

ответ

2

TechGuy, то p:dialog оказывается на странице загрузки даже если это не сразу видно пользователю (проверьте источник HTML). Это означает, что selectedTrans имеет значение null, когда страница сначала отображается, в результате возникает PropertyNotFoundException. Вы должны быть в состоянии исправить эту ошибку просто путем инициализации поля в бэк-боба:

private Transection selectedTrans = new Transection(); 

Это будет перезаписана setPropertyActionListener при нажатии на кнопку, которая хорошо.

+0

Я сделал это и получил благодарность за решение. – TechGuy

Смежные вопросы