on 09-07-2007 4:18 PM
Hi All,
I am trying to to read from UI elements on my screen . When I try the following code, it errors out with java.lang.NullPointerException exception. It appears, I am reading a value that has not been set. I am doing this in my OnActionSave method.
wdContext.nodeDetails_Out().currentDetails_OutElement().getEmpNo()
tableInput.setEmpNo(wdContext.nodeDetails_Out().currentDetails_OutElement().getEmpNo());
Details_Out (output node) elements is what bounded to my text field. I also have Details_Input table in my context.
Any help is appreciated.
Another info. I directly mapped my model node to view elements. Do I need to create value nodes and copy the values from model node to view node and map them UI elements.
What is the best practice.
If I need to create value nodes, how do I create through code. I have 50 fields, I think it is going to be very cumbersome to create all value nodes manually.
Thanks
Raghu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Rahu,
If you have 50 feilds to be mapped to UI elements its always better to map the model fields. Can you tell us your BAPI model structure and which fields you are mapping to UI?
And also try this, you should initialize the BAPI Input object in wdInit() so that your UI fields will be binded to the BAPI and copied while executing the BAPI.
Write this sample code in wdInit()
ZBAPI<>_Input inputObject = new ZBAPI<>_Input inputObject();
wdContext.nodeZBAPI<>_Input ().bind(inputObject );
If you have any table parameters then you should initialize the values and bind it to inputObject.
Regards
Abhilash
Abhilash,
That is exactly what I am doing in WdInit
Z_Opts_Masterdata_Details_Input input = new Z_Opts_Masterdata_Details_Input();
wdContext.nodeZ_Opts_Masterdata_Details_Input().bind(input);
input.setEmpNum("A0001");
input.setFlag("Q");
try
{
wdContext.currentZ_Opts_Masterdata_Details_InputElement().modelObject().execute();
wdContext.nodeOpts_Output().invalidate();
wdContext.nodeOutput().invalidate();
}
catch(WDDynamicRFCExecuteException e)
{
// report exception using message manager
}
The data is pulled into the screen. But I cannot read the text value, when I want to update or insert.
The size of my nodeDetails_Out is zero.
I am sorry, looks like I repeating the same thing again. I am missing something
Thanks
Raghu
Raghu,
Create two value attributes empnum and flag and map this fields to UI value property.
Then change the code this way:
Z_Opts_Masterdata_Details_Input input = new Z_Opts_Masterdata_Details_Input();
wdContext.nodeZ_Opts_Masterdata_Details_Input().bind(input);
input.setEmpNum(wdContext.currentContextElement().getEmpNum());
input.setFlag(wdContext.currentContextElement().getFlag());
I did not understand what you mean by:
<i>The data is pulled into the screen. But I cannot read the text value, when I want to update or insert.</i>
Regards
Abhilash
Abhilash,
Thanks very much for your help.
I figured what I was doing wrong.
in my save I was initializing using the bind object before reading my values. That is why It was giving null exception.
I had to read my values before into bofore I initialized to insert.
Its working again. I really appreciate your fast response.
Thanks
Raghu
Thanks every one for your help. I know where the problem is but I dont what the fix is.
The size of my nodeDetails_Out Element is 0. That is why I am getting a null exception.
<b>Why is my nodeDetails_OutElement size is zero.</b>
Here is what I am trying to do.
I have a data entry screen. I want to be able to enter /change /pull data.
I am able to pull data into my fields (bound to my nodeDetail_Out elements)
I am trying to enter some values and write to table in SAP. I am able to Insert using hard coded values.
Instead of hard coded values, I want to read from my text fields to insert.
Questions.
1. How do I initialize in Web Dynpro to be able to read from the text fields
2. I am inputting only one record at a time, so I am assuming I dont have to loop through the node to execute the insert.
When I do an find on a specific record and execute, I was able to pull the record, but when I modify and try to read the same record, it still gives null exception.
Can someone please give the steps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think the best thing would pe to post your code here so that we can take a look and let you know whats wrong
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Raghu,
It seems that you output node is not populated try printing the size of your output node after the execution of BAPI.
wdComponentAPI.getMessageManger().reportException(wdContext.nodeDetails_Out().size(),true);
If this size if 0 that means that your node is not filled and thus you are getting null pointer exception.
Regards,
Murtuza
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Firasath,
Yes, I am initializing the output element.
The steps I took,
I did a search based on EmployeeID, which populated the form based on the results from BAPI. I modified the value and I am trying to save the value to the table. I am trying to read the employee id and other fields on the form.
Do I have to explicitly initialize each field. I have about 50 fields (distributed on different tabs) on my form.
Thanks
Raghu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jennifer,
I tried without nodDetails_Out as you suggested
tableInput.setEmpNo(wdContext.currentDetails_OutElement().getEmpNo());
I still get the null exception.
I am mapping to context model node. Model Node has Output node which has the Detail_Out node which has my column mappings.
This must be pretty common thing to do, I am not sure what I am missing.
Thanks
Hi Rahgunath,
When you are calling this method? Is it after executing the BAPI? The out node is only initialized after BAPI execution. The initialization of the node is done by BAPI after BAPI execution. And also Details_Out node contains mulitple elements. If you are doing the code in loop you should do this way:
for(int index=0;index<nodDetails_Out().size();index++)
{
wdContext.nodDetails_Out().setLeadSelection(index);
//create tableInput element
tableInput.setEmpNo(wdContext.currentDetails_OutElement().getEmpNo());
}
Regards
Abhilash
Hi Ragha,
When you are getting null value for employee number set it to 0.It will not give null pointer exception.
Check this code.
int size = wdContext.nodeDetails_Out().size();
for(int i=0;i<size;i++)
{
String empno = wdContext.nodeDetails_Out().getDetails_OutElementAt(i).getEmpNo();
if(empno == null || empno.equals() )
{
empno = 0;
}
tableInput.setEmpNo(empno);
}
Regards,
Mithu
Null pointer exception tells me that you are trying to access output element which is not been initialized yet. Do you enter the value for this input field before calling the code
tableInput.setEmpNo(wdContext.nodeDetails_Out().currentDetails_OutElement().getEmpNo());
?
It will be good to describe your process flow in detail
Regards
Firasath
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.