私のページにコマンドボタンのリストを作成する必要がありますが、いくつか問題があります。私はbeanからrequest.setAttributeを通してリストを渡します。そして、一度に値を取得するときにはうまくいくように見えますが、foreachループを実行すると、それらはすべてnullのように見えます(そして、生成され、デフォルト値0、 ""など、私が知る限り)。どんな助けでも大歓迎です!追加されたコードでは、foreachループの外側にあるボタンを作成するときに正しい値を取得しますが、ループ自体を実行しないときは取得しません。 Listは整数型であり、後でJavaオブジェクト(同じ問題に遭遇した)でなければなりません。 JSFバージョン2.2を使用します。 logtest()とgotoprofile()の両方が、目的のポインタを出力します。JSFでforeachループを使用する
私のBeanがあります。
@ManagedBean(name="MyProfile")
@RequestScoped
そして、私は私の豆で私の変数myInterestListを設定します。そして、あなたはJSF 2を使用している場合は、XHTMLにあなたのページを変更する必要があり
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>
使用$ {}オルリー代わりに#{}オルリー –
をコンパイルしようとしているときに、私はこのエラーを取得します。 "属性値はdeffered-valueまたはdeferred-methodですが、指定された値には、テキスト本体に許可されていない$ -expression" – user3058296