2016-12-01 119 views
0

我有兩個實體,VehicleLorry,貨車有特殊屬性maxWeight。這些實體擁有自己的表格 - 車輛,參數爲idVehicle,licensePlate,amountKMmaxWeight。我可以怎麼稱呼這個參數 -JSF打印基類打印時繼承類的屬性

<h:dataTable var="v" value="#{vehicleMB.allVehicle}"> 
      <h:column headerClass="tableHeader"> 
       <f:facet name="header">License plate</f:facet> 
       #{v.licensePlate} 
      </h:column> 
      <h:column headerClass="tableHeader"> 
       <f:facet name="header">Max weight</f:facet> 
       #{*******maxWeight******} 
      </h:column> 
</h:dataTable> 

becouse v.maxWeight是未知。方法getAllVehicle只選擇表格中的所有車輛。有小費嗎 ?

貨車類:

@Entity 
public class Lorry extends Vehicle { 
    private long maxWeight; 

    public long getMaxWeight() { 
     return maxWeight; 
    } 

    public void setMaxWeight(long maxWeight) { 
     this.maxWeight = maxWeight; 
    } 
} 

Vehicle類:

@Entity 
public class Vehicle { 

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    private long idVehicle; 

    private String licensePlate; 
    private int amountKM; 


    @ManyToOne 
    Company company; 

    @OneToMany(mappedBy="vehicle") 
    List<Path> paths; 

    public List<Path> getPaths() { 
     return paths; 
    } 
    public void setPaths(List<Path> paths) { 
     this.paths = paths; 
    } 
    public long getIdVehicle() { 
     return idVehicle; 
    } 
    public void setIdVehicle(long idVehicle) { 
     this.idVehicle = idVehicle; 
    } 
    public String getLicensePlate() { 
     return licensePlate; 
    } 
    public Company getCompany() { 
     return company; 
    } 
    public void setCompany(Company company) { 
     this.company = company; 
    } 
    @Override 
    public int hashCode() { 
     final int prime = 31; 
     int result = 1; 
     result = prime * result + (int) (idVehicle^(idVehicle >>> 32)); 
     return result; 
    } 
    @Override 
    public boolean equals(Object obj) { 
     if (this == obj) 
      return true; 
     if (obj == null) 
      return false; 
     if (getClass() != obj.getClass()) 
      return false; 
     Vehicle other = (Vehicle) obj; 
     if (idVehicle != other.idVehicle) 
      return false; 
     return true; 
    } 
    public void setLicensePlate(String licensePlate) { 
     this.licensePlate = licensePlate; 
    } 
    public int getAmountKM() { 
     return amountKM; 
    } 
    public void setAmountKM(int amountKM) { 
     this.amountKM = amountKM; 
    } 
} 
+0

'的' – diufanman

+0

@diufanman這並不能解決問題 - '類'entities.Vehicle'沒有'maxWeight'屬性。在實體車輛我沒有這個屬性,只有在貨車類:/ –

+0

我知道。你有沒有嘗試粘貼代碼?只有在班級是貨車時纔會顯示 – diufanman

回答

1
<h:outputText value="#{v.maxWeight}" rendered="#{v != null and v.class.simpleName eq 'Lorry'}"/>