cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to achieve Error Handling

Former Member
0 Kudos

Hi All,

Within my method call I invoke a error handler method but this does not seem to function. The code is as enclosed below can someone let me know as to why please.

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

{

//@@begin onActionContactPersonalizationPressed(ServerEvent)

this.checkMandatory("ProductCategory");

this.checkMandatory("ProductFamilySel");

this.checkMandatory("ProductSel");

this.checkMandatory("ContractManager");

this.checkMandatory("ContractStartDate");

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

wdThis.wdFirePlugExitCustPOCtoCP();

//@@end

}

// Error handler method

public void checkMandatory( java.lang.String fieldName )

{

//@@begin checkMandatory()

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

Object attVal = this.wdContext.currentContextElement().getAttributeValue(fieldName);

IWDAttributeInfo attInfo = this.wdContext.getNodeInfo().getAttribute(fieldName);

if(attVal instanceof String){

if(((String)attVal).length() == 0){

msgMgr.reportContextAttributeMessage(

this.wdContext.currentContextElement(),

attInfo,

IMessageHPBBankingProductOffering.MISSING_INPUT,

new Object[] {fieldName},

true);

}

}

//@@end

}

Thanks in advance.

Best regards,

Divya

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Divya,

instead of


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

use


if ( !wdThis.wdGetAPI().getComponent().getMessageManager().<b>hasExceptions()</b> )
{
  wdThis.wdFirePlugExitCustPOCtoCP();
}

Maksim had explained "why"

Btw, instead of wdThis.wdGetAPI().getComponent() you may just use wdComponentAPI controller variable.

VS

former_member182372
Active Contributor
0 Kudos

Valery, doesn`t

cancelNavigation = true

prevent any plugs navigation?

Former Member
0 Kudos

Maksim,

Yes, it prevents navigation. It stops <b>global</b> navigation. So if you have quite complex application composed from several components, any component may break navigation of complete application.

So it is better to set this parameter to false and verifies message manager for exceptions, thus, skipping navigation only locally and let the rest of the system decides on its own.

VS

Former Member
0 Kudos

Hi All,

I have now changed it to the code enclosed below:

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

{

//@@begin onActionContactPersonalizationPressed(ServerEvent)

this.checkMandatory("ProductCategory");

this.checkMandatory("ProductFamilySel");

this.checkMandatory("ProductSel");

this.checkMandatory("ContractManager");

this.checkMandatory("ContractStartDate");

String selPdDesc = (String)wdContext.currentContextElement().getAttributeValue("ProductSel");

wdContext.currentContextElement().setProductSelDesc(selPdDesc);

if( !wdThis.wdGetAPI().getComponent().getMessageManager().hasExceptions() ){

wdThis.wdFirePlugExitCustPOCtoCP();

}

//@@end

}

public void checkMandatory( java.lang.String fieldName )

{

//@@begin checkMandatory()

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

Object attVal = this.wdContext.currentContextElement().getAttributeValue(fieldName);

IWDAttributeInfo attInfo = this.wdContext.getNodeInfo().getAttribute(fieldName);

if(attVal instanceof String){

if(((String)attVal).length() == 0){

msgMgr.reportContextAttributeMessage(

this.wdContext.currentContextElement(),

attInfo,

IMessageHPBBankingProductOffering.MISSING_INPUT,

new Object[] {fieldName},

false);

}

}

//@@end

}

Still doesn seem to work.

Can someone state as to why?

Thanks in advance

Best regards,

Divya

former_member182372
Active Contributor
0 Kudos

Hello Divya,

Could you tell us, what exactly is not working? And what are you expecting from code?

Best regards, Maksim Rashchynski

Former Member
0 Kudos

Hi Maksim,

I need to display an error messsage when a mandatory field is left blank.

I have all these values stored in respective context variables and I call the this.checkMandatory(""); method with these context variable methods.

I am not sure how to raise it within this method and restrict to this screen until all mandatory screen fields are filled.

Thanks again.

Best regards,

Divya

Former Member
0 Kudos

Hi Divya

check the below line.

if(((String)attVal).length() == 0)

Make sure what the method length() returns when the string is null.

It might be -1 and not 0.

Regards,

saravana.

Former Member
0 Kudos

Divya

Check this:

msgMgr.reportContextAttributeMessage

(

...

IMessageHPBBankingProductOffering.MISSING_INPUT

...

)

Does MISSING_INPUT error message declared in message pool as "error"? or it is left "standard" (default setting)?

VS

Former Member
0 Kudos

How can I define where my messages appear when I use the follwing code to display 'em?

msgMgr.raiseMessage(IMessageMyProject.MISSING_INPUT,
			new Object[] {fieldName},
			false);	

former_member182372
Active Contributor
0 Kudos

Hello Divya,

Why are you calling raisePendingException. From https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/javadocs/nw04/sp12... dynpro runtime environment/com/sap/tc/webdynpro/progmodel/api/iwdmessagemanager.html

<i>This method checks if any exceptions were reported to the exception manager and are still stored in the exceptions manager. In case there is at least one exception still stored, this method does not return, but . raises some framework internal exception instead in order to return to the framework error handler.

</i>

So, if you don`t need to chech whether you have exceptions, than you don`tneed to call this method. And to prevent navigation you already passing true as cancelNavigation in method reportContextAttributeMessage.

Best regards, Maksim Rashchynski