2012-03-09 4 views
2

txtファイルRegistrationFormBean()から読み込んだオブジェクトのArrayListがあります。要素型オブジェクトのArrayListに対するStruts 1.1の論理反復子

public List getuserList() throws IOException{ 

      InputStream input = new FileInputStream("log.txt"); 

       int i=0; 

       String temp[]=new String[5]; 

              tmp= new RegistrationFormBean(); 
       BufferedReader in = new BufferedReader(new FileReader("log.txt")); 

       while ((str = in.readLine()) != null) { 

           StringTokenizer st = new StringTokenizer(str,"\t\t"); 

        while(st.hasMoreElements()){ 
        temp[i]=st.nextElement().toString(); 
               } 

                tmp.setName(temp[0]); 
        tmp.setCognome(temp[1]); 
        tmp.setCitta(temp[4]); 
        tmp.setDdnascita(temp[2]); 
        tmp.setCodfisc(temp[3]); 

        userList.add(tmp); 
             } 
       in.close(); 

    return userList; 
} 

これはArrayListのを反復処理する必要があるJSPページが返され、配列リストの各要素の属性を印刷

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %> 
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> 
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<jsp:useBean id="userList" scope="request" class="com.webagesolutions.struts.actions.query"/> 



<html:html> 
<HEAD> 
<%@ page 
language="java" 
contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1" 
%> 
<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> 
<META name="GENERATOR" content="IBM WebSphere Studio"> 
<META http-equiv="Content-Style-Type" content="text/css"> 
<LINK href="theme/Master.css" rel="stylesheet" type="text/css"> 
<TITLE></TITLE> 
</HEAD> 

<BODY> 
    <table border=1> 
     <logic:iterate name="userList" id="nextElement" property="userList"> 
    <tr> 
    <td><bean:write name="nextelement" property="name"/></td> 
    <td><bean:write name="nextElement" property="cognome"/></td> 
    <td><bean:write name="nextElement" property="ddnascita"/></td> 
    <td><bean:write name="nextElement" property="codfisc"/></td> 
    <td><bean:write name="nextElement" property="citta"/></td> 
    </tr> 
    </logic:iterate>   
    </table> 
</BODY> 
</html:html> 

は、だから私は、要素にアクセスする方法を思ったんだけどさ次の要素のうち、プロパティがelement.name element.cognome element.ddnascita(要素の属性)であるとすると、txtファイルを読み込むクラスにいくつかのゲッターを定義する必要がありますか? jspページの要素タイプを参照する必要がありますか?

私が書いたコードでは、最初の列しか印刷されず、tmpの「citta」が要素の最後の属性であることを示しています。 また、デバッグとリストを実行しました正しくロードされるので、私が想定している問題はJSPページにあります。

答えて

3

<nested:nest>タグを使用すると、ネストされたプロパティにアクセスできます。 がそれを使用するには、JSPページ内のtaglibを追加する必要があります。

<%@ taglib uri="/tags/struts-nested" prefix="nested"%> 

を上記の例では、あなたは、いくつかのcognomeのような複合性等、プレーン文字列プロパティを持つ親豆のリストとしてuserListを持っていますname。さて、このようなuserListを反復起動します。私は、カスタムに関するいくつかのまともな参照は、タグを支柱見つけることができるApacheのページの横に、探していたものである

<nested:nest property="userList"> 
    <!-- 'name' is just plain String, does not need a nested iteration --> 
    <nested:write property="name"/> 

    <!-- but 'cognome' has some inner properties, we are interested in exploring --> 
    <nested:iterate property="cognome"> 
     <nested:write property="somePropertyOfCognome"/> 
    </nested:iterate> 

</nested:nest> 
+0

THX? –

関連する問題