2012-04-23 6 views
1

私はfileUploadのためにmanagedBeanを持っています。一度ファイルがアップロードされたら、パーサのドロップダウンから選択された値に基づいて別のパーサを呼び出す必要があります。DetailsClassのオブジェクトを作成しています。ここで注目すべきは、parserClassDetailsClassがfaces-config.xmlに登録されていないどちらも、ここでの私の質問は、私はDetailsClassParserクラスにFileUploadクラスからセッション情報を保持したい場合は、私はfaces-config.xmlでそれを定義する必要がありますJSF:ManagedBean、ビジネスロジックを扱うには良い場所ですか?

  • であるということですしかし、どうすればparserクラスとDetailsClassを定義する必要があります。それはmanagedBeanなどと定義する必要がありますか?ここで

はコードです:私は私のmanagedBeanクラスで

示すように、2つの機能、fileUploadcallParser

public void uploadFile(FileEntryEvent event) 
{ 
    FacesContext ctx = FacesContext.getCurrentInstance(); 
    //Setting getSession to false, container will not create new session if session is not present and return null 
    HttpSession session = (HttpSession) ctx.getExternalContext().getSession(false); 
    setSession(session); 

    resultBean = new ResultBean(); 
    FileEntry fileEntry = (FileEntry) event.getSource(); 
    FileEntryResults results = fileEntry.getResults(); 
    FileEntry fe = (FileEntry) event.getComponent(); 

    FacesMessage msg = new FacesMessage(); 
    for (FileEntryResults.FileInfo fileInfo : results.getFiles()) 
    { 
     if (fileInfo.isSaved()) 
     { 
      File file = fileInfo.getFile(); 
      String filePath = file.getAbsolutePath(); 
      callParser(selectedItem, filePath); 
     } 
     resultBeanList.add(resultBean); 
    } 
} 

private void callParser(String parserType, String filePath) 
{ 
    if ("Delta".equals(parserType)) 
    { 
     PositionParserDelta deltaParser = new PositionParserDelta(); 
     deltaParser.getQuotes(filePath); 
    } 
    else if ("Gamma".equals(parserType)) 
    { 
     PositionParserGamma gammaParser = new PositionParserGamma(); 
     gammaParser.getQuotes(filePath); 
    } 
} 

、我々はそのクラスIになるよう、Delta Parserを考えましょう

public class PositionParserDelta extends Base 
{ 
    List<String[]> dataList = new ArrayList<String[]>(); 
    ContractManager contractManager = new ContractManager(); 

    public PositionParserDelta() 
    { 
    } 

    public void getQuotes(String fileName) 
    { 
     try 
     { 
      Map<String, ContractSeries> gsLookup = contractManager.getContractsMap(ContractManager.VendorQuotes.KRT); 
      CSVReader reader = new CSVReader(new FileReader(fileName), '\t'); 
      String[] header = reader.readNext(); 
      dataList = reader.readAll(); 
      List<Trade> tradeBeanList = new ArrayList<Trade>(); 
      for (String[] data : dataList) 
      { 
       //Some Business Logic 
      } 
     } 
     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 
} 

My contractManager Clas Sだから基本的に仮定するが べきか、その後managedBeanから他のクラスを呼び出していた場合、私の質問は、

ある

<managed-bean> 
     <managed-bean-name>fileUpload</managed-bean-name> 
     <managed-bean-class>trade.UploadBlotterBean</managed-bean-class> 
     <managed-bean-scope>session</managed-bean-scope> 
</managed-bean> 

public class ContractManager extends Base 
    { 
     private List<Series> List = new ArrayList<Series>(); 
     private ContractSeries[] SeriesList = new Series[3]; 
     private ListingOps listingOps; 

//This line throws error as faces class not found and it makes sense because am not registering this with faces-config.xml 
     HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false); 

     public List<ContractSeries> getContracts(long orgId, HttpSession session) 
     { 
      log.info("Inside getContracts method call"); 
      if (false) 
      { 
       //Some Logic 
      } 
      else 
      { 
       try 
       { 
        //Set session and get initialContext to retrieve contractSeries data from ejb calls 
        log.info("Trying to get allContractSeries data from listingOpsBean"); 
        Series[] allSeries = deltaOps.findAllSeries(true); 
        Collections.addAll(contractList, allContractSeries); 
       } 
       catch (Exception ex) 
       { 

       } 
      } 
      return contractList; 
     } 

     public Map<String, ContractSeries> getContractsMap(VendorQuotes vendorQuotes) 
     { //Some Logic 
    } 

ようしかし、faces-config.xmlファイル内を検索しますfaces-config.xmlに定義され、JSFに新規登録されているので、 となり、他のクラスをmanagedBeanから呼び出していくつかのビジネス これらのクラスのロジックは良い練習と見なされますか?

はまた、私は私がParserContractMappingクラス全体でUploadFileで取得セッションを維持することを確認する必要があります。また

は、すべてが顔-configに管理対象Beanとして '登録' されますか?

+0

私の質問は明確であるか、混乱があります。私に教えてください。私は質問に肉を追加することができます。 – Rachel

答えて

1

わかりませんが、すべての豆は<managed-bean>faces-configとして登録されています。特定の役割には、クラスの演劇は、彼らが

  1. Model Managed-Bean

  2. バックマネージド・ビーン

  3. コントローラーマネージド・ビーン

  4. サポートマネージド・ビーン

    に分類することができます
  5. ユーティリティマネージドビーン...

適切な名前を付けることで、faces-configで区別できます。 Beanが提供する作業ごとに、スコープを設定します。

+0

「managedBean」と「managedProperty」の違いは何ですか? – Rachel

+0

http://stackoverflow.com/questions/4713483/difference-between-managed-bean-and-backing-bean – Vyoma

関連する問題