Hi,
I am new to WebDynpro and am trying to do validation for my 4 fields,that they should not be left empty.
Here as a first step,i have created a key in the message pool with text"Field cannot be empty."
2.Also created a method in the view called checkMandatory of the type boolean and parameter fieldName.
In the view i implemented the following:
public boolean checkMandatory( java.lang.String fieldName )
{IWDMessageManager msgMan = wdComponentAPI.getMessageManager();
String fieldname = "FirstName";
String FirstName = wdContext.nodeEmployee().currentEmployeeElement().getAttributeAsText(fieldname);
IWDAttributeInfo employeeAttr = wdContext.nodeEmployee().getNodeInfo().getAttribute(fieldname);
if(FirstName.length()==0)
{msgMan.reportContextAttributeMessage(wdContext.nodeEmployee().currentEmployeeElement().getAttributePointer(fieldname), IMessageEmployee.MISSING_INPUT, new Object[]{fieldname});
return false;
}
return true;
3.I checked the method in the save method in the view
public void onActionSave(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionSave(ServerEvent)
if(checkMandatory(null))
{ IEmployeeElement E1 = wdContext.nodeEmployee().createAndAddEmployeeElement();
wdContext.nodeEmployee().setLeadSelection(E1.index());
}
Is my approach correct?
How should i go ahead with checking the same for other fields?
Request Help.
Regards,
Suvarna