Sayfamda bir komut listesi listesi oluşturmam gerekiyor, ancak bununla ilgili bir sorunum var. Listeyi request.setAttribute aracılığıyla fasulyemden geçiriyorum ve değerleri her seferinde bir tane elde ettiğimde işe yarayacak gibi görünüyor, ancak bir foreach döngüsünden geçtiğimde, hepsi boş görünüyor (Ve bu nedenle üretiliyor ve bir varsayılan değer 0, "", bildiğim kadarıyla). Herhangi bir yardım büyük takdir edilecektir! Eklenen kodda, foreach döngüsünün dışında düğmeler yaptığımda doğru değerleri alıyorum, ancak döngüyü kendim çalıştırdığımda değil. Liste tamsayı tipindedir ve daha sonra bir java nesnesi olmalıdır (aynı probleme göre). JSF sürüm 2.2'yi kullanarak. Hem logtest() hem de gotoprofile(), ilgi alanı çıktısını yazdırır.JSF'de foreach döngüsünü kullanma
benim fasulye vardır:
@ManagedBean(name="MyProfile")
@RequestScoped
Ve benim fasulye benim değişken myInterestList ayarlayın: o zaman, JSF 2 kullanıyorsanız, xhtml sayfanızı değiştirmelisiniz
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>
kullanın $ {orly} yerine no {orly} bu hatayı alıyorum –
derlemeye çalışırken. "TLD'ye göre, öznitelik değeri bir degerlendirilmiş değer veya ertelenmiş yöntemdir, ancak belirtilen değer bir $ -ifadesi içerir" – user3058296