cancel
Showing results for 
Search instead for 
Did you mean: 

Validate Input Fields in View

Former Member
0 Kudos

Hi,

I have a node, called NODEA, under that i have 5 attributes, in my View Context which are mapped to Custom Controller. I created an action "SAVE" in View Controller. Now when i press SAVE button, i need to check all attributes whether it is empty or not. If they are empty i need to report an error to the user.

Could you please tell me how did you validated the model node attributes.

Thanks

Vijay

Accepted Solutions (0)

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi Lakshmi, see my sample code...

// method for checking mandatory

public void CheckMandatory( java.lang.String EmpId, java.lang.String Emp_ID, java.lang.String displayValue )

{

//@@begin CheckMandatory()

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

IWDAttributeInfo attributeInfo = this.wdContext.getNodeInfo().getAttribute(Emp_ID);

if(EmpId==null || EmpId.equalsIgnoreCase(""))

{

msgMgr.reportContextAttributeMessage(this.wdContext.currentContextElement(),attributeInfo,IMessageLoginComponent.MISSINGI_NPUT,new Object[] {displayValue},true);

}

else

{

try

{

int age = Integer.parseInt(EmpId);

if(Emp_ID.equalsIgnoreCase("Age"))

{

if(age > 100)

{

msgMgr.reportContextAttributeMessage(this.wdContext.currentContextElement(),attributeInfo,IMessageLoginComponent.AGE_GT100,new Object[] {displayValue},true);

}

}

}

catch(NumberFormatException NFE)

{

msgMgr.reportContextAttributeMessage(this.wdContext.currentContextElement(),attributeInfo,IMessageLoginComponent.DATE_IS_IN_PAST,new Object[] {displayValue},true);

}

}

//@@end

}

//Method for checking not null

public void CheckSexNotNull( com.sap.emp.info.Sex value, java.lang.String label )

{

//@@begin CheckSexNotNull()

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

IWDAttributeInfo attributeInfo = this.wdContext.getNodeInfo().getAttribute(label);

if(value==null)

{

msgMgr.reportContextAttributeMessage(this.wdContext.currentContextElement(),attributeInfo,IMessageLoginComponent.EMPID__MISSING,new Object[] {label},true);

}

//@@end

}

//On Action call these methods.

CheckMandatory(empId,"EmpId","Employee ID");

CheckSexNotNull(sex,"Sex");

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

wdThis.wdFirePlugGoToEmpDetails(UserName ,Sex);

Is it helping you?

Just inform me if u need more .....code snippet?

Regards,

Karthick

Former Member
0 Kudos

hi

use webdynpro s default functionality, keep the fields mandatory and use the message manager class to report your exceptions, based on the values present when the user presses save.

u need to check for null as nibu says some times u may also have to take care of "" as well.

regards

vln

Former Member
0 Kudos

Hi Lakshmi,

If you are creating only one element for the node and if you are not initializing your attributes anywhere, these two lines of code should serve your purpose.

Iprivate<View_name>.INODEAElement elmt = wdContext.currentINODEAElement();

if(elmt.get<Attrubte_name>()==null)

wdComponentAPI.getMessageManager.reportWarning("your msg);

Best Regards,

Nibu.

Former Member
0 Kudos

Hi,

Do check the following link for Validating actions.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/webdynpro/us... validating and non-validating actions.pdf

Regards,

Vijith

Former Member
0 Kudos

Hi Lakshmi ,

You can check the size of the node by using

wdcontext.node<node name>.size()

IF it is zero give the warning message

Hope this helps you

Regards

Rohit

Former Member
0 Kudos

Hi,

I dont know whether i got your requirement right.

Suppose that you have bound your input field to the attributes in node a then you can get the values in a particular input field as

wdContext.current<Name of Node>Element().get<Name of atrribute>();

You can check whether this value is empty or not and print out the error message using message manager like

wdComponentAPI.getMessageManager().reportException("No Value",true);

Hope this helps.

Revert back for further clarification.

Regards,

Vijith