Skip to Content

In this blog I would like to share a real time scenario which I have recently implemented for one of our client – the scenario is “Copy Down” in WebDynpro Java tables.

Definition:  Copy Down is functionality where Cell data is copied from first row of table to the remaining rows of the same cell as a result of an event. The event can be onEnter for InputField, onToggle for CheckBox etc,.

Requirement:

–  Data should be copied from first row to remaining rows.

–  Only current selected cell data should be copied down. The remaining cells data should not be disturbed.

–  Event should be triggered only from first row. All other rows should behave normally.

–  The event can be triggered from an InputField, CheckBox, DropDown etc.., but action should be the same (i.e., needs generalized solution for any kind of source event).

–  Copy Down No Edit: Data should be editable only in first row. The remaining rows should have non-editable fields but data is copied down from first row.

–  Copy Down Edit: Cells in all rows should be editable with Copy Down from first row.

–  Blank for Entry: No copy down functionality, all cells should be editable in all rows.

I am not giving the details of how to implement Copy Down Edit, Copy Down No Edit and Blank for Entry as this can be easily achieved with context binding for UI properties.

Solution:

–  Define a table with required UI elements and context binding. (Assume we have created a node called ‘UserEntry’ and mapped with Table UI elements).

–  Do not map the “event handler method” for UI elements. Event handler mapping is done dynamically in wdModifyView method.

–  Implement an event handler method which is used as common handler for all events, with the following code:

  public void onActionCopyDownData(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, java.lang.String fieldName )

  {

    //@@begin onActionCopyDownData(ServerEvent)

      if(wdContext.nodeUserEntry().getLeadSelection()==0 && fieldName!= null && fieldName.trim().length()>0)

      {

            int size = wdContext.nodeUserEntry().size();

            IWDNodeElement sourceEle = wdContext.nodeUserEntry().getElementAt(0);

            IWDNodeElement targetEle = null;

            for(int index=1;index<size;index+)</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            {                 </pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>                  targetEle   = wdContext.nodeUserEntry().getElementAt(index);</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>                  targetElement.setAttributeValue(fieldName, sourceElement.getAttributeValue(attributeName));</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            }</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>      }</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>    }     </pre><p style=”margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in” class=”MsoNormal”>-       Define a String array with names of the attributes which requires copy down functionality.</p><p style=”margin: 0in 0in 0pt 0.5in” class=”MsoNormal”>static String[] copyDowAttrb  = {“Zz_Cmname”,”Zz_Color”,”Zz_Fabcomp1″,”Zz_Fabcomp2″,”Zz_Fabcomp3″,</p><p style=”margin: 0in 0in 0pt 0.5in” class=”MsoNormal”>”Zz_Fabcomp4″,”Zz_Fabcomp5″, “Zz_Fabperc1”, “Zz_Fabperc2”, “Zz_Fabperc3″, </p><p style=”margin: 0in 0in 0pt 0.5in” class=”MsoNormal”>”Zz_Fabperc4″,”Zz_Fabperc5″, “Zz_Packtype”, “Zz_Size”};</p><p style=”margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in” class=”MsoNormal”> </p><p style=”margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in” class=”MsoNormal”>-       Here I assumed that UI Element IDs are in a pattern with Context attribute names. In this case all UI element Ids ends with ‘X_editor’ where X is the context attribute name.</p><p style=”margin: 0in 0in 0pt” class=”MsoNormal”> </p><p style=”margin: 0in 0in 0pt 0.5in; text-indent: -0.25in; tab-stops: list .5in” class=”MsoNormal”>-       Implement the following code in wdModifyView()</p><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”> </pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>      if(firstTime)</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>      {</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            IWDAction onEnterAction = wdThis.wdCreateAction(IPrivateNonFlexProductionView.WDActionEventHandler.COPY_DOWN_DATA,””);</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            </pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            int copyDownAttribSize        = copyDowAttrb.length;</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            IWDViewElement viewElement  = null;</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            IWDInputField inputField      = null;</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            IWDCheckBox   checkBox        = null;</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            </pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            for(int index=0;index<copyDownAttribSize;index)</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>            {</pre><pre class=”MsoNormal” style=”margin: 0in 0in 0pt”>                  viewElement = view.getElement(copyDowAttrb[index]“_editor”);          

                  if(viewElement != null)

                  {

                        if(viewElement instanceof IWDInputField)

                        {

                              inputField = (IWDInputField)viewElement;

                              inputField.setOnEnter(onEnterAction);

                              inputField.mappingOfOnEnter().addParameter(“fieldName”,copyDowAttrb[index]);

                        }

                        else

                        if(viewElement instanceof IWDCheckBox)

                        {

                              checkBox = (IWDCheckBox)viewElement;

                              checkBox.setOnToggle(onEnterAction);

                              checkBox.mappingOfOnToggle().addParameter(“fieldName”,copyDowAttrb[index]);

                        }  

                        //This way code can be extended to all UI elements.                    

                  }

            }

}

  The following is the run time screen shot: 

!https://weblogs.sdn.sap.com/weblogs/images/13663/c3.JPG|height=103|alt=Copy Down|width=519|src=https://weblogs.sdn.sap.com/weblogs/images/13663/c3.JPG|border=0!</body>

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply