Search code examples
web-servicessoaporacle-adfjdeveloper

How to create new record from web service in ADF?


I have created a class and published it as web service. I have created a web method like this:

    public void addNewRow(MyObject cob) {
    MyAppModule myAppModule = new MyAppModule();
    try {
        ViewObjectImpl vo = myAppModule.getMyVewObject1();
    ================> vo object is now null
        Row r = vo.createRow();
        r.setAttribute("Param1", cob.getParam1());
        r.setAttribute("Param2", cob.getParam2());
        vo.executeQuery();
        getTransaction().commit();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

As I have written in code, myAppModule.getMyVewObject1() returns a null object. I do not understand why! As far as I know AppModule has to initialize the object by itself when I call "getMyVewObject1()" but maybe I am wrong, or maybe this is not the way it should be for web methods. Has anyone ever faced this issue? Any help would be very appreciated.


Solution

  • You can check nice tutorial: Building and Using Web Services with JDeveloper It gives you general idea about how you should build your webservices with ADF.

    Another approach is when you need to call existing Application Module from some bean that doesn't have needed environment (servlet, etc), then you can initialize it like this:

    String appModuleName = "org.my.package.name.model.AppModule";
    String appModuleConfig = "AppModuleLocal";
    ApplicationModule am = Configuration.createRootApplicationModule(appModuleName, appModuleConfig);
    

    Don't forget to release it:

    Configuration.releaseRootApplicationModule(am, true);
    

    And why you shouldn't really do it like this.
    And even more...

    Better aproach is to get access to binding layer and do call from there.
    Here is a nice article.