简体   繁体   English

JSF <ui:repeat> 零件

[英]JSF <ui:repeat> component

i want to make simple DropDownList. 我想做一个简单的DropDownList。

<p:selectOneMenu id="starter" value="#{reportRegisterManagedBean.starter}" style="width:160px" converter="#{reportStarterConverter}" required="true" requiredMessage="Select Report Starter">
                           <ui:repeat value="#{reportRegisterManagedBean.startersSelectItems}" var="dss">
                                <f:selectItem  itemLabel="#{dss}" itemValue="#{dss}" itemDescription="TEST" />
                           </ui:repeat>
                        </p:selectOneMenu>

DropDownList is enpty, if i use <f:selectItems> instead of <ui:repeat> works very well, but <f:selectItems> Component itemDescription =(this is simple tooltip analogy) not working. 如果我使用<f:selectItems>而不是<ui:repeat>话, DropDownList是很不错的,但是<f:selectItems>组件itemDescription =(这是简单的工具提示类推)无法正常工作。 <f:selectItem> Component itemDescription =(this is simple tooltip analogy) working fine. <f:selectItem>组件itemDescription =(这是简单的工具提示类推),工作正常。 That's why I decided to use the and <f:selectItem> with its itemDescription attribute. 这就是为什么我决定将and <f:selectItem>及其itemDescription属性一起使用的itemDescription

The <f:selectItem> needs to be added during view build time. 在视图构建期间需要添加<f:selectItem> However, the <ui:repeat> runs during view render time. 但是, <ui:repeat>在视图渲染期间运行。 You need a repeater which runs during view build time. 您需要一个在视图构建期间运行的转发器。 The JSTL <c:forEach> is such one. JSTL <c:forEach>就是这样的。

<p:selectOneMenu ...>
    <c:forEach items="#{reportRegisterManagedBean.startersSelectItems}" var="dss">
        <f:selectItem ... />
    </c:forEach>
</p:selectOneMenu>

Alternatively, create a custom renderer. 或者,创建一个自定义渲染器。 Here's an example which does exactly the same for <p:selectManyCheckbox> : Primefaces tooltip for p:selectManyCheckbox 这是一个与<p:selectManyCheckbox>完全相同的示例<p:selectManyCheckbox> Primefaces工具提示

As you don't like String array. 由于您不喜欢String数组。 here is tested and working example with User class: 这是User类的经过测试且有效的示例:

public class FilterBean {

private List<User> uList = new ArrayList<User>();
private User selectedUser = new User();


public List<User> getuList() {
    User u1 = new User();
    u1.setName("Tom");
    u1.setDesc("worker");
    User u2 = new User();
    u2.setName("Peter");
    u2.setDesc("owner");

    uList.add(u1);
    uList.add(u2);

    return uList;
}

public void setuList(List<User> uList) {
    this.uList = uList;
}   

public User getSelectedUser() {
    return selectedUser;
}

public void setSelectedUser(User selectedUser) {
    this.selectedUser = selectedUser;
}
}   

And this is JSF 这是JSF

    <p:selectOneMenu value="#{filterBean.selectedUser}"> 
        <f:selectItem itemLabel="Select One" itemValue="" />   
        <f:selectItems  value="#{filterBean.uList}" var="n" itemValue="#{n}" itemDescription="#{n.desc}" itemLabel="#{n.name}" />  
    </p:selectOneMenu> 

This shows desc for Tom and Peter :) 这显示了Tom和Peter的描述:)

Here is how you create a drop-down list in primefaces : 这是在primefaces创建下拉列表的primefaces

<p:selectOneMenu id="starter" value="#{reportRegisterManagedBean.starter.selectedItem}">  
        <f:selectItems value="#{reportRegisterManagedBean.starter.startersSelectItems}" />  
</p:selectOneMenu>  

I have tried several examples and got this results: 我尝试了几个示例,并得到了以下结果:

I have this in pojo: 我在pojo中有这个:

private String selectL;
private String[] listas;


public String[] getListas() {
    listas = new String[2];  
    listas[0] = "pirmas";
    listas[1] = "antras";
    return listas;
}

and this jsf works (itemDescription must be String): 并且此jsf有效(itemDescription必须为String):

    <p:selectOneMenu value="#{formBean.selectL}">   
        <f:selectItems  value="#{filterBean.listas}" var="n" itemDescription="#{n}2" />  
    </p:selectOneMenu>  

and this not :/ : 这不是:/:

    <p:selectOneMenu value="#{formBean.selectL}">   
        <f:selectItems  value="#{filterBean.listas}" itemDescription="test2" />  
    </p:selectOneMenu>  

EDIT: 编辑:

After some test I just added var into second selectOneMenu and it WORKS now too: 经过一些测试,我只是将var添加到第二个selectOneMenu中,它现在也可以工作:

    <p:selectOneMenu value="#{formBean.selectL}">   
        <f:selectItems  value="#{filterBean.listas}" var="n" itemDescription="test2" />  
    </p:selectOneMenu>  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM