cancel
Showing results for 
Search instead for 
Did you mean: 

Displaying message after comparing two BigDecimal Values

former_member187658
Participant
0 Kudos

Hi

I have an application, in which 2 BigDecimal values are compared , and if they don't match, an error is to be displayed.

I am able to compare the values. But the message is not shown even when the condition is not met.

Code is as follows:

BigDecimal actualLiftingsTotal=wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().getLi_Con_NomElementAt(size-1).getAct_Lift();

BigDecimal contractVolumeTotal=wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().getLi_Con_NomElementAt(size-1).getCon_Vol();

BigDecimal Actual_Proposed_Total=actualLiftingsTotal.add(bdProp_Nom_Value);

try

{

if(Actual_Proposed_Total==contractVolumeTotal)

{

int flag2=1;

}

else

{

IWDMessageManager msgMgr = this.wdThis.wdGetAPI().getComponent().getMessageManager();

IWDAttributeInfo attributeInfo=this.wdContext.getNodeInfo().getChild("ContractsVolumeResultViewNode").getChild("Output").getChild("Li_Con_Nom_output").getAttribute("Prop_Nom");

msgMgr.reportContextAttributeMessage(this.wdContext.currentContractVolumeResultViewNodeElement(),attributeInfo,IMessageContractVolumesComp.CHECK__PROPOSEDNOMINATION,new Object[] {Actual_Proposed_Total},true);

}

}catch(NullPointerException ex)

{

ex.printStackTrace();

}

This is being done on the Save Action Button.

Can anybody please help.

Thanks & regards,

Anupreet

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi Anupreet,

Your code looks fine, don't know why you are not getting the message displayed. Anyway please try out this suggestion and see if it makes any differenece:

Please edit your message in the message pool such that it doesn't require any objects. (Use some plain error text initially). Then modify your else block like:

else

{

wdComponentAPI.getMessageManager().reportSuccess("Inside else block");

IWDAttributeInfo info = wdContext.getNodeInfo().getAttribute(IPrivate<your_View_name>.ILi_Con_Nom_outputElement.PROP_NOM);

IWDMessageManager messageMgr = this.wdComponentAPI.getMessageManager();

messageMgr.reportContextAttributeMessage(this.wdContext.currentLi_Con_Nom_outputElement(),info,IMessageContractVolumesComp.CHECK__PROPOSEDNOMINATION,null,true);

}

And inside your catch block do make sure to print the exception through wdComponentAPI.getMessageManager().reportWarning("ERROR"+e.toString());

Hope this helps,

Best Regards,

Nibu.

Former Member
0 Kudos

Hi Anupreet,

I suggest you to try to run a sample code by creating a new DC.

I think there is no need of try-catch block.

test this code..

public void onActionTest(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionTest(ServerEvent)

//String help = wdThis.wdGetContext().currentContextElement().getHelp();

//this.checkMandatory(help);

//wdThis.wdGetAPI().getComponent().getMessageManager().raisePendingException();

BigDecimal no1 = wdContext.currentContextElement().getNo1();

wdComponentAPI.getMessageManager().reportSuccess("No-1 = "+no1);

BigDecimal no2 = wdContext.currentContextElement().getNo2();

wdComponentAPI.getMessageManager().reportSuccess("No-2 = "+no2);

BigDecimal no3 = no1.add(no2);

wdComponentAPI.getMessageManager().reportSuccess("No-3 = "+no3);

checkDecimal(no1,no2,no3);

//wdThis.wdGetAPI().getComponent().getMessageManager().raisePendingException();

//@@end

}

public void checkDecimal( java.math.BigDecimal no3, java.math.BigDecimal no1, java.math.BigDecimal no2 )

{

//@@begin checkDecimal()

IWDMessageManager msgMgr = this.wdThis.wdGetAPI().getComponent().getMessageManager();

IWDAttributeInfo attributeInfo=this.wdContext.getNodeInfo().getAttribute("No3");

if(no3.toBigInteger().equals(new BigDecimal(no1.add(no2).toBigInteger())))

{

wdComponentAPI.getMessageManager().reportSuccess("Successful No-3 = "+no3);

}

else

{

msgMgr.reportContextAttributeMessage(this.wdContext.currentContextElement(),attributeInfo,IMessageErrorTest.DECIMAL_TEST,new Object[] {"Not Equal"},true);

}

//@@end

}

Message key - DecimalTest

Messagetype :Error

messagetext : something...here..

try to execute this sample project successfully ...then you 'll come to know what mistake you have done.

I think spend some time in creating this sample pro. and test it.

Regards,

Karthick

Former Member
0 Kudos

Hi,

Make your context elements as no1 ,no2 and no3

and make the type as decimal.

regards,

karthick

former_member187658
Participant
0 Kudos

Hi Nibu

I tried your suggestion. It goes in the else block and prints the Statement.

But after that it catches the exception n prints the NullPointerException. Though i have caught this exception only in the catch block.

Thanks & regards,

Anupreet

Former Member
0 Kudos

Hi Anupreet,

If you are getting a Null pointer exception, you can very well identify the line of code that throws this exception. In your stack trace, try to pick up the line that ends with 'at <yourviewname>.java'. See the corresponding line number in your view.

Best Regards,

Nibu.

Former Member
0 Kudos

Hi Anupreet,

Send the stack trace.We'll find whats that exception?

Regards,

Karthick

former_member187658
Participant
0 Kudos

Hi Karthick

The stacktrace is as follows:

java.lang.NullPointerException

at com.sap.bp.ngl.contvol.ContractVolumeResultView.onActionSave(ContractVolumeResultView.java:346)

at com.sap.bp.ngl.contvol.wdp.InternalContractVolumeResultView.wdInvokeEventHandler(InternalContractVolumeResultView.java:202)

at com.sap.tc.webdynpro.progmodel.generation.DelegatingView.invokeEventHandler(DelegatingView.java:87)

at com.sap.tc.webdynpro.progmodel.controller.Action.fire(Action.java:67)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleAction(WebDynproMainTask.java:100)

at com.sap.tc.webdynpro.clientserver.task.WebDynproMainTask.handleActionEvent(WebDynproMainTask.java:299)

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

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

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

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.doPost(DispatcherServlet.java:55)

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

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

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

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

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

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

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

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

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

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

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

at com.sap.engine.core.cluster.impl6.session.UnorderedChannel$MessageRunner.run(UnorderedChannel.java:71)

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:94)

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

Thanks & regards,

Anupreet

former_member187658
Participant
0 Kudos

Hi

I just checked, the exception is being thrown in the statement gathering attributeInfo.

Can you please help in this.

Thanks & regards,

Anupreet

Former Member
0 Kudos

Hi Anupreet,

See the line no: 346 of your view.

(ContractVolumeResultView.java:346).

If you paste that line of code here, we might be able to help you.

Best Regards,

Nibu.

former_member187658
Participant
0 Kudos

Hi Nibu

The line number 346 is :

IWDAttributeInfo attributeInfo=this.wdContext.getNodeInfo().getChild("ContractsVolumeResultViewNode").getChild("Output").getChild("Li_Con_Nom_output").getAttribute("Prop_Nom");

Thanks & regards,

Anupreet

Former Member
0 Kudos

Hi Anupreet,

Try replacing that line with something similar to this :

IWDAttributeInfo attributeInfo = wdContext.getNodeInfo().getAttribute(IPrivate<your_View_name>.ILi_Con_Nom_outputElement.PROP_NOM);

Best regards,

Nibu.

former_member187658
Participant
0 Kudos

Hi Nibu

I tried the thing suggested by you. But on counter checking the values, attributeInfo doesn't have any value. It is having value as "null".

And hence it gives the NullPointer Exception.

Thanks & regards,

Anupreet

Former Member
0 Kudos

Hi Anupreet,

Try this.

IWDAttributeInfo attributeInfo = this.wdContext.getNodeInfo().getChild("ContractsVolumeResultViewNode").getChild("Output").getChild("Li_Con_Nom_output").getAttribute(IPrivateContractsVolumeResultView.ILi_Con_Nom_outputElement.PROP_NOM);

And make sure that your context name and PROP_NOM should be same.

Regards,

Karthick

Former Member
0 Kudos

Hi Anupreet,

Just trying to help you debug your application ...!

Before your comparison statement, just print the values of both the variables and make sure that they are populated properly

wdComponentAPI.getMessageManager().reportSuccess("Actual_Proposed_Total = "+Actual_Proposed_Total);

wdComponentAPI.getMessageManager().reportSuccess("contractVolumeTotal = "+contractVolumeTotal);

Then inside your if & else blocks try printing some text to make sure that the control reaches the desired block.

Hope this helps,

Best Regards,

Nibu.

former_member187658
Participant
0 Kudos

Hi

I have done exactly the way you mentioned karthick, and also tried the way bhavik had said.

Even during the debugging, i checked it, the right data is coming in the variables, it is being compared and on condition becoming false, control does reach the desired block. But the error message is not being displayed.

Can you please help in this, as i am clueless, where exactly the problem is arising.

Thanks & regards,

anupreet

Former Member
0 Kudos

Hi Anupreet,

Have you made the message type as Error?

Regards,

Karthick

former_member187658
Participant
0 Kudos

Hi Karthick

Yes, message type is Error only.

Thanks & regards,

Anupreet

Former Member
0 Kudos

Hi Anupreet,

Have you made the attributes which is representing the Bigdecimals as decimals?

1.means in the context select the attribute which is representing the big decimal and in the property -type make it as decimal.

now try.

2. And check whether yo have given message text or not,bcaz message text will be displayed in the browser instead of message key.check it out.

3.If you are getting any exception just lemme know.then easily we can debug it.

Regards,

Karthick

former_member187658
Participant
0 Kudos

Hi Karthick

The context attribute is of type Decimal itself.

I have also provided with the message text.

It was giving NullPointerException when i hadn't written the code in the try-catch. but after putting try-catch, no exception is being thrown.

Thanks & regards,

Anupreet

Former Member
0 Kudos

Hi Anupreet,

Write following line of code when both values are not same.

wdcomponentAPI.getMessegemanager().reportWarning("<Your messege>");

No need to write all other things.

Regards,

Bhavik

Former Member
0 Kudos

Hi Anupreet,

See this example code.

OnAction method.

public void onActionToResultView(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )

{

//@@begin onActionToResultView(ServerEvent)

String name = wdThis.wdGetStartViewController().wdGetContext().currentContextElement().getC_name();

this.checkMandatory(name);

wdThis.wdGetAPI().getComponent().getMessageManager().raisePendingException();

wdThis.wdFirePlugToResultView();

//@@end

}

Dont forget to follow these steps.

In the message pool

Write your message key like in my case -- MISSING_INPUT

Message Type - Error

Give some message text.

I think It should help you.

Regards,

Karthick

My Check Mandatory method

public void checkMandatory( java.lang.String name )

{

//@@begin checkMandatory()

IWDMessageManager messageManager = this.wdThis.wdGetAPI().getComponent().getMessageManager();

// Object attributeValue = this.wdContext.currentContextElement().getAttributeValue(name);

IWDAttributeInfo attributeInfo = this.wdContext.getNodeInfo().getAttribute("name");

// if(attributeValue instanceof String){

if (name == null || name.equalsIgnoreCase("")){

messageManager.reportContextAttributeMessage

(this.wdContext.currentContextElement(),

attributeInfo,

IMessageStartView.MISSING_INPUT,

new Object[]{"name"},

true);

}//if

// }//if

//@@end

}

Former Member
0 Kudos

Hi Anupreet,

On Action method

write your code like this as you said.

BigDecimal actualLiftingsTotal=wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().getLi_Con_NomElementAt(size-1).getAct_Lift();

BigDecimal contractVolumeTotal=wdContext.nodeContractVolumeResultViewNode().nodeOutput().nodeLi_Con_Nom().getLi_Con_NomElementAt(size-1).getCon_Vol();

BigDecimal Actual_Proposed_Total=actualLiftingsTotal.add(bdProp_Nom_Value);

then write one more method (like.. checkDecimals() )to test whether the decimal values are matching.

inside that method.

checkDecimals method write your code ..but to that check Decimals method you have to pass the parameters which do you want to match.

try

{

if(Actual_Proposed_Total==contractVolumeTotal)

{

int flag2=1;

}

else

{

IWDMessageManager msgMgr = this.wdThis.wdGetAPI().getComponent().getMessageManager();

IWDAttributeInfo attributeInfo=this.wdContext.getNodeInfo().getChild("ContractsVolumeResultViewNode").getChild("Output").getChild("Li_Con_Nom_output").getAttribute("Prop_Nom");

msgMgr.reportContextAttributeMessage(this.wdContext.currentContractVolumeResultViewNodeElement(),attributeInfo,IMessageContractVolumesComp.CHECK__PROPOSEDNOMINATION,new Object[] {Actual_Proposed_Total},true);

}

}catch(NullPointerException ex)

{

ex.printStackTrace();

}

}

And in the message pool editor you have to create a new message for your error message.

If you are not understanding my idea.just lemme know I'll explain this with sample code.

Dont forget to reward the answers if you are satisfied.

Regards,

Karthick