cancel
Showing results for 
Search instead for 
Did you mean: 

EJB with WD java

Former Member
0 Kudos

Hi All

I have a requirement in which i have to query a database

My Front End is in WD and I am using a java bean model which interacts with stateless session bean fro there connectivity with database happens.

but when in component controller i set the variables of bean model it throws me Null Pointer exception..the value which i am setting when displayed is all right but when i use say

wdContext.nodeMyCommandBean().currentMyCommandBeanElement().setDeptName(dpname);

here MyCommandBean is my java class which i am using as a model and deptName is its one of the variable

It throws a Null Pointer Exception here whereas when i display "dpname " to chk whether it has some data it gives me correct value

Please Help

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Monika,

Always check the variable value not equal to null and then do process.

if(dpname!=null)

wdContext.nodeMyCommandBean().currentMyCommandBeanElement().setDeptName(dpname);

Regards, Suresh KB

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

just check currentMyCommandBeanElement(). is null or not before accessing the

setDeptName(dpname);

Regards

Ayyapparaj

Former Member
0 Kudos

Hi AyyappaRaj and Suresh

Thanks for ur replies

i chekced dpname and its not null

@ Ayyaparaj

i checked currentMyCommandBeanElement(). and its giving me that its null ...how to resolve the problem

Thanks

Former Member
0 Kudos

Hi,

You need to execute this model to get some data.

Else you have to create an instance of this.

Regards

Ayyapparaj

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Monika,

Did you Initialized the controller?

wdContext.nodeMycommandBean().bind(new MyCommandBean())

Check out this link: [Here|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1f5f3366-0401-0010-d6b0-e85a49e93a5c]

Regards, Suresh KB

Former Member
0 Kudos

Hi,

I think the node u have created is not a model node. Only then it might be possible that the node is created but not the element in that node.

Try to create an Element n assign dpname value. And then add it to the Node.

C if this helps.

Regards,

Kunal Kotak

Former Member
0 Kudos

Hi Suresh

Ya i forgot to write this line of code...

But adding this gave me new problem...

My control is going to my bean model but it does not move further

What could be the problem ??

Thanks

suresh_krishnamoorthy
Active Contributor
0 Kudos

Hi Monika,

What is new problem?. can you please elaborate and post the error trace.

Regards, Suresh KB

Former Member
0 Kudos

Hi Suresh

I wrote this line of code in wdInit of Component Controller :

wdContext.nodeMyCommandBean().bind(new MyCommandBean());

Now whats the new problem is that when i deploy and run my application it doestn't display my UI's and when i remove this line of code i am able to see my UI's

I think problem is with Java Bean class :

This is the constructor which i wrote in java class which i am using as a model

public MyCommandBean(){

try{ InitialContext ctx= new InitialContext();

objDepartmentBean = (DepartmentBean)ctx.lookup("jdbc/MySessionBean");

}catch(Exception e){

e.printStackTrace();

}

}

Here DepartmentBean is a Session Bean in a EJB project.

Please suggest some solution

Thanks

former_member751941
Active Contributor
0 Kudos

Hi Monika,

Go through this link.

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1f5f3366-0401-0010-d6b0-e85a49e9...

public class MyCommandBean {

private int multiplier;

private ssn;

String private double bonusAmount;

private String message;

BonusCalculatorLocal theCalculator = null;

BonusCalculatorLocalHome home = null;

public MyCommandBean() throws CreateException {

//looks up the session bean and creates the Home interface

try {

InitialContext ctx = new InitialContext();

home = (BonusCalculatorLocalHome)ctx.lookup("localejbs/MySessionBean");

<b>theCalculator = home.create();</b>

} catch (Exception namingException) {

namingException.printStackTrace();

}

}

}

Regards,

Mithu

Former Member
0 Kudos

Hi Mithu

Thanks for ur reply. When i write wdContext.nodeMyCommandBean().bind(new MyCommandBean()); line of code in my Component controller it does not display my UI's but when i remove this from there thn m able to see my Ui's when application deployed and run....

this time in my bean model i wrote these lines of code:

public MyCommandBean(){

try{ InitialContext ctx= new InitialContext();

home = (DepartmentLocalHome)ctx.lookup("jdbc/MySessionBean");

objDepartmentLocal = home.create();

}catch (Exception namingException) {

namingException.printStackTrace();

}

}

Former Member
0 Kudos

Hi All

My problem has been solved..I just reimported my model and the problem got solved..I think the Wd application was not taking the changes made in the java bean model without reimporting

Thanks

Monika