Adding Java Code for the
Controller
After you have successfully executed all the required declarative development steps, you now need to add some individual lines of Java code for the view controller.
Within each controller, there are some predefined places where you can add source code. These include, in particular, the standard methods wdDoInit() and wdDoExit(),and also the Action Event-Handler in the view controllers.
wdDoInit() is always controlled if the controller is instanced. For this reason, you must remember that at this point there is an object that – at runtime – represents the entire input, including all the input parameters for calling the business method.
1. Open the Java editor for the view controller.
2. Add the following source code for the action event handler onActionGetStudent between //@@begin and //@@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();
} catch (Exception e) {
e.printStackTrace();
}
//@@end
}
3. Add the following source code in the wdDoInit() method of the view controller.
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
}
4. Adjust the package name for the model class – if required.
5. Save the new content.
Deploying and Running the Sample Application