現在我正在玩Flex和Java集成,並試圖通過單擊Flex按鈕來訪問EJB3方法,但它給了我空指針錯誤。無法從FLEX(BlazeDS)調用EJB
以下是我在我的代碼:
[控制器:]
public class homePageController {
@EJB
CategoryFacadeRemote categoryFacade;
public String populateDBWithXMLData(){
ArrayList<Category> cats = new ArrayList<Category>();
cats = new QuestionsUtil().getCategories();
try{
categoryFacade.createMany(cats);
}
catch(EJBException ex){
ex.printStackTrace();
}
System.out.println("SIZE: " + cats.size());
return "HIIIIII";
}
}
[CategoryFacade]
@Stateless
public class CategoryFacade implements CategoryFacadeLocal, CategoryFacadeRemote {
@PersistenceContext
private EntityManager em;
public void create(Category category) {
em.persist(category);
}
public void createMany(ArrayList<Category> categories){
for(int i = 0; i < categories.size(); i++){
create(categories.get(i));
}
}
...
}
[遠程-config.xml中]
...
<destination id="homePageController">
<properties>
<source>homePageController</source>
</properties>
</destination>
...
[Flex App。文件]
...
<mx:RemoteObject id="hcRO" destination="homePageController"></mx:RemoteObject>
<mx:Script>
...
private function callHomePageController():void{
hcRO.addEventListener(ResultEvent.RESULT, hcROResultHandler);
hcRO.addEventListener(FaultEvent.FAULT, hcROFaultHandler);
hcRO.populateDBWithXMLData();
}
private function hcROResultHandler(eve:ResultEvent):void{
Alert.show("RESULT:" + eve.message.body.toString());
}
private function hcROFaultHandler(eve:FaultEvent):void{
Alert.show("FAULT:" + eve.message.toString());
}
]]>
</mx:Script>
<mx:Button x="148" y="222" label="homePageController" click="callHomePageController()" width="262" height="43"/>
</mx:Application>
如果我拿出對EJB的調用,程序工作正常。我確信解決方案很簡單,但我無法弄清楚。
順便說一句,我使用Glassfish作爲我的應用程序。服務器。
我遇到了同樣的問題。由於這只是我搞亂的事情,我終於放棄了。我確信這是愚蠢的我正在做...只是不知道什麼 – 2009-04-20 22:52:05