Skip to Content
avatar image
Former Member

Many times dynamic generate UIElement at Runtime ???

Hello Everyone,

I wanna generate a UIElement (InputField) at runtime. When man click a button "Add InputField", then a UIElement (InputField) is dynamic generated. Man can generate many times UIElement"InputField" with this button.

I have tried the Webdynpro Tutorial 17. But not yet any idea.

Plx give me some suggestions and code.

Thanks in advance

best regards

Yaning

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Jan 16, 2007 at 05:11 AM

    hi

    for this create 2 int variables <b>act</b> and a <b>counter</b>

    //@@begin others

    static int act,counter=0;

    //@@end

    <b>in Doinit set act to 0.</b>

    public void wdDoInit()

    {

    //@@begin wdDoInit()

    act=0;

    //@@end

    }

    <b>create an action(onActionCreate_Element) and assign it to the button ui element</b>

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

    {

    //@@begin onActionCreate_Element(ServerEvent)

    act = 1;

    //@@end

    }

    <b>in wdDoModifyView</b>

    public static void wdDoModifyView(IPrivateDynamicView wdThis, IPrivateDynamicView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

    {

    //@@begin wdDoModifyView

    if( act== 1)

    {

    IWDTransparentContainer con= (IWDTransparentContainer)view.getElement("RootUIElementContainer");

    IWDInputField input = (IWDInputField)view.createElement(IWDInputField.class,"input1"+counter);

    IWDAttributeInfo test = wdContext.getNodeInfo().addAttribute("name"+counter,"ddic:com.sap.dictionary.string");

    input.bindValue(test);

    input.setVisible(WDVisibility.VISIBLE);

    counter++;

    con.addChild(input);

    act = 0;

    }

    //@@end

    }

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 16, 2007 at 06:42 AM

    Hi Yaning,

    Let ur root container id be RootUIElementContainer

    Do the following steps

    1. Create a static variable say ' myvar ' of type com.sap.tc.webdynpro.progmodel.api.IWDView in last declaration part(ie. inside //@@begin others //@@end.

    2. Create a static variable of type int in last declaration part as static int count=0;

    2. In wdDoModifyView(), add the following

    myVar=view;

    3. Inside ur action to create input field, add the following

    IWDTransparentContainer root=(IWDTransparentContainer)view1.getElement("RootUIElementContainer");

    IWDAttributeInfo attrInfo=wdContext.getNodeInfo().addAttribute("Name"+count,"ddic:com.sap.dictionary.string");

    IWDInputField input=(IWDInputField)view1.createElement(IWDInputField.class,"input"+count);

    input.bindValue(attrInfo);

    input.setVisible(WDVisibility.VISIBLE);

    root.addChild(input);

    count++;

    Regards,

    Fahad Hamsa

    Add comment
    10|10000 characters needed characters exceeded

    • >

      > Do the following steps

      >

      > 1. Create a static variable say ' myvar ' of type

      > com.sap.tc.webdynpro.progmodel.api.IWDView in last

      > declaration part(ie. inside //@@begin others

      > //@@end.

      >

      > 2. Create a static variable of type int in last

      > declaration part as static int count=0;

      >

      It's not a good idea to create static variables like you proposed. Such application will not work in multiuser (multithreaded) environment.

      It's better to store all necessary variables in the context of the view controller which is available in static method 'wdDoModifyView()'.

      BR

      Sergei

  • avatar image
    Former Member
    Jan 16, 2007 at 10:02 AM

    Hi Yaning,

    U can destroy the input field as

    IWDInputField input=(IWDInputField)view1.getElement(input field ID);

    input.destroy();

    Regards

    Fahad hamsa

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 16, 2007 at 12:19 PM

    hello,

    another question,

    when man click the button "delete field" , the Context attribute must be removed.

    how do it?

    thx

    regards

    Yaning

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Siarhei Pisarenka

      hi,

      my NWDS version SAP

      NetWeaver Developer Studio

      Version: 2.0.17

      i think ,it is the same as you say.

      +++++

      IWDInputField theInput = (IWDInputField) view.getElement("InputField" + counter);

      theInput.destroy();----


      "compile error"

      +++++

      regards

      yaning