cancel
Showing results for 
Search instead for 
Did you mean: 

What to do to add some UI elements in a group element on click of a button?

Former Member
0 Kudos

I want to add Input fields and labels in the a group in a view on click of a button.

How to :

1)Access the right gropu in view through code?

2)Create elements in the group through code?

Please reply soon!

Sumit

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi All,

I also want to change the layoutdata of a UI element through code.

Please help!

Sumit

Former Member
0 Kudos

See my sample code.

Armin

Answers (8)

Answers (8)

Former Member
0 Kudos

Armin,

Please can you tell me :

How to bind the view contexts with a model context through code?

Reply soon!

Sumit

Former Member
0 Kudos

Armin ,

That problem got solved.

I have defined a simple type and used it.

Thanks!

Sumit

Former Member
0 Kudos

Armin,

Your code actually suits my situation and I am adding a row on click of the button

(Row contains Inputfields and labels)

When i have to create value attribute I need to give data type in addAttribute() function .

In layout for the first row I have choosen string as the data type.

While going with coding when i give the data type String or char or long.

It gives an exception.

Sumit

Former Member
0 Kudos

Please open a new thread and post the code.

Armin

Former Member
0 Kudos

Armin,

Thanks for your answer.

I have given String type for the first row.

But while creating a new context attribute through code I a unable to give the String data type.

What should I do?

Sumit

Former Member
0 Kudos

Please open a new thread and give more details.

Armin

Former Member
0 Kudos

You need a flag to signal that the elements should be added with the next call to wdDoModifyView().

Add a boolean context attribute "AddFields" to the view context and set it to true in the action handler for the button:

void onActionAddFields(...)
{
  wdContext.currentContextElement().setAddFields(true);
}

In method wdDoModifyView(), check the flag and reset it after the code that adds the fields:

(I assume the group has a MatrixLayout)

static void wdDoModifyView(...)
{
  if (wdContext.currentContextElement().getAddFields())
  {
    /* access group by ID given at designtime */
    IWDGroup group = (IWDGroup) view.getElement("groupID");
    IWDLabel label = (IWDLabel) view.createElement(IWDLabel.class, null);
    /* if new row in MatrixLayout should be started: */
    IWDMatrixHeadData labelLayoutData = label.createLayoutData(IWDMatrixHeadData.class);
    /* change settings for layout data if needed */

    label.setText("whatever");

    IWDInputField field = (IWDInputField) view.createElement(IWDInputField.class, null);
    /* if in same row as label: */
    IWDMatrixData fieldLayoutData = field.createLayoutData(IWDMatrixData.class);
    /* change field layout data if needed */

    field.bindValue("context.attribute.path");
    label.setLabelFor(field);
    group.addChild(label);
    group.addChild(field);
    wdContext.currentContextElement().setAddFields(false);
  }
}

Armin

Former Member
0 Kudos

Hi,

In your WdModifyView add this code simply.

// Root element of the every view capture the initially.

IWDTransparentContainer container = (IWDTransparentContainer)view.getElement(IWDTransparentContainer.class,"RootUielementcontainer");

// create the Group dynamically.

IWDGroup theGroup = (IWDGroup)view.getElement("InputGroup");

// create your ui elements add to be group.

IWDButton but = (IWDButton)view.createElement(IWDButton.class,"but");

but.setText("rama");

but.setTooltip("Developpment");

// create on more lablel

IWDLabel label = (IWDLabel)view.createElement(IWDLabel.class,"nagu");

label.setText("rama");

// finally add your label and button to Group.

grp.addChild(but);

grp.addChild(label);

// group to be added to container.

container.addChild(grp);

This might helps you.

Thanks,

Lohi.

Former Member
0 Kudos

Hi,

1. You always know the id of the Group UI element from the designtime. So in the wdDoModifyview() method, you will need to do

view.getElement("id_of_group");

2. For this go through <a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/4f/07cf3dd28b5610e10000000a114084/frameset.htm">this</a> link.

Regards,

Satyajit.

abhimanyu_lagishetti7
Active Contributor
0 Kudos

Hi Sumit

in wdModifyView() write the code accordingly

IWDButton theButton = (IWDButton)view.createElement(

IWDButton.class, "butn");

IWDGroup theGroup = (IWDGroup)view.getElement("Group1");

theGroup.addChild( theButton);

this code adds button to your group with id "Group1".

for more information on dynamic UI Elements go through this link

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/74cda090-0201-0010-6b91-f85b2489...

Regards

Abhimanyu L