ui:repeat 不为我呈现数据

发布于 2025-01-03 15:20:30 字数 4859 浏览 2 评论 0原文

web.xml

<!-- JavaServer Faces -->
<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml,/WEB-INF/faces-managed-beans.xml,/WEB-INF/faces-navigation.xml</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.SKIN</param-name>
    <param-value>blueSky</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.CONTROL_SKINNING</param-name>
    <param-value>enable</param-value>
</context-param>
<context-param>
    <param-name>com.sun.faces.validateXml</param-name>
    <param-value>true</param-value>
</context-param>
<filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- Faces Servlet -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<login-config>
    <auth-method>BASIC</auth-method>
</login-config>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<validator>
    <validator-id>com.test..view.validator.Regex</validator-id>
    <validator-class>com.test..view.validator.regex.RegexValidator</validator-class>
</validator>
<application>
    <locale-config>
        <default-locale>en</default-locale>
    </locale-config>
    <message-bundle>com.test..view.resources.bundle.Messages</message-bundle>
</application>
</faces-config>

JSP 文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<html> 
<head>
</head>
<body onload="alert(\"test\")">
    It works <hr/>
<f:view>
<h:form>
<ui:repeat value="${buildVehicleBean.buildVehicleBO.allVehicles}" var="var1">
    <h:outputText value="#{var1.modelLineName}"/><br/>
</ui:repeat>

</h:form>
</f:view>
</body>

</html>

当我在浏览器中查看源代码时,我看到

...
<ui:repeat value="[com.test.model.bo.CarBO@3f9ba5,
com.test.model.bo.CarBO@38662,
com.test.model.bo.CarBO@16b9c59,
com.test.model.bo.CarBO@1e5bbb0,
com.test.model.bo.CarBO@1855620,
com.test.model.bo.CarBO@d984ff,
com.test.model.bo.CarBO@1dd4000,
com.test.model.bo.CarBO@100bb12,
com.test.model.bo.CarBO@f9d8ce]" var="var1">


<br/>
</ui:repeat>
...

As you see just 'br' tag in ui:repeat.

这对我来说似乎很简单,显然我在某个地方丢失了一些东西,很难找到它。如果我使用一些简单的东西,比如常量值,它会起作用

<h:outputText value="#{12345}"/><br/>
<h:outputText value="#{buildVehicleBean.testDouble}"/><br/>

如果我在下一行中使用“#”而不是“$”,它会给出错误“

<ui:repeat value="${buildVehicleBean.buildVehicleBO.allVehicles}" var="var1">

我是 JSF 新手,来自 JSP 和 JSF”。支柱背景。

web.xml

<!-- JavaServer Faces -->
<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>
<context-param>
    <param-name>javax.faces.CONFIG_FILES</param-name>
    <param-value>/WEB-INF/faces-config.xml,/WEB-INF/faces-managed-beans.xml,/WEB-INF/faces-navigation.xml</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.SKIN</param-name>
    <param-value>blueSky</param-value>
</context-param>
<context-param>
    <param-name>org.richfaces.CONTROL_SKINNING</param-name>
    <param-value>enable</param-value>
</context-param>
<context-param>
    <param-name>com.sun.faces.validateXml</param-name>
    <param-value>true</param-value>
</context-param>
<filter>
    <display-name>RichFaces Filter</display-name>
    <filter-name>richfaces</filter-name>
    <filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
    <filter-name>richfaces</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
</filter-mapping>
<listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
<!-- Faces Servlet -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>
        org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<login-config>
    <auth-method>BASIC</auth-method>
</login-config>

faces-config.xml

<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<validator>
    <validator-id>com.test..view.validator.Regex</validator-id>
    <validator-class>com.test..view.validator.regex.RegexValidator</validator-class>
</validator>
<application>
    <locale-config>
        <default-locale>en</default-locale>
    </locale-config>
    <message-bundle>com.test..view.resources.bundle.Messages</message-bundle>
</application>
</faces-config>

JSP file

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<html> 
<head>
</head>
<body onload="alert(\"test\")">
    It works <hr/>
<f:view>
<h:form>
<ui:repeat value="${buildVehicleBean.buildVehicleBO.allVehicles}" var="var1">
    <h:outputText value="#{var1.modelLineName}"/><br/>
</ui:repeat>

</h:form>
</f:view>
</body>

</html>

When I view source in browser, I see

...
<ui:repeat value="[com.test.model.bo.CarBO@3f9ba5,
com.test.model.bo.CarBO@38662,
com.test.model.bo.CarBO@16b9c59,
com.test.model.bo.CarBO@1e5bbb0,
com.test.model.bo.CarBO@1855620,
com.test.model.bo.CarBO@d984ff,
com.test.model.bo.CarBO@1dd4000,
com.test.model.bo.CarBO@100bb12,
com.test.model.bo.CarBO@f9d8ce]" var="var1">


<br/>
</ui:repeat>
...

As you see nothing other than 'br' tag within ui:repeat.

It seems very simple to me, obviously I am missing something somewhere, it is hard to find it. If I use something simple like a constant value it works

<h:outputText value="#{12345}"/><br/>
<h:outputText value="#{buildVehicleBean.testDouble}"/><br/>

If I use '#' instead of '$' in the following line it gives error

<ui:repeat value="${buildVehicleBean.buildVehicleBO.allVehicles}" var="var1">

I new to JSF and coming from JSP & Struts background.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

星星的轨迹 2025-01-10 15:20:30

标签是 Facelets 查看技术。但您仍在使用古老的 JSP 视图技术。它们不能一起使用。您不能在 JSP 中使用 Facelets 标记,反之亦然。基本上,Facelets 是JSP 的继承者。

您有 2 个选择:

  1. 用 Facelets 替换 JSP。如果您有很多现有的 JSP 页面,那么这将是一项相当大的工作。如需参考,请检查以下链接:

  2. 使用 JSTL 或 RichFaces 的 相反。它们提供相似的语法和功能。您应该只考虑 JSTL 在视图构建期间运行,而 RichFaces 在视图渲染期间运行。根据您的 web.xml,您似乎已经在使用 RichFaces。因此,只需在 JSP 顶部声明 a4j 标记库并使用 如下:

    <%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>;
    ...
    
        
    >

The <ui:repeat> tag is part of Facelets view technology. But you're still using the ancient JSP view technology. They cannot be used together. You cannot use Facelets tags in JSP or the other way round. Basically, Facelets is the successor of JSP.

You have 2 options:

  1. Replace JSP by Facelets. This is quite a work if you have a lot of existing JSP pages though. For references, check the following links:

  2. Use JSTL <c:forEach> or RichFaces' <a4j:repeat> instead. They offer similar syntax and functionality. You should only take into account that the JSTL one runs during view build time while the RichFaces' one runs during view render time. Based on your web.xml, you seem to be already using RichFaces. So just declare the a4j taglib in top of JSP and use the <a4j:repeat> as follows:

    <%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
    ...
    <a4j:repeat value="#{buildVehicleBean.buildVehicleBO.allVehicles}" var="var1">
        <h:outputText value="#{var1.modelLineName}"/><br/>
    </a4j:repeat>
    
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文