< p:列>使用对象的列表属性时不会呈现 [英] <p:columns> won't render when list-property of object is used

查看:102
本文介绍了< p:列>使用对象的列表属性时不会呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用<p:columns>,但是当我给List喂它时,它却不提供任何东西,该List是正在封装<p:dataTable>的对象的属性.

I am trying to use <p:columns> but it renders nothing when I feed it with a List that is a property of the objects the enclosing <p:dataTable> is iterating over.

可以成功使用<ui:repeat>中的该列表,或使用<p:column>访问<p:dataTable>内部的列表之一. <p:columns>当将列表分配给支持bean的属性时.
但是,当使用Car -object 的属性时,该位置将不显示任何内容.没有错误消息等.

I can use that list succesfully in <ui:repeat> or access one of it's entries inside the <p:dataTable> using <p:column>. <p:columns> when a assign the list to a property of the backing bean.
But when using the property of the Car-object nothing is rendered at that place. There is no error message etc.

《 Primefaces 4.0用户指南》 中有关Dynamic Columns的部分使我感到困惑使用代码示例cars[colIndex],但<p:columns>仍具有除cars之外的其他值-我不知道该如何使用.

The part about Dynamic Columns in the Primefaces 4.0 User Guide confuses me as in the code example cars[colIndex] is used but still the <p:columns> has a value other than cars - I don't how this is supposed to be used.

其他信息:
我需要<p:columns>的列列表成为该类的一部分,因为我想对具有不同属性的几个类重用代码,因此需要不同的列.

Additional Info:
I need the list of columns for <p:columns> to be part of the class as I want to reuse the code for several classes with different properties and thus require different columns.

Facelets代码:

the Facelets code:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

<h:head></h:head>
<h:messages />
<h:form>
    <!-- works -->
    <ui:repeat value="#{carBean.cars}" var="car">
        ui:repeat: #{car.features}
    </ui:repeat>

    <p:dataTable value="#{carBean.cars}" var="car">

       <!-- works too -->
       <p:column>
           p:column: #{car.features.get(0)}
       </p:column>

       <!-- works too -->
       <p:columns value="#{carBean.beanFeatures}" var="feature" columnIndexVar="colIndex">  
            carBean p:columns: #{feature}
       </p:columns>

       <!-- renders nothing -->
       <p:columns value="#{car.features}" var="feature" columnIndexVar="colIndex">  
            car p:columns: #{feature}
       </p:columns>

    </p:dataTable>

</h:form>
</html>

后备豆:

package myPackage;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

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

@ManagedBean
@ViewScoped
public class CarBean implements Serializable {

    List<Car> cars;
    List<String> beanFeatures;

    @PostConstruct
    public void init(){
        cars = new ArrayList<Car>();
        Car car1 = new Car();
        car1.features.add("windows");
        car1.features.add("fridge");
        Car car2 = new Car();
        car2.features.add("wheels");
        car2.features.add("nuclear engine");
        cars.add(car1);
        cars.add(car2);
        beanFeatures = car1.getFeatures();
    }

    public List<Car> getCars() {
        return cars;
    }

    public void setCars(List<Car> cars) {
        this.cars = cars;
    }

    public List<String> getBeanFeatures() {
        return beanFeatures;
    }

    public void setBeanFeatures(List<String> beanFeatures) {
        this.beanFeatures = beanFeatures;
    }

}

Car

package myPackage;

import java.util.ArrayList;
import java.util.List;


public class Car {

    List<String> features = new ArrayList<String>();

    public List<String> getFeatures() {
        return features;
    }

    public void setFeatures(List<String> features) {
        this.features = features;
    }

}

推荐答案

基本上,这不是Primefaces动态列的工作方式.您的动态列必须直接与Managed Bean的属性绑定.每次汽车迭代都无法选择稳定地保持该值.

That's basically not the way Primefaces dynamic columns work. Your dynamic columns must be binded against a Managed Bean's property directly. There's no choice to dinamically stablish that value for each car iteration.

因此,简而言之,对于不同的表值,不可能有不同的列.可以对表列进行动态渲染,但这必须在 PrimeFaces开始对值进行循环之前确定.

So, in short words, is not possible to have different columns for different table values. Table columns can be dinamically rendered, but this must be decided before PrimeFaces starts looping over the values.

如果您查看 Primefaces展示,您会发现

但是,可以使用ui:repeat在同一列中循环显示汽车的功能,因此您可以将所有功能都放在一个列中:

However, it's possible to loop over car's features in the same columns using a ui:repeat, so you could have all its features in a single column:

<p:column>  
    <ui:repeat value="#{car.features}" var="feature">
        #{feature}
    </ui:repeat>
</p:column>

这篇关于&lt; p:列&gt;使用对象的列表属性时不会呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆