2017-05-19 15 views
0

JavaとVaadinを初めて使用し、Vaadinグリッドの表示データ中にスタックしました。入れ子にする入れ子になったJSONデータがVaadinグリッドに表示されます

[ 
    { 
     "id":1, 
     "name":"testSiteC", 
     "accountId":1, 
     "accountData":{ 
     "id":1, 
     "name":"testAccountA", 
     "code":"AC0001", 
     "salesStaffId":200, 
     "samplingDate":1493038800000, 
     "startDate":1493038800000, 
     "creditPeriod":15, 
     "cinNo":"testCinNo", 
     "vatRegistrationNo":"testVatRegistrationNo", 
     "panNo":"testPanNo", 
     "serviceTaxRegistrationNo":"testServiceTaxRegistrationNo", 
     "isActive":true, 
     "billingType":"testBillingType", 
     "billingBasis":"cup count basis", 
     "billingAddress":"billingAddress", 
     "consigneeAddress":"test", 
     "clientRelationshipManagerStaffId":2, 
     "opsManagerId":1, 
     "serviceTaxId":1, 
     "createdOn":1483209000000, 
     "updatedOn":1494949002000 
     }, 
     "building":"3rd floor", 
     "locality":"Koramangala", 
     "city":"Bangalore", 
     "state":"Karnataka", 
     "country":"India", 
     "peopleCount":100, 
     "staffInCharge":1, 
     "dailyStartTime":"23:34:23", 
     "dailyEndTime":"23:34:34", 
     "createdOn":1493799889000, 
     "updatedOn":1494945760000, 
     "isActive":true, 
     "opsStartDate":1493730000000 
    } 
] 

豆:私のようなJSON形式のデータを持っているtable.addColumn(SitePantryResponse::getSiteData::getName).setCaption("Site Name")のようにグリッドにデータを表示しながら、

package com.chaipoint.boxc.common.model; 

import java.io.Serializable; 
import java.sql.Time; 
import java.sql.Timestamp; 
import java.util.Date; 

public class SiteResponse implements Serializable { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 
    private Long id; 
    private String name; 
    private Integer accountId; 
    private AccountResponse accountData; 
    private String building; 
    private String locality; 
    private String city; 
    private String state; 
    private String country; 
    private Integer peopleCount; 
    private Integer staffInCharge; 
    private Time dailyStartTime; 
    private Time dailyEndTime; 
    private Date createdOn; 
    private Timestamp updatedOn; 
    private Boolean isActive; 
    private Date opsStartDate; 

    public Long getId() { 
     return id; 
    } 

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

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public Integer getAccountId() { 
     return accountId; 
    } 

    public void setAccountId(Integer accountId) { 
     this.accountId = accountId; 
    } 

    public AccountResponse getAccountData() { 
     return accountData; 
    } 

    public void setAccountData(AccountResponse accountData) { 
     this.accountData = accountData; 
    } 

    public String getBuilding() { 
     return building; 
    } 

    public void setBuilding(String building) { 
     this.building = building; 
    } 

    public String getLocality() { 
     return locality; 
    } 

    public void setLocality(String locality) { 
     this.locality = locality; 
    } 

    public String getCity() { 
     return city; 
    } 

    public void setCity(String city) { 
     this.city = city; 
    } 

    public String getState() { 
     return state; 
    } 

    public void setState(String state) { 
     this.state = state; 
    } 

    public String getCountry() { 
     return country; 
    } 

    public void setCountry(String country) { 
     this.country = country; 
    } 

    public Integer getPeopleCount() { 
     return peopleCount; 
    } 

    public void setPeopleCount(Integer peopleCount) { 
     this.peopleCount = peopleCount; 
    } 

    public Integer getStaffInCharge() { 
     return staffInCharge; 
    } 

    public void setStaffInCharge(Integer staffInCharge) { 
     this.staffInCharge = staffInCharge; 
    } 

    public Time getDailyStartTime() { 
     return dailyStartTime; 
    } 

    public void setDailyStartTime(Time dailyStartTime) { 
     this.dailyStartTime = dailyStartTime; 
    } 

    public Time getDailyEndTime() { 
     return dailyEndTime; 
    } 

    public void setDailyEndTime(Time dailyEndTime) { 
     this.dailyEndTime = dailyEndTime; 
    } 

    public Date getCreatedOn() { 
     return createdOn; 
    } 

    public void setCreatedOn(Date createdOn) { 
     this.createdOn = createdOn; 
    } 

    public Timestamp getUpdatedOn() { 
     return updatedOn; 
    } 

    public void setUpdatedOn(Timestamp updatedOn) { 
     this.updatedOn = updatedOn; 
    } 

    public Boolean getIsActive() { 
     return isActive; 
    } 

    public void setIsActive(Boolean isActive) { 
     this.isActive = isActive; 
    } 

    public Date getOpsStartDate() { 
     return opsStartDate; 
    } 

    public void setOpsStartDate(Date opsStartDate) { 
     this.opsStartDate = opsStartDate; 
    } 

    public static long getSerialversionuid() { 
     return serialVersionUID; 
    } 



} 

ビーンが

public class SitePantryResponse implements Serializable { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 
    private Long id; 
    private String name; 
    private Integer siteId; 
    private SiteResponse siteData; 
    private Integer floorNo; 
    private Date createdOn; 
    private Timestamp updatedOn; 
    private Boolean isActive; 

    public Long getId() { 
     return id; 
    } 

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

    public String getName() { 
     return name; 
    } 

    public void setName(String name) { 
     this.name = name; 
    } 

    public Integer getSiteId() { 
     return siteId; 
    } 

    public void setSiteId(Integer siteId) { 
     this.siteId = siteId; 
    } 

    public SiteResponse getSiteData() { 
     return siteData; 
    } 

    public void setSiteData(SiteResponse siteData) { 
     this.siteData = siteData; 
    } 

    public Integer getFloorNo() { 
     return floorNo; 
    } 

    public void setFloorNo(Integer floorNo) { 
     this.floorNo = floorNo; 
    } 

    public Date getCreatedOn() { 
     return createdOn; 
    } 

    public void setCreatedOn(Date createdOn) { 
     this.createdOn = createdOn; 
    } 

    public Timestamp getUpdatedOn() { 
     return updatedOn; 
    } 

    public void setUpdatedOn(Timestamp updatedOn) { 
     this.updatedOn = updatedOn; 
    } 

    public Boolean getIsActive() { 
     return isActive; 
    } 

    public void setIsActive(Boolean isActive) { 
     this.isActive = isActive; 
    } 

    public static long getSerialversionuid() { 
     return serialVersionUID; 
    } 


} 

だから、ネストされた豆を含むが、それスロー:

この式のターゲットタイプは機能的インタフェースエラーでなければならない。

答えて

0

SitePantryResponse :: getSiteData ::のgetName

それはそのような連鎖メソッド参照することはできません。あなたが本当にメソッド参照を使用したい場合は、あなたがそれらをチェーンしますヘルパーメソッドを使用して、後でGrid.addColumnに渡すことができValueProvider返すことができますか

table.addColumn(r -> r.getSideDate().getName()).setCaption("Site Name") 

<A, B, C> ValueProvider<A, C> chain(Function<A, B> f1, Function<B, C> f2) { 
    return f1.andThen(f2)::apply; 
} 
をあなたの代わりに、簡単なラムダ式を使用することができます

table.addColumn(chain(SitePantryResponse::getSiteData, SiteResponse::getName)).setCaption("Site Name") 
をしかし、あなたが見ることができるように、これは、コードが複雑かつ長くなり、その理由がない:あなたが書くことができます。これにより

単純なラムダ式よりもこのアプローチを使用する。

+0

ラムダ式は私にとって完璧に機能します。どうもありがとうございます。 –

関連する問題