<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Validating Input field in Web Dynpro in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501016#M842102</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the method &lt;STRONG&gt;WDDOBEFOREACTION&lt;/STRONG&gt; to validate the values before the user set an action or you can create an action to the &lt;STRONG&gt;onEnter&lt;/STRONG&gt; event of the field to be validated when the user press Enter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 24 Mar 2008 21:07:26 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2008-03-24T21:07:26Z</dc:date>
    <item>
      <title>Validating Input field in Web Dynpro</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501013#M842099</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;Could you please tell me how do I use set_attribute and get_attribute methods to get the user input from the dynpro screen?&lt;/P&gt;&lt;P&gt;The user enters some data in the input field. I need to get this data and validate it.&lt;/P&gt;&lt;P&gt;Please tell me how to get the user input.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards,&lt;/P&gt;&lt;P&gt;Srilakshmi B&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Mar 2008 11:46:51 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501013#M842099</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-05T11:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Validating Input field in Web Dynpro</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501014#M842100</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi &lt;/P&gt;&lt;P&gt;  to validate user input data, use PAI event  , and check it there.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2008 07:23:41 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501014#M842100</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-07T07:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Validating Input field in Web Dynpro</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501015#M842101</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;you can go through it,might be your problem solve.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; Example for Using Messages &lt;/P&gt;&lt;P&gt;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 &amp;#150; that is, messages with dynamic text &amp;#150; are defined.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Description of Example&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Prerequisites&lt;/P&gt;&lt;P&gt;You have created a Web Dynpro application and defined view &amp;#147;MainView&amp;#148; within a Web Dynpro component.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Procedure&lt;/P&gt;&lt;P&gt;Creating the View&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Define the view as illustrated below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Context Creation:&lt;/P&gt;&lt;P&gt;The context that provides the data is created as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       1.      Create a context node, UIElem&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       2.      Set the propertycardinality to 1..1 for the context node.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       3.      Create the context attributes a, b, and TypeField.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;       4.      Set the Type of the context attributes to Integer.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data Binding&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;sss&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Object&lt;/P&gt;&lt;P&gt; Object ID&lt;/P&gt;&lt;P&gt; Data Binding to Attribute&lt;/P&gt;&lt;P&gt; Path Within the Context Structure&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt; Input Field&lt;/P&gt;&lt;P&gt; A&lt;/P&gt;&lt;P&gt;  MainView.UIElem.a&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;b&lt;/P&gt;&lt;P&gt; Input Field&lt;/P&gt;&lt;P&gt; B&lt;/P&gt;&lt;P&gt;  MainView.UIElem.b&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Children_2&lt;/P&gt;&lt;P&gt; Input Field&lt;/P&gt;&lt;P&gt; TypeField&lt;/P&gt;&lt;P&gt;  MainView.UIElem.TypField&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In addition, bind the Children_3 pushbutton to action ValidateAction, which you also have to create. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Creating Messages in the Message Pool&lt;/P&gt;&lt;P&gt;The Web Dynpro tools provide a special message editor for defining messages of different types.  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A message is defined by a specified key, message type, and message text. The message types  error,  warning, and  standard are predefined. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Create the following messages:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Messages Defined in the Message Editor&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Message Key&lt;/P&gt;&lt;P&gt; Message Type&lt;/P&gt;&lt;P&gt; Message text&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;key1&lt;/P&gt;&lt;P&gt; warning&lt;/P&gt;&lt;P&gt; Please enter a number between the range of &lt;SPAN __jive_macro_name="0"&gt; and &lt;SPAN __jive_macro_name="1"&gt;&lt;/SPAN&gt;!

  &lt;/SPAN&gt; and &lt;SPAN __jive_macro_name="1"&gt; 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 &amp;lt; i &amp;amp;&amp;amp; i &amp;lt; 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 &amp;lt; i &amp;amp;&amp;amp; I &amp;lt; 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  &lt;SPAN __jive_macro_name="0"&gt;&lt;/SPAN&gt; and &lt;/SPAN&gt;!) 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 &lt;SPAN __jive_macro_name="0"&gt;&lt;/SPAN&gt; (and the second with &lt;SPAN __jive_macro_name="1"&gt;&lt;/SPAN&gt;, and so on).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Result&lt;/P&gt;&lt;P&gt;After you have built and deployed your application, you can call it by choosing Run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the user enters a number that lies within the defined domain, a standard message is displayed:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the user enters a number that does not lie within the defined domain, a warning message is displayed:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Mar 2008 07:35:34 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501015#M842101</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-18T07:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Validating Input field in Web Dynpro</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501016#M842102</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can use the method &lt;STRONG&gt;WDDOBEFOREACTION&lt;/STRONG&gt; to validate the values before the user set an action or you can create an action to the &lt;STRONG&gt;onEnter&lt;/STRONG&gt; event of the field to be validated when the user press Enter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Mar 2008 21:07:26 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/validating-input-field-in-web-dynpro/m-p/3501016#M842102</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-24T21:07:26Z</dc:date>
    </item>
  </channel>
</rss>

