我在我的应用程序中使用JSF 1.2。我想通过它在我的支持bean定义这样一个String数组遍历:不知道如何遍历提供的“项目”<c:forEach>
private String[] services;
下面是面孔-config文件管理bean条目:
<managed-bean>
<managed-bean-name>registrationBean</managed-bean-name>
<managed-bean-class>com.bean.RegistrationBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
我想迭代通过用户选择的服务并将其显示在我的屏幕中。下面是我使用的代码:
<c:forEach items="#{registrationBean.services}" var="service">
<c:out value="${service}"></c:out>
</c:forEach>
但我得到的错误:
Don't know how to iterate over supplied "items" in <c:forEach>
请让我知道如何解决这个问题。
编辑
如果我改变String[]
到List<String>
然后我得到这个异常:
java.lang.RuntimeException: wrapped Exception: java.lang.UnsupportedOperationException
com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:156)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.icesoft.faces.webapp.xmlhttp.BlockingServlet.service(BlockingServlet.java:56)
下面是支持bean初始化:
private List<String> services;
public RegistrationBean() {
this.services = new ArrayList<String>();
}
faces-config.xml中:
<?xml version='1.0' encoding='UTF-8'?>
<managed-bean>
<managed-bean-name>registrationBean</managed-bean-name>
<managed-bean-class>com.bean.RegistrationBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<description>This will navigate to the Success screen.</description>
<from-view-id>/registration.jspx</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/success.jspx</to-view-id>
</navigation-case>
</navigation-rule>
web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<description>
ICEfaces Address Demo
</description>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<context-param>
<param-name>javax.faces.application.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<context-param>
<param-name>com.sun.faces.validateXml</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>com.icesoft.faces.synchronousUpdate</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>
<listener>
<listener-class>com.icesoft.faces.util.event.servlet.ContextEventRepeater</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>
<servlet>
<servlet-name>Persistent Faces Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<servlet>
<servlet-name>Blocking Servlet</servlet-name>
<servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>
<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jspx</url-pattern>
</servlet-mapping>
<!-- Persistent Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>*.iface</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Persistent Faces Servlet</servlet-name>
<url-pattern>/xmlhttp/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Blocking Servlet</servlet-name>
<url-pattern>/block/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
尝试更改'列表'的'String []''。 –
2013-04-10 15:58:35
我试过了,但得到了我的第一篇文章的编辑部分提到的异常。任何进一步的帮助呢? – user182944 2013-04-10 16:03:19
您确定您的托管bean已创建,列表服务在您的bean构造函数或@ PostConstruct方法中初始化,并且不是空的,并且getter是干净的:public List getService(){return this。服务; }'? –
2013-04-10 16:06:47