‎2008 Mar 05 11:46 AM
Hi All,
Could you please tell me how do I use set_attribute and get_attribute methods to get the user input from the dynpro screen?
The user enters some data in the input field. I need to get this data and validate it.
Please tell me how to get the user input.
Thanks & Regards,
Srilakshmi B
‎2008 Mar 07 7:23 AM
hi
to validate user input data, use PAI event , and check it there.
‎2008 Mar 18 7:35 AM
hi,
you can go through it,might be your problem solve.
Example for Using Messages
The following example shows how you can use messages created in the Message Editor. In the example, both messages with static text and messages that are dependent on user inputs that is, messages with dynamic text are defined.
Description of Example
Users can create a domain in this sample application. They can then enter a number in the next input field and press Click here to validate. If the specified number lies in the previously specified range, the user is informed of this fact in a standard message. If the number does not lie within this domain, the user sees a warning message.
Prerequisites
You have created a Web Dynpro application and defined view MainView within a Web Dynpro component.
Procedure
Creating the View
...
Define the view as illustrated below:
Context Creation:
The context that provides the data is created as follows:
...
1. Create a context node, UIElem
2. Set the propertycardinality to 1..1 for the context node.
3. Create the context attributes a, b, and TypeField.
4. Set the Type of the context attributes to Integer.
Data Binding
To make the messages dynamic with regard to specification of the domain, the user inputs have to be saved. To do this, the input fields have to be bound to the context.
sss
Object
Object ID
Data Binding to Attribute
Path Within the Context Structure
a
Input Field
A
MainView.UIElem.a
b
Input Field
B
MainView.UIElem.b
Children_2
Input Field
TypeField
MainView.UIElem.TypField
In addition, bind the Children_3 pushbutton to action ValidateAction, which you also have to create.
Creating Messages in the Message Pool
The Web Dynpro tools provide a special message editor for defining messages of different types.
A message is defined by a specified key, message type, and message text. The message types error, warning, and standard are predefined.
Create the following messages:
Messages Defined in the Message Editor
Message Key
Message Type
Message text
key1
warning
Please enter a number between the range of and ! and are placeholders for the user input (the domain), which changes dynamically. key2 standard The value entered is within the valid range. Implementation Because the messages are only displayed when the user Chooses Click here to validate, the messages must be implemented in the method onActionValidateAction: Implementierung der Methode onActionValidateAction() //@@begin imports import com.sap.tc.webdynpro.progmodel.controller.MessageManager; import com.sap.test.errorhandlingtest1.wdp.IMessageErrorhandlingTest1; import com.sap.test.errorhandlingtest1.wdp.IPrivateMainView; //@@end //... public void onActionValidateAction( com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent) { //@@begin int i = wdContext.currentUIElemElement().getTypField(); int a = wdContext.currentUIElemElement().getA(); int b = wdContext.currentUIElemElement().getB(); MessageManager msgMgr = (MessageManager)wdThis.wdGetAPI().getComponent().getMessageManager(); if (a < i && i < b) { msgMgr.reportMessage(IMessageErrorhandlingTest1.KEY2, null, true); } else { Object[] arg ={new Integer(a), new Integer(b)}; msgMgr.reportMessage(IMessageErrorhandlingTest1.KEY1, arg, true); } //@@end } The following tasks have been implemented in this method: 1. Read user inputs: int I = wdContext.currentUIElemElement().getTypField(); int a = wdContext.currentUIElemElement().getA(); int b = wdContext.currentUIElemElement().getB(); 1. Read messages from the Message Manager: MessageManager msgMgr = (MessageManager) wdThis.wdGetAPI().getComponent().getMessageManager(); 2. Does the input lie within the defined domain? if (a < i && I < b) 3. Call the standard message when the input lies within the domain: MsgMgr.reportMessage(IMessageErrorhandlingTest1.KEY2, null); Method reportMessage can be used to read the messages from the Message Manager. In this way you define the key and the objects that you want to change dynamically in the messages. Because no dynamic text was defined in your standard messages, you define null as a parameter. 4. Call the warning messages when the input does not lie within the domain: Object[] arg ={new Integer(a), new Integer(b)}; MsgMgr.reportMessage(IMessageErrorhandlingTest1.KEY1, arg); Because the warning messages ( Please enter a number between the range of and !) contain text that depends on the user input, you also have to define the parameters for the domain in an object array. In the messages, the first object is then called from the array with (and the second with , and so on).
Result
After you have built and deployed your application, you can call it by choosing Run.
If the user enters a number that lies within the defined domain, a standard message is displayed:
If the user enters a number that does not lie within the defined domain, a warning message is displayed:
‎2008 Mar 24 9:07 PM
Hi,
You can use the method WDDOBEFOREACTION to validate the values before the user set an action or you can create an action to the onEnter event of the field to be validated when the user press Enter.
Regards,