質問
jspページに表示する情報を保持するBeanのベクトルがあります。現在、これを表示するために標準のJava式を使用していますが、jstlを使用して懸念を分離したいと考えています。これは可能ですか?グーグルで検索しましたが、何も見つかりません。
解決
探しているのは <!> lt; c:foreach <!> gt; タグ。
たとえば、MyClassのインスタンスでmyIntプロパティの値を出力する(以下で定義):
<c:foreach items="${vectors name}" var="pos" >
<!-- print the value of myInt for each position of the array.
Method getMyInt() must exist in pos object.-->
<c:out value="${pos.myInt}"/>
<!-- print the value of myInt for each composed instance.
Method getRelatedInstance() must exist in pos object. -->
<c:out value="${pos.relatedInstance.myInt}"/>
</c:foreach>
ここで、ベクター名はベクターの名前です。たとえば、
クラスmyClassがあるとします。
public class MyClass{
private MyClass relatedInstance;
//some members and methods
public int getMyInt(){
//return something
}
public MyClass getRelatedInstance(){
return this.relatedInstance;
}
List<myClass> my_vector = getFilledList();
request.setAttribute("vectors name",my_vector)
他のヒント
トムの例に費やすために、より具体的なものを次に示します。
<c:foreach items="${myList}" var="myItem">
<c:out value="${myItem.someProperty}"/>
</c:foreach>
Where <!> quot; myList <!> quot;ベクターを含むリクエスト属性です。
一般的なエラーは、$ {myList}の周りの$ {}を忘れることです。これを行うと、JSTLはエラーをスローせず、単一のアイテム、ストリング<!を持つリストを生成します。 > quot; myList <!> quot;。
所属していません StackOverflow