cancel
Showing results for 
Search instead for 
Did you mean: 

Checking for mandatory fields - How to

Former Member
0 Kudos

Hi

I have to check for some mandatory field in Webdynpro when the user click Save button using messages.When all the mandatory fields are filled up it will save and proceed to the next view.

What is the best approach to acheive this functionality ?

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi

Incase you want to perform only a simple check(as in just check whether the field is empty or if it is of required length) you can use methods 1 and 2 of my prev post.

In case you want to do some additional checks then you can always use method 3 , which uses "reportContextAttributeMessage" method of "IWDMessageManager" as described by krishnam.

Looking forward to your reply.

Regards,

Abhishek.

Former Member
0 Kudos

Hi,

In order to <b>check for mandatory fields</b> , you can do this...

1. To set an inputfield as mandatory, you can just its state property as required.

To raise an error, I think you have to code some validation (in your onActionClicked method)...

2. For corresponding property define some simple types in Dictionaries / Local Dictionary / Data Types / Simple Types (see WD outline) with minLength > 0 constraint or FixedLength constraint and use this simple types as the property types of the context attributes. If you bind the UI elements to this context attributes, the WD runtime will do the checks automatically.

3. Check the contents of the UI elements with required input manually (by checking the contents of the bound context attributes).

Use the report(Invalid)ContextAttribute... methods of the Message Manager API to report missing data.

Hope this helps you.

Regards,

Abhishek.

Former Member
0 Kudos

HI Ananda Sankar,

For this first we have to edit the message pool editor with some relevant error or warning messages if the field is empty.

for this we can define as

Message Defined in the Message Editor

Message Key Message Type Message Text

MissingInput error : Entry of a valid is required for

proceeding with the requested service.

we can display the defined message in the implementation of the view

controller using the method reportContextAttributeMessage()of the

IWDMessageManager interface. The message is contained in the generated

IMessageSimpleErrors interface as a constant called MISSING_INPUT. The

value of the argument is passed in the array {"Name"}.

Implementation of the View Controller

...

IWDMessageManager msgMgr =

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

msgMgr.reportContextAttributeMessage(

this.wdContext.currentContextElement(), attributeInfo,

IMessageSimpleErrors..MISSING_INPUT, new Object[] {"Name"},true);

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);

we have to write the method checkmandotory check(say)

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

}

In initilization we have to set as

public void initialize() {

//@@begin initialize()

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

}

we have to call mandatory method under this postmessage button

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

{

//@@begin onActionSave(ServerEvent)

this.checkMandatory("Name");

}

and when click on "post message" button it will go to next screen(we have to fire the plugs to next screen on click on button) if all the required fields are filled.If any of the field is not filled with data then it gives u error message as mentioned in the "message pool".

hope ur satisfied.If ur satisfied pls dont forget to reward some points.

regards,

Krishnam Raju.

Former Member
0 Kudos

Hi,

We cannot set the InputField's property as mandatory. The best way is to check if any InputField is empty. First check if its 'null' (for String attributes). Then trim() and check for its length. It should be greater than 0.

String text = wdContext.currentContextElement().getText();

if(text!=null)

{

text = text.trim();

if(text.length()>0)

{

...

}

}

Regards,

Piyush.

PS: for an integer field the default value will be 0.

Former Member
0 Kudos

Hi

Thanks. But which IWDMessage maqnager service I have to use to report the error and stay on the same view BUT when corrected will move on to the next view.

Regards

Ananda

Former Member
0 Kudos

Hi,

In order to display some message:

wdComponentAPI.getMessageManager().reportSuccess("Message");

u can use .reportWarning(""); or .reportException("",true);

Now fire the plug to another view, only if u find all the fields are correct else display the message.

Regards,

Piyush.

Former Member
0 Kudos

hi ananda,

If u want name filed to be mandatory with *(red) symbol we have to change the Inputfiled name input form group state(under properties) as required.

Regards,

Krishnam raju