cancel
Showing results for 
Search instead for 
Did you mean: 

CE 7.1 Webdynpro & Java Tutorial > model object must not be null

andre_langhorst
Employee
Employee
0 Kudos

Hi there,

I did the EJB3+Webdynpro Tutorial at http://help.sap.com/saphelp_nwce10/helpdata/en/44/D958673EF05F4DE10000000A11466F/frameset.htm

Unfortunately a model node element seems not to be created (is null). I checked everything what I did twice (every code mentioned is in the controller). What could the problem be?

Cheers,

André

java.lang.IllegalArgumentException: model object must not be null

at com.sap.tc.webdynpro.progmodel.context.ModelNodeElement.(IPrivateStudsWDView.java:397)

at com.sap.demo.wdstuds.studswdapp.comp.wdp.IPrivateStudsWDView$IContextNode.doCreateElement(IPrivateStudsWDView.java:66)

at com.sap.tc.webdynpro.progmodel.context.NodeInfo.createElement(NodeInfo.java:1064)

at com.sap.tc.webdynpro.progmodel.context.Node.createElementInternal(Node.java:1047)[/code]

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Basically this execption occurs when you are trying to create a element in a model node, where in the model

object is not instantiated inside wdDoInit() of the component controller.

andre_langhorst
Employee
Employee
0 Kudos

I did write no code in the component controller, I used the view controller (I know and it is stated within the tutorial that this is not good practice, but that it should work).

Here are my view controller methods:


  public void wdDoInit()
  {
    //@@begin wdDoInit()
	     com.sap.tc.cm.ejb.example.model.MyStudsModel myModel = new com.sap.tc.cm.ejb.example.model.MyStudsModel();

	     wdComponentAPI.getModelInstanceMap().putDefaultInstance("com.sap.tc.cm.ejb.example.model.MyStudsModel", myModel);
    //@@end
  }

  public void onActionGetStudent(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionGetStudent(ServerEvent)

     try {

        // executes the corresponding method on the session facade

        wdContext.currentRequest_StudsLocal_getStudentElement().

        modelObject().execute();

       

        // forces Web Dynpro to re-create the Request model object

        // in order to clear the InputField

        wdContext.nodeRequest_StudsLocal_getStudent().invalidate();

       

        // updates the UI elements bound to the Response node

        wdContext.nodeResponse().invalidate();

     } catch (Exception e) {

        e.printStackTrace();

     }   

    //@@end
  }

It should be instantiated at this point? Maybe the problem is with modelObject() != myModel ?

Former Member
0 Kudos

Hi,

public void wdDoInit()
  {
    //@@begin wdDoInit()
	     com.sap.tc.cm.ejb.example.model.MyStudsModel myModel = new com.sap.tc.cm.ejb.example.model.MyStudsModel();
 <b>wdContext.nodeRequestMyStudsModel().bind(myModel );</b>
	     wdComponentAPI.getModelInstanceMap().putDefaultInstance("com.sap.tc.cm.ejb.example.model.MyStudsModel", myModel);
    //@@end
  }

Regards,

Naga

andre_langhorst
Employee
Employee
0 Kudos

does not work:

The method nodeRequestMyStudsModel() is undefined for the type 
 IPrivateStudsWDView.IContextNode

andre_langhorst
Employee
Employee
0 Kudos

sorry, I had a typo, now I get this error

The method bind(IPrivateStudsWDView.IRequest_StudsLocal_getStudentElement) 
 in the type IPrivateStudsWDView.IRequest_StudsLocal_getStudentNode is not 
 applicable for the arguments (MyStudsModel)

Former Member
0 Kudos

hia,

soryy bind it to

nodeMyStudsModel()

Regards,

Naga

andre_langhorst
Employee
Employee
0 Kudos

there is no such method in WDContext!

Answers (2)

Answers (2)

andre_langhorst
Employee
Employee
0 Kudos

This is not answered, I'll restate the question because the page is so full.

former_member751941
Active Contributor
0 Kudos

Hi Andre,

Please check the name of the model node in the context.

Then try.

public void wdDoInit()

{

//wdContext.node<ModelName>().bind(<ModelName>() ServiceProxy.create());

wdContext.nodeMyStudsModel().bind(MyStudsModelServiceProxy.create());

}

In side “onActionGetStudent” Method don’t use "wdContext.nodeResponse().invalidate();"

Regards,

Mithu

andre_langhorst
Employee
Employee
0 Kudos

hi, my model is not a node in the context, hence I cannot use the nodes your tell me to! only its descendants are nodes eg. nodeAdress(), nodeRequest..., nodeResponse

Is my context not okay?

andre_langhorst
Employee
Employee
0 Kudos

I have no clue why, but now it works. Another question:

I have no one mapped node in the view context and one string attribute to take the value. What's the best way to get the value to the component controller? Directly mapping the input field attribute does not work.

andre_langhorst
Employee
Employee
0 Kudos

Now I found the problem, whenever I set the Controllers Model cardinality from 0..n to 1..1 (it should be automatically created then I guess) I get:

   java.lang.IllegalArgumentException: model object must not be null

on launching the application. How do I get around this?

andre_langhorst
Employee
Employee
0 Kudos

Another hint, maybe it's due to that I am using an EJB3 model. I cannot map the whole model in the context editor and I don't have these ServiceProxy objects.