【发布时间】:2013-12-26 10:06:51
【问题描述】:
我需要在我的页面上创建一个命令按钮列表,但我遇到了一些问题。我通过 request.setAttribute 从我的 bean 传递列表,当我一次获取一个值时它似乎工作,但是当我通过 foreach 循环运行时,它们似乎都是空的(因此被生成,并有一个据我所知,默认值 0、“”等)。任何帮助将不胜感激!在添加的代码中,当我在 foreach 循环之外制作按钮时,我得到了正确的值,但在我运行循环本身时却没有。 List 是整数类型,以后应该是 java 对象(遇到同样的问题)。使用 JSF 2.2 版。 logtest() 和 gotoprofile() 都打印出interestpointer。
我的豆子有:
@ManagedBean(name="MyProfile")
@RequestScoped
我在我的 bean 中设置了我的变量 myInterestList:
HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
session.setAttribute("myInterestProfileName", profileName);
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@ page import="java.util.List,com.jsflogin.stringWithPointer" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<f:view>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSF Successfull login</title>
</head>
<body>
<h:form id="forloop">
<c:set var ="myTempList" value="${myInterestListYay}" scope="session"/>
<c:out value="interest list"/><p>
<h:commandButton value="#{myInterestListYay[1]}" action="#{MyProfile.logTest}">
<f:setPropertyActionListener target ="#{MyProfile.interestPointer}" value = "#{myInterestListYay[1]}"/>
</h:commandButton><p>
<ui:repeat var="orly"value="${myInterestListYay}" varstatus="status">
<c:out value="${status.index}"/><h:commandButton value="#{orly}" action="#{MyProfile.logTest}">
<f:setPropertyActionListener target ="#{MyProfile.interestPointer}" value = "#{orly}"/>
</h:commandButton><p>
</ui:repeat>
<c:forEach var="orly" items="${MyProfile.interestsAndPointers}" varStatus="status" >
<c:out value="${status.index}"/><c:out value=": "/><c:out value="${orly.stringName}"/><h:commandButton value="go to interest page" action="#{MyProfile.goToInterestProfile}">
<f:setPropertyActionListener target ="#{MyProfile.interestPointer}" value = "#{orly.pointer}"/>
</h:commandButton><p>
</c:forEach>
</h:form>
</body>
</f:view>
</html>
【问题讨论】:
-
使用 ${orly} 代替 #{orly}
-
我在尝试编译时收到此错误。 "根据TLD,属性值为deferred-value或deferred-method,但指定值包含$-expression"
标签: java web-services jsp jsf foreach