2010-11-25 72 views
0

我在一個類中設置java bean的值。如何獲得另一個類的價值可以有人給例子?如何從java的另一個類的bean中獲取值

import java.util.ArrayList; 

public class HomeBean { 
    String indexname=""; 
    String lastvalue="";  
    String changepercentage=""; 
    ArrayList aindexname=new ArrayList(); 
    ArrayList alastname=new ArrayList(); 
    ArrayList alastpercentage=new ArrayList(); 
    public String getIndexname() { 
     return indexname; 

    } 
    public void setIndexname(String indexname) { 
     this.indexname = indexname; 
     System.out.println("******index name is *****"+indexname); 
     aindexname.add(indexname); 

    } 

    public String getLastvalue() { 
     return lastvalue; 
    } 
    public void setLastvalue(String lastvalue) { 
     this.lastvalue = lastvalue; 
    } 
    public String getChangepercentage() { 
     return changepercentage; 
    } 
    public void setChangepercentage(String changepercentage) { 
     this.changepercentage = changepercentage; 
    } 
    public ArrayList getArrayListIndexName() 
    { 
     for(int i=0;i<aindexname.size();i++) 
     { 
     System.out.println("####indexname is######"+aindexname.get(i).toString()); 
     } 

    return aindexname; 
    } 

    public ArrayList getArrayListLastValue() 
    { 
    return alastname; 

    } 

    public ArrayList getArrayListChangePercentage() 
    { 

    return alastpercentage;  
    } 




} 

一類

mport java.util.ArrayList; 

import org.w3c.dom.Document; 
import org.w3c.dom.Element; 
import org.w3c.dom.Node; 
import org.w3c.dom.NodeList; 

public class DomTableParser 
{ 

ArrayList listTable=new ArrayList(); 
    public ArrayList parseXmlFile(String tableservicevalue){ 
     //get the factory 
    Document doc; 
      StringtoDocument stdoc=new StringtoDocument(); 
       doc=stdoc.getDocument(tableservicevalue); 

       //System.out.println("Information of all employees"); 


       HomeBean bean=new HomeBean(); 
      Element docEle = doc.getDocumentElement(); 




      NodeList indexNode = docEle.getElementsByTagName("INDEX"); 
      if(indexNode != null && indexNode.getLength() > 0) 
      { 
       for(int i = 0 ; i < indexNode.getLength();i++) 
       { 
        Element homeElmnt = (Element)indexNode.item(i); 

        DomParserTableDataSet dataSet=new DomParserTableDataSet(); 
         String indexName = homeElmnt.getAttribute("INDEX_NAME"); 
         String lastValue=homeElmnt.getAttribute("LAST_VALUE");  
         String changePercentage=homeElmnt.getAttribute("CHANGE_PERCENTAGE"); 
         //String questgroupid=loginElmnt.getAttribute("ID"); 
         bean.setIndexname(indexName); 
         bean.setLastvalue(lastValue); 
         bean.setChangepercentage(changePercentage); 
         bean.getArrayListIndexName(); 
         dataSet.setIndexName(indexName); 
         dataSet.setLastValue(lastValue); 
         dataSet.setChangePercentage(changePercentage); 
          listTable.add(dataSet); 



       } 
      } 


     return listTable; 
    } 




} 
+0

設定值,你能解釋一下你的問題的更多細節。 – Megha 2012-02-28 11:53:01

回答

相關問題