cancel
Showing results for 
Search instead for 
Did you mean: 

Null poiner exception when trying to store extension data in existing BO

Former Member
0 Kudos

Hi All,

When I am trying to store extension data to existing 'basket' business object using the code below, I am getting a null pointer exception.

public ActionForward doPerform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

try {

UserSessionData userSessionData = UserSessionData.getUserSessionData(request.getSession());

BusinessObjectManager isaBOM = (BusinessObjectManager)userSessionData.getBOM(BusinessObjectManager.ISACORE_BOM);

Basket basket = isaBOM.getBasket();

//String quantity1 = request.getParameter("quantityofweek");

String quantity1 = "1";

basket.addExtensionData("ZEXTENSION",quantity1);

//String test = (String) basket.getExtensionData("ZEXTENSION");

//if (test != null)

request.setAttribute("Z_quantity",quantity1);

}

catch (Exception e){

request.setAttribute ("Z_quantity",e);

}

return mapping.findForward("success");

}

I just followed the 'Examples in E-Commerce' document to do this . I face null pointer exception at the line

basket.addExtensionData("ZEXTENSION",quantity1);

I guess it is not able to retrieve instance of basket and so null is stored in basket object and getting null pointer exception by calling 'addextensiondata' method.

Is there anything that i need to add to the code so that I will be store additional data in existing business object?

Any pointers will be of great help.

Thanks,

Anasuya.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Your selection is right. But, problem is where you are using this action is it after AddToBasket Action or before that. Because from product catalog to Basket there are series of actions involved.

You need to check for the right place to add. You will get the basket only after the basket is created.

And try to add extension data to header of the order not to the basket.

Regards,

Sateesh Chandra

Former Member
0 Kudos

Hi Sateesh,

Thanks for ur valuable reply.

I used the action in middle of 'quicksearchaddtobasketaction' and addtobasketaction' i.e, before the 'addtobasketaction' class.

So from ur reply I understood that basket is created in 'addtobasketaction' class and i need to add my custom class after addtobasketaction.

Can you give more detailed explanation on this

" And try to add extension data to header of the order not to the basket. "

And also a special thanks to you as I have started my E-Commerce with your document "How to create custom application in E-Commerce 5.0 without NWDI."

And also can you tell me how to identify exact business object that suits our requirement.

Thanks,

Anasuya.

Answers (1)

Answers (1)

Ash_ok
Contributor
0 Kudos

Hi Anasuya,

You could try and parse the Basket object to a String variable and then getting the variable to be output onto a .jsp to see if the object is in fact getting populated. Also, you could run the whole transaction with session trace settings switched on and see the actions and the values being parsed from the log files.

Hope this helps.

Ashok.

Former Member
0 Kudos

Hi Ashok,

Thanks for your reply.

I checked and could confirm that 'basket' object is null.

can you give me any inputs regarding how to get the basket instance populatd into the method?

Thanks,

Anasuya

Ash_ok
Contributor
0 Kudos

Hi Anasuya,

Sorry for being so blunt ....... but, have you put any items onto your basket before triggering the action ?

Also, can you output the value of the BOM onto a string to see if that is getting populated ?

Cheers,

Ashok.

Former Member
0 Kudos

Hi Ashok,

Thanks for your reply.

Let me explain my requirement.

when a user searches for a product in B2B webshop in 'products' tab in left frame, search results table include 4 fields ( product number,description,price and shopping basket icon).when he selects a particular line item, that goes to shopping basket with id and description.

Now my requirement is to add an extra column in product catalog that holds quantity and should be passed to shopping basket along with id and description.

I was told that I have to use 'basket' business object to store this extension data . Am I right in this or misleaded? By seeing your reply, I got a doubt that my selection of business object may be wrong because I did not even select a product into the shopping basket.If so can you tell me the correct business object? How to identify a exact business object that suits the requirement?

Thanks,

Anasuya.

Ash_ok
Contributor
0 Kudos

Hi Anasuya,

I am speculating, based on your actions, that the business object triggered would be the catalog. You could verify that by looking into the log files.

Cheers,

Ashok.

Former Member
0 Kudos

Hello,

You said

Now my requirement is to add an extra column in product catalog that holds quantity and should be passed to shopping basket along with id and description.

I am confused. Is it not true that the catalog page already has a Quantity column? Sorry if I am misreading the requirement.

Easwar Ram

http://www.parxlns.com

Former Member
0 Kudos

Hi Easwar Ram,

Thanks for ur reply. We have a quantity column in 'shopping basket' but not in the 'product catalog'...i.e, in the results table we get when we search for a product.

Thanks,

Anasuya.

Former Member
0 Kudos

Hello Anasuya,

My bad. I should have read the thread entirely.

Questions:

  1. Are you using late order determination? (Option 'Document Type Can Be Chosen Late' in Shop Admin XCM)

  2. Is it true that you are trying this scenario, before you clicked the "Create new shopping basket" etc. in the Welcome page?

If your reply is "yes", then, the basket object will not be existing at that point. You have to include createbasket in your flow somehow. But only once! Also, this action might require order.jsp as input form. This solution is cumbersome.

Instead you can fool the ISA, by tweaking the BasketTransferItem put by the QuickSearchAddToBasketAction. This BasketTransferItem is available in the request context - attribute baskettransferitem. So, in your custom action do this. No need for extension data...


import com.sapmarkets.isa.businessobject.item.BasketTransferItemImpl;
BasketTransferItemImpl transferItem = new BasketTransferItemImpl();
transferItem.setQuantity(quantity1); //quantity is given as string.
request.setAttribute("baskettransferitem", transferItem);

Easwar Ram

http://www.parxlns.com

Former Member
0 Kudos

Hi Easwar Ram,

Thanks for ur valuable reply which helped a lot.