cancel
Showing results for 
Search instead for 
Did you mean: 

Check for blank attribute

Former Member
0 Kudos

hi!

I have created a form template with Context node as Student

Context
     |--Student (node)
          |---roll (attribute)
          |---name (attribute)
          |---age (attribute)
          |  ...... and many more attribtes

On clicking submit I want to do some processing.

But processing can be carried out only if no field is left blank.

How can I check if all attributes in the Student node are filled?

Is is possible to do it without individually checking each attribute for blank field?

Please Help.

Accepted Solutions (1)

Accepted Solutions (1)

sanyev
Active Participant
0 Kudos

Hi p78,

You can use a Validating action to achieve your requirement. Basically when you create an action handler there is a checkbox "Validation" which should be checked. Once you make an action as a validation action when the user clicks on the button that is associated with the validation action, Webdynpro framework will do a form validation. A basic check will be carried out like data type check, length check etc.

If there is no validation error then the action handler will be called. But here in your case blank values are not checked by the framework form validation mechanism even if in the inputfield you set the state as required. But still there is a way to highlight the errors in the form. Once the action handler is called you have to check the mandatory attributes in the context and see if they are null or blank. If that is the case then you can trigger the frameworks validation mechanism to show the error fields and give a corrective message.

IWDMessageManager msgMgr =
	wdComponentAPI.getMessageManager();
	msgMgr.reportContextAttributeMessage(
            wdContext.nodeStudent().currentStudentElement().getAttributePointer("name"),
	IMessageActionValidationTest.MISSING_INPUT, new Object[] {"Name"});

If you execute the above code in your action handler then the inputfield bound to the attribute name will be highlighted in error. The message with key MissingInput which is there in the message pool will be shown as the error explanation message.

You can go throuth this tutorial on form validation. [https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60db527d-7be4-2a10-0283-e915cfb179a8]

I have done form validation with empty field check before and the above document was very helpful.

If you would like to set a length limitation to an attribute you can set the Min or Max length for that attribute and the default validation mechanism will take care of the validation.

You can write the code in wdDoInit() for setting length limitation.

wdContext().nodeData().getNodeInfo().getAttribute("name").getModifiableSimpleType().setMinLength(5);

Hope this helps.

Regards,

Sanyev

Former Member
0 Kudos

Hi!

Thanks that was indeed very useful.

Regards

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

U can use this also for checking

if(wdThis.wdGetContext().currentStudentElement().getname().equalsIgnoreCase(""))

{

//

}

John

Former Member
0 Kudos

Hi...

On action Submit.. Write this code

if ( wdContext.currentStudentElement().getroll()==null |

wdContext.currentStudentElement().getname() ==null |

wdContext.currentStudentElement().getage()==null )

{

wdComponentAPI.getMessageManager().reportWarning("All the fields are mandatory");

}

Regards,

Alamelu

Former Member
0 Kudos

Hi ,

I Hope this is your requirement that no input fields must be empty on clicking the submit button.

If so the solution will be very easy,

just bind all the attribute under the nodes to various inputfields , and there is a proprty called state for input fields , chage it to "required" from normal , then on clicking submit it will automatically throw error message , you no need to check the attribute , since you have binded the attribute to the input field.

Regards,

Sam Charles J.

Former Member
0 Kudos

Hi,

on action submit check for null values for each n evry field..

put checks for null values on action...

Regards

Khushboo