gpt4 book ai didi

apache-flex - 无法从 FLEX (BlazeDS) 调用 EJB

转载 作者:行者123 更新时间:2023-12-04 07:08:16 26 4
gpt4 key购买 nike

现在我正在玩 Flex 和 Java 集成,并尝试通过单击 Flex 按钮访问 EJB3 方法,但它给了我空指针错误。

这是我的代码中的内容:

[ Controller :]

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";
}
}

[类别门面]
@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));
}
}

...
}

[远程配置.xml]
...
<destination id="homePageController">
<properties>
<source>homePageController</source>
</properties>
</destination>
...

[Flex 应用程序。文件]
...
<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 作为我的应用程序。服务器。

最佳答案

您是否在使用 ejb3 factory ?

关于apache-flex - 无法从 FLEX (BlazeDS) 调用 EJB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/770391/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com