简体   繁体   English

ui:repeat在JSF 2.0中不起作用?

[英]ui:repeat does not work in JSF 2.0?

In my page, <ui:repeat> does not work. 在我的页面中, <ui:repeat>不起作用。 <c:forEach> is work. <c:forEach>正在工作。 I don't know what am I missing? 我不知道我在想什么? Otherwise, Does not <ui:repeat> work JSF 2.0? 否则, <ui:repeat>在JSF 2.0中工作吗?

mypage.xhtml (it does not work) mypage.xhtml(无效)

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html" 
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="/common/commonLayout.xhtml">
    <ui:define name="content">
        <h:form id="toDeleteForm">
                <table>
                    <tr>
                        <td>
                            <ui:repeat value="#{DatePick.timeSlot}" var="timeSlot">
                                <h:outputText value="#{timeSlot}" style="font-size:12px;"/><br/>
                            </ui:repeat>
                        </td>
                    </tr>
                </table>
        </h:form>
    </ui:define>
</ui:composition>

mypage.xhtml (it is ok) mypage.xhtml(可以)

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html" 
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="/common/commonLayout.xhtml">
    <ui:define name="content">
        <h:form id="toDeleteForm">
                <table>
                    <tr>
                        <td>
                            <c:forEach items="#{DatePick.timeSlot}" var="timeSlot">
                                <h:outputText value="#{timeSlot}" style="font-size:12px;"/>
                            </c:forEach>
                        </td>
                    </tr>
                </table>
        </h:form>
    </ui:define>
</ui:composition>

DatePick.java DatePick.java

@Name("DatePick")
@Scope(ScopeType.CONVERSATION)
public class DatePick {

    public List<String> getTimeSlot() {
        // list form database
        return timeSlot;
    }
}

Output will be as below in my page. 输出将如下所示。

    01/01/2012
02/01/2012
03/01/2012
04/01/2012
05/01/2012

I used Java EE 6 annotations and it worked fine on GlassFish 3.1.2.2 with Mojarra 2.1.6. 我使用了Java EE 6注释,它在Mojarra 2.1.6的GlassFish 3.1.2.2上运行良好。 I did modify your code, but here it is. 我确实修改了您的代码,但是在这里。

@Named
@ConversationScoped
public class DatePick implements Serializable {

    private static final long serialVersionUID = -5061581851476260511L;

    public DatePick() {
    }

    public List<String> getTimeSlot() {
        List<String> dates = new ArrayList<String>() {
            private static final long serialVersionUID = 3109256773218160485L;

            {
                add("01/1/2012");
                add("02/1/2012");
                add("03/1/2012");
                add("04/1/2012");
                add("05/1/2012");
                add("06/1/2012");
                add("07/1/2012");
                add("08/1/2012");
                add("09/1/2012");
                add("10/1/2012");
                add("11/1/2012");
                add("12/1/2012");
            }
        };
        return dates;
    }
}

and here is the page... 这是页面...

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./WEB-INF/templates/main.xhtml"
                xmlns:h="http://java.sun.com/jsf/html">
    <ui:define name="content">
        <table>
            <tr>
                <td>
                    <ui:repeat value="#{datePick.timeSlot}" var="timeSlot">
                        <h:outputText value="#{timeSlot}"/><br/>
                    </ui:repeat>
                </td>
            </tr>
        </table>
    </ui:define>
</ui:composition>

The result was the expected output. 结果是预期的输出。 Note: I did not start, or end a conversation. 注意:我没有开始或结束对话。

There were some issues with that were fixed in 2.1 in a couple of different builds. 有一些问题已在2.1中以几个不同的版本修复。 You would need to look at the release notes for a particular build and issues resolved. 您需要查看特定版本的发行说明并解决问题。

UPDATE 更新

I posted the complete solution here: stackoverflow-ui-repeat-example 我在此处发布了完整的解决方案: stackoverflow-ui-repeat-example

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

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