cancel
Showing results for 
Search instead for 
Did you mean: 

webdynpro - model based on javabean which uses session bean

Former Member
0 Kudos

Hi there,

I created a project in which a command bean makes use of a session EJB.

A model has then been made from that command bean.

Session EJB


package com.sap.carrefour.ejb;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Collection;

import javax.ejb.CreateException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.naming.InitialContext;
import javax.sql.DataSource;
/**
 * @ejbHome <{com.sap.carrefour.ejb.CarrSessHome}>
 * @ejbLocal <{com.sap.carrefour.ejb.CarrSessLocal}>
 * @ejbLocalHome <{com.sap.carrefour.ejb.CarrSessLocalHome}>
 * @ejbRemote <{com.sap.carrefour.ejb.CarrSess}>
 * @stateless 
 * @transactionType Container
 */
public class CarrSessBean implements SessionBean {

	public void ejbRemove() {
	}

	public void ejbActivate() {
	}

	public void ejbPassivate() {
	}

	public void setSessionContext(SessionContext context) {
		myContext = context;
	}

	private SessionContext myContext;
	/**
	 * Business Method.
	 */
	public String getData(String store_id) {
		String exception = new String();
		String name = new String();
		
		try{
			InitialContext initContext = new InitialContext();
			DataSource dataSource = (DataSource) initContext.lookup("jdbc/CarrefDSAlias");
			Connection conn = dataSource.getConnection();
			PreparedStatement stmt = conn.prepareStatement("select * from DEPOT where DC_ID = ?");
			stmt.setString(1,store_id);
			ResultSet res = stmt.executeQuery();
			while(res.next()){
				name = res.getString("DC_NAME");
			}
			conn.close();
		}
		catch(Exception e){

		}
		return name;
	}


	/**
	 * Create Method.
	 */
	public void ejbCreate() throws CreateException {
		// TODO : Implement
	}

}

Command bean


/*
 * Created on Jun 16, 2008
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package com.sap.carrefour;

import java.util.ArrayList;
import java.util.Collection;

import javax.naming.Context;
import javax.naming.InitialContext;

import com.sap.carrefour.ejb.CarrSessLocal;
import com.sap.carrefour.ejb.CarrSessLocalHome;

/**
 * @author AllanDu
 *
 * To change the template for this generated type comment go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
public class CarrCommandBean{
	Collection coll = new ArrayList();
	CarrSessLocal session = null;

	String id = new String();
	String name = new String();

	public CarrCommandBean(){
		try {
			Context con = new InitialContext();
			CarrSessLocalHome home = (CarrSessLocalHome) con.lookup("sap.com/testCarr_EAR/CarrSessBean");
			session = home.create();			 
		}
		catch(Exception e){
		}
	}
	
	public void getSessData(){
		try{
			name = session.getData(id);
			coll.add(session.getData(id)); 
		}
		catch(Exception e){
		}
	}
	/**
	 * @return
	 */
	public Collection getColl() {
		return coll;
	}

	/**
	 * @param collection
	 */
	public void setColl(Collection collection) {
		coll = collection;
	}

	/**
	 * @return
	 */
	public String getId() {
		return id;
	}

	/**
	 * @return
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param string
	 */
	public void setId(String string) {
		id = string;
	}

	/**
	 * @param string
	 */
	public void setName(String string) {
		name = string;
	}

}

Relation model:

Name Source role Target role Model class

CarrCommandBean.name Source(1...1) name(1...1) CarrCommandBean

Context of controller:

model node: test

attr: id

name

value node: id

attr: idstore

Controller method:


  public void triggerModel( java.lang.String storeid )
  {
    //@@begin triggerModel()
    CarrCommandBean bean = new CarrCommandBean();
	bean.setId(storeid);
	wdContext.nodeTest().bind(bean);
    
    //@@end
  }

View action (button)


  public void onActiontriggerModel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActiontriggerModel(ServerEvent)
    String id = wdContext.currentVidElement().getIdstore();
    wdThis.wdGetTestController().triggerModel(id);
    //@@end
  }

When I execute the wd application I get the following error message:

com.sap.tc.webdynpro.services.exceptions.WDRuntimeException: Failed to create delegate for component com.sap.test.Test. (Hint: Is the corresponding DC deployed correctly? Does the DC contain the component?)

at com.sap.tc.webdynpro.progmodel.generation.ControllerHelper.createDelegate(ControllerHelper.java:110)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingComponent.<init>(DelegatingComponent.java:38)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.doInit(ClientComponent.java:776)

at com.sap.tc.webdynpro.clientserver.cal.ClientComponent.init(ClientComponent.java:330)

at com.sap.tc.webdynpro.clientserver.cal.ClientApplication.init(ClientApplication.java:382)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.execute(WebDynproMainTask.java:618)

at com.sap.tc.webdynpro.clientserver.cal.AbstractClient.executeTasks(AbstractClient.java:59)

at com.sap.tc.webdynpro.clientserver.cal.ClientManager.doProcessing(ClientManager.java:251)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doWebDynproProcessing(DispatcherServlet.java:154)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doContent(DispatcherServlet.java:116)

at com.sap.tc.webdynpro.serverimpl.defaultimpl.DispatcherServlet.doGet(DispatcherServlet.java:48)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.runServlet(HttpHandlerImpl.java:390)

at com.sap.engine.services.servlets_jsp.server.HttpHandlerImpl.handleRequest(HttpHandlerImpl.java:264)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:347)

at com.sap.engine.services.httpserver.server.RequestAnalizer.startServlet(RequestAnalizer.java:325)

at com.sap.engine.services.httpserver.server.RequestAnalizer.invokeWebContainer(RequestAnalizer.java:887)

at com.sap.engine.services.httpserver.server.RequestAnalizer.handle(RequestAnalizer.java:241)

at com.sap.engine.services.httpserver.server.Client.handle(Client.java:92)

at com.sap.engine.services.httpserver.server.Processor.request(Processor.java:148)

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java:33)

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java:41)

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)

at java.security.AccessController.doPrivileged(Native Method)

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:100)

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:170)

Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

at java.lang.reflect.Constructor.newInstance(Constructor.java:274)

at com.sap.tc.webdynpro.progmodel.generation.ControllerHelper.createDelegate(ControllerHelper.java:74)

... 26 more

Caused by: java.lang.NoClassDefFoundError: com.sap.carrefour.CarrCommandBean

at com.sap.test.wdp.InternalTest.<init>(InternalTest.java:46)

... 31 more

Did I miss something or ...? A .jar and .ear file have been created from the EJB and deployed succesfully.

Kind regards

Allan

Edited by: Allan Duinslaeger on Jun 16, 2008 2:43 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Try to rebuild entire project and see, if this resolves your issue.

Hope you have specified Runtime dependency to this dc's

I guess at design time you are able to resolve the classes.

Regards

Ayyapparaj

Former Member
0 Kudos

Thanks for the suggestion, I'll try to rebuild the project.

Another error I also got was the NoClassDefFoundError; would this also be solved by rebuilding?

I don't understand what you mean with this, could you elaborate:

"Hope you have specified Runtime dependency to this dc's" => by the way, I didn't use any DC

"I guess at design time you are able to resolve the classes."

By the way, was it +/- the right way to do EJB's & models? Do you think it should work when this error is solved?

Kind regards

Allan

Edited by: Allan Duinslaeger on Jun 17, 2008 8:55 AM

Former Member
0 Kudos

Hi,

Are you added the EJB at Web Dynpro project references?

properties->webdynpro->refrences->sharing regerences

<vendor>/<EARProject>

Regards

Answers (0)