cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic node attributes

former_member540174
Participant
0 Kudos

I'm a bit lost and need some guidance in the right direction.

I have created a dynamic node and elements (in this case 5 will be variable once the bugger is working). This is working fine.


    if (firstTime)
    {
		IWDNodeInfo employees = wdContext.getNodeInfo().addChild("Employees",null,true,true,false,true,false,false,null,null,null);
		employees.addAttribute("employeeUserId","ddic:com.sap.dictionary.string");
		
    	IWDTransparentContainer employeeContainer = (IWDTransparentContainer)view.getElement("EmployeeContainer");
		
		for(int i=0; i<5; i++)
		{
			IWDInputField emplUserId = (IWDInputField) view.createElement(IWDInputField.class,"emplUserId" + i);
    		emplUserId.setLength(8);
    		emplUserId.setReadOnly(false);
    		emplUserId.setEnabled(true);
			IWDNodeInfo nodeinfo = wdContext.getChildNode("Employees", 0).getNodeInfo();
			emplUserId.bindValue(nodeinfo.getAttribute("employeeUserId"));
    		employeeContainer.addChild(emplUserId);
		}
    }

Now when I click a button I need to go though the context which now has node Employees with attibuttes for userid's. I'm getting lost trying to get to the context's employee user id's (employeeUserId).

In my button click event I've started my code but keep getting lost --- help me find my way...

To get the Employee node I do....


	IWDNodeInfo employeeNode = wdContext.getChildNode("Employees",0).getNodeInfo();

Then what is next to get the employee User Id's that are in this node? what do I do to get the employeeUserId attributes?

Diane

Edited by: Diane Fuller on Feb 28, 2008 7:31 PM

Accepted Solutions (1)

Accepted Solutions (1)

ThatSAPGuy
Advisor
Advisor
0 Kudos

Diane-

If I understand correctly you want to get hold of the value of the employee id (the one the user has entered in the input field). Here is how you do it:


IWDNode employeeNode = wdContext.getChildNode("Employees", null);
IWDNodeElement employeeElement = employeeNode.getElementAt(NNN);
String employeeID = employeeElement.getAttributeAsText("employeeUserId");

Where NNN is can be lead select, or 0, or a particular offset. If you want to use lead select you can initialise it to


int NNN = employeeNode.getLeadSelection();

Cheers-

Atul

former_member540174
Participant
0 Kudos

When I tried to view the second employeeElement it fails with a java.lang.IndexOutOfBoundsException: Index: 1, Size: 1 when I do the getElementAt(1)


	IWDNode employeeNode = wdContext.getChildNode("Employees",0);
	IWDNodeElement employeeElement = employeeNode.getElementAt(0);
	String employeeID = employeeElement.getAttributeAsText("employeeUserId");
	msgMgr.reportSuccess("UserId is " + employeeElement.getAttributeAsText("employeeUserId"));
	employeeElement = employeeNode.getElementAt(1);
	msgMgr.reportSuccess("UserId is " + employeeElement.getAttributeAsText("employeeUserId"));

As there are five input boxes on my page something is mismatching. Did I declare my node correctly - I need the node to contain 0 to many entries.


 if (firstTime)
    {
         IWDNodeInfo employees = wdContext.getNodeInfo().addChild("Employees",null,
		true,true,false,true,false,false,null,null,null);
		employees.addAttribute("employeeUserId","ddic:com.sap.dictionary.string");
		
    	IWDTransparentContainer employeeContainer = (IWDTransparentContainer)view.getElement("EmployeeContainer");
		
		for(int i=0; i<5; i++)
		{
			IWDInputField emplUserId = (IWDInputField) view.createElement(IWDInputField.class,"emplUserId" + i);
    		emplUserId.setLength(8);
    		emplUserId.setReadOnly(false);
    		emplUserId.setEnabled(true);
			IWDNodeInfo nodeinfo = wdContext.getChildNode("Employees", 0).getNodeInfo();
			emplUserId.bindValue(nodeinfo.getAttribute("employeeUserId"));
    		employeeContainer.addChild(emplUserId);
		}
    }

Sorry - so many questions -this is my try at first dynamic.

Diane

Former Member
0 Kudos

Binding against node elements is not possible. Either create different attributes or use a node-driven element like a table.

Armin

ThatSAPGuy
Advisor
Advisor
0 Kudos

Diane-

The problem you are having is you have only one attribute in your node (employeeUserId). This is being bound to five input fields. What you will have to do is create your attributes in a loop as well, i.e. using the addAttribute( ) method. So that there is a 1:1 relationship between your input field and an attribute in the context.

Cheers-

Atul

Edited by: Atul Savur on Feb 28, 2008 5:31 PM

Answers (0)