我有managedBean
的fileUpload
,一旦文件被上传,然后我需要调用基于从解析器下拉列表中选择什么样的价值,然后在解析器正在创建的对象不同的解析器DetailsClass
我在哪里调用getDetails
针对特定类的方法,一点需要注意的是,无论parserClass
也不DetailsClass
是注册在faces-config.xml中,我的问题是在这里
- 如果我想保持从会话信息
FileUpload
类Parser
类DetailsClass
那么我就应该将其定义在faces-config.xml
,但是应该如何parser
类和DetailsClass
来定义,它应该被定义为managedBean
或像别的东西吗?
下面是代码:
在我managedBean类我有两个功能, 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);
}
}
现在,让我们说,我们考虑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();
}
}
}
我contractManager
类的样子
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文件,
<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>
所以基本上我的问题是,
如果假设我打电话从其他类
managedBean
那怎么办,他们中定义faces-config.xml
,自是新的JSF
,从调用其他类managedBean
并具有好的做法那些类一些业务逻辑?
此外,我需要确保我认为,我在获取会话UploadFile
跨越Parser
和ContractMapping
类。
也,
是一切“注册”在脸上,配置管理,豆?