cancel
Showing results for 
Search instead for 
Did you mean: 

How to override standard error message in Value help?? - URGENT

former_member1191927
Participant
0 Kudos

Hi all,

I have provided a value help to one of my fields in my web dynpro screen. Now when ever user enters a invalid value, it gives a message "String <> not in enumeratrion".

I want to change this to a user friendly message.

Here's the code that i have used:-

ISimpleTypeModifiable modifiable_cust = wdContext.getNodeInfo().getAttribute(IPrivateBAcodeCreateView.IContextElement.CTX__VH__CUST).getModifiableSimpleType();

modifiable_cust.setFieldLabel("Customer");

IModifiableSimpleValueSet valueset_cust = modifiable_cust.getSVServices().getModifiableSimpleValueSet();

int size_cust =wdContext.nodeLi_Kunnr().size();

String custCode =null;

String custDesc=null;

for (int i=0;i<size_cust;i++)

{

custCode = wdContext.nodeLi_Kunnr().getLi_KunnrElementAt(i).getKunnr();

custDesc=wdContext.nodeLi_Kunnr().getLi_KunnrElementAt(i).getDescription();

valueset_cust.put(custCode,custDesc);

}

Any info on this will be really greatful.

Please reply ASAP. It is urgent.

Regards,

Narahari

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Narahari,

You cannot do this with standard value help (EVS).

Any your custom code is invoked only after WD validates entered value itself (and produces error message), and you have no "hooks" to participate in this process.

Similar issue arised here:

I ended up with OVS replacement for EVS, see https://weblogs.sdn.sap.com/pub/wlg/3309. [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken]

This technique can be used for overriding error message as well (code of OVS4EVS.EvsHelper.applyValue should be altered).

WARNING: code is quite complex and referencing a lot of materials that reader should be familiar with.

Valery Silaev

EPAM Systems

http://www.NetWeaverTeam.com

Former Member
0 Kudos

hi Narahari,

I tried out with different scenario for getting error msg.Here im sending soem code .where we have to declare the error msgs in the messaging area.

Pls look into this code this may give u some idea.

my scenario is

name field

birthady date field

emailaddress field

Save button

clear button

and submit button.

when name field is empty and when user tries to click on save it gives error msg "pls enter the name fied" which is mandatory.

if bday date is greater than todays date it shuld give error msg "pls enter the date which shuld be less than todays date"......

for this i had created tree methods

//@@begin imports

import java.sql.Date;

import com.sap.tc.webdynpro.progmodel.api.IWDMessageManager;

import com.sap.tc.webdynpro.tutorial.errorbehavior.wdp.IMessageSimpleErrors;

import com.sap.tc.webdynpro.tutorial.errorbehavior.wdp.IPrivateForm;

//@@end

...

/** declared method */

public void checkDesired(java.lang.String fieldName) {

//@@begin checkDesired()

IWDMessageManager messageMgr =

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

Object attributeValue =

this.wdContext.currentContextElement().getAttributeValue(fieldName);

IWDAttributeInfo attributeInfo =

this.wdContext.getNodeInfo().getAttribute(fieldName);

if (attributeValue instanceof String) {

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

if (fieldName.equals("EMailAddress"))

messageMgr.reportContextAttributeMessage(

this.wdContext.currentContextElement(),

attributeInfo,

IMessageSimpleErrors.DESIRED_E_MAIL,

null,

true);

}

}

//@@end

}

/** declared method */

public void checkMandatory(java.lang.String fieldName) {

//@@begin checkMandatory()

IWDMessageManager messageMgr =

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

Object attributeValue =

this.wdContext.currentContextElement().getAttributeValue(fieldName);

IWDAttributeInfo attributeInfo =

this.wdContext.getNodeInfo().getAttribute(fieldName);

if (attributeValue instanceof String) {

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

String fieldLabel =

this.wdContext.getNodeInfo().getAttribute(fieldName)

.getSimpleType().getFieldLabel();

messageMgr.reportContextAttributeMessage(

this.wdContext.currentContextElement(),

attributeInfo,

IMessageSimpleErrors.MISSING_INPUT,

new Object[] { fieldLabel },

true);

}

}

//@@end

}

/** declared method */

public void checkDateInPast(java.lang.String fieldName) {

//@@begin checkDateInPast()

IWDMessageManager msgMgr =

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

Date theDate = (Date)

this.wdContext.currentContextElement().getAttributeValue(fieldName);

IWDAttributeInfo attributeInfo =

this.wdContext.getNodeInfo().getAttribute(fieldName);

if (theDate.after(new Date(System.currentTimeMillis()))) {

String fieldLabel =

this.wdContext.getNodeInfo().getAttribute(fieldName)

.getSimpleType().getFieldLabel();

msgMgr.reportContextAttributeMessage(

this.wdContext.currentContextElement(),

attributeInfo,

IMessageSimpleErrors.DATE_IS_IN_FUTURE,

new Object[] { fieldLabel, theDate },

and for intilization.....

public void wdDoInit() {

//@@begin wdDoInit()

this.initialize();

//@@end

}

...

/** declared method */

public void initialize() {

//@@begin initialize()

wdContext.currentContextElement().setName("");

wdContext.currentContextElement().setBirthday(new Date(0));

wdContext.currentContextElement().setEMailAddress("");

wdContext.getNodeInfo().getAttribute("EMailAddress")

.getModifiableSimpleType().setFieldLabel("E-Mail Address");

//@@end

}

...

The methods checkDateInPast(), checkDesired(), and checkMandatory() are

called by the event handler of the onActionSave() action. They contain the actual input

checks.

The error message is stored internally by a source code line of the following type:

messageMgr.reportContextAttributeMessage(

this.wdContext.currentContextElement(),

attributeInfo,

IMessageSimpleErrors.<MessageKey>,

Object[] arguments,

true);

in save button code will be.....

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

{

//@@begin onActionSave(ServerEvent)

this.checkMandatory("Name");

this.checkDateInPast("Birthday");

this.checkDesired("EMailAddress");

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

wdThis.wdGetAPI().getComponent().getMessageManager().reportSuccess(

"The sample form data was successfully saved!");

//@@end

}

...

on click on submit

public void onActionSendEMail(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent

wdEvent )

{

//@@begin onActionSendEMail(ServerEvent)

this.checkMandatory("EMailAddress");

wdThis.wdFirePlugSendEMailOut(wdContext.currentContextElement().getEMailAddress());

//@@end

}

...

on click on clear...

public void onActionClear(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent

wdEvent )

{

//@@begin onActionClear(ServerEvent)

// Initialize context of this view again

this.initialize();

//@@end

}

...

Hope that this code will solve ur problem...

PLs reward the points .If ur satisfied pls close the forum...

regards,

Krishnam Raju.