私はfileUpload
のためにmanagedBean
を持っています。一度ファイルがアップロードされたら、パーサのドロップダウンから選択された値に基づいて別のパーサを呼び出す必要があります。DetailsClass
のオブジェクトを作成しています。ここで注目すべきは、parserClass
もDetailsClass
がfaces-config.xmlに登録されていないどちらも、ここでの私の質問は、私はDetailsClass
にParser
クラスにFileUpload
クラスからセッション情報を保持したい場合は、私はfaces-config.xml
でそれを定義する必要がありますJSF:ManagedBean、ビジネスロジックを扱うには良い場所ですか?
- であるということですしかし、どうすれば
parser
クラスとDetailsClass
を定義する必要があります。それはmanagedBean
などと定義する必要がありますか?ここで
はコードです:私は私のmanagedBeanクラスで
示すように、2つの機能、fileUpload
とcallParser
:
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
から呼び出していくつかのビジネス これらのクラスのロジックは良い練習と見なされますか?
はまた、私は私がParser
とContractMapping
クラス全体でUploadFile
で取得セッションを維持することを確認する必要があります。また
は、すべてが顔-configに管理対象Beanとして '登録' されますか?
私の質問は明確であるか、混乱があります。私に教えてください。私は質問に肉を追加することができます。 – Rachel