【问题标题】:JSF print property of inheriting class during printing of base class [duplicate]打印基类期间继承类的JSF打印属性[重复]
【发布时间】:2016-12-01 09:45:21
【问题描述】:

我有两个实体,VehicleLorry,货车有特殊属性 maxWeight。这些实体有自己的表格 - 车辆,参数为idVehiclelicensePlateamountKMma​​xWeight。我如何在 -

期间调用此参数
<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>

因为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;
    }
}

车辆类别:

@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;
    }
}

【问题讨论】:

  • &lt;h:outputText value="#{v.maxWeight}" rendered="#{v != null and v.class.simpleName eq 'Lorry'}"/&gt;
  • @diufanman 这不能解决问题 - The class 'entities.Vehicle' does not have the property 'maxWeight'。在实体 Vehicle 我没有这个属性,只有在 Lorry 类中:/
  • 我知道。您是否尝试过粘贴代码?仅当类为 Lorry 时才会呈现
  • 你使用泛型吗?
  • 我编辑的答案如下:原来的单引号和双引号不正确&lt;h:outputText value="#{v.maxWeight}" rendered="#{v != null and v.class.simpleName eq 'Lorry'}"/&gt;

标签: jsf managed-bean


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

【讨论】:

    猜你喜欢
    • 2016-03-21
    • 1970-01-01
    • 2011-08-23
    • 1970-01-01
    • 2016-12-27
    • 2018-04-07
    • 1970-01-01
    • 2022-01-11
    • 2017-10-17
    相关资源
    最近更新 更多