cancel
Showing results for 
Search instead for 
Did you mean: 

GetAttribute() at Index?

Former Member
0 Kudos

I'm trying to dynamically assign values to a dropdown UI at runtime. I have the data in a context structure and wish to modify the available drop down values. I've written the code below and it works -- I think -- except where I get the IWDAttributeInfo of the current element. I can't seem to figure out how to get the something like ...getQuestion_ResponsesElementAt(i).getAttribute(...).

The code below appears only to get and bind the first element.

Any thoughts would be much appreciated.

/Greg

int noQuestions = wdContext.nodeQuestion_Responses().size();
		
		for ( int i = 0; i < noQuestions; i++ ) {
			
			qElem = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i);
			int noResponses = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i).nodeResponses().size();	
					
	 		IWDDropDownByKey dropDown = (IWDDropDownByKey)view.createElement(IWDDropDownByKey.class,
	 			                                                                 null );
	 			
	                             IWDAttributeInfo attrinfo = wdContext.nodeQuestion_Responses().getNodeInfo().getAttribute(IPrivateQuestionView.IQuestion_ResponsesElement.ANSWER);	
			ISimpleTypeModifiable simple = attrinfo.getModifiableSimpleType();
			IModifiableSimpleValueSet valueSet = simple.getSVServices().getModifiableSimpleValueSet();
			
			for ( int x=0; x< noResponses; x++ ) {
					rElem = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i).getResponsesElementAt(x);
					valueSet.put(rElem.getRvalue(), rElem.getRtext());
			}
                                             
			dropDown.bindSelectedKey(attrinfo);
			dropDown.setWidth("113");
			
			theUIElement = dropDown;
			
			theLabel = (IWDLabel)view.createElement( IWDLabel.class, null );
			theLabel.setText( qElem.getQtext());
			theLabel.setLabelFor( theUIElement.getId());
	
			//	 add UI elements to container
			theGroup.addChild(theLabel);
			theGroup.addChild(theUIElement);
			
		}
    }

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

To further explain...

I have the context structure below. Which a contains multiple questions where each can contain multiple responses. In the future there will be code that will filter out reponses that are not applicable. I'd hoped to iterate through the Questions_Responses create the UI element and bind their reponses to IWDDropDownBy[Key/Index]. So far no joy.

Thanks for your time.

/Greg



+ Question_Responses ( 0..n, s=true )
   - Answer
   - Qtext
   ...
   + Responses ( 0..n, s=false)
      - Rtext
      - Rvalue
      ... 


former_member182372
Active Contributor
0 Kudos

Do you need to create drop downs dynamically? because you can make table (datasource bound to QuestionResponses) add column, column editor with type drop down by index and bind texts property to Question_Responses.Responses.Rtext

Former Member
0 Kudos

I gave you sample code using DropDownByIndex in the other thread.

If you really have to create the UI elements programmatically (do you?), the following should do the job:

IWDDropDownByIndex questionSelector = (IWDDropDownByIndex) view.createElement(IWDDropDownByIndex.class, null);

questionSelector.bindTexts("Question_Responses.QText");

IWDDropDownByIndex responseSelector = (IWDDropDownByIndex) view.createElement(IWDDropDownByIndex.class, null);

responseSelector.bindTexts("Question_Responses.Responses.RText");

/* Access container e.g. Group */

IWDGroup container = (IWDGroup) view.getElement("GroupID");

container.addChild(questionSelector);

container.addChild(responseSelector);

To access for example response 2 for question 1 (where numbering starts with 0), you can use code like

IQuestion_ResponsesElement q = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(1);

IResponsesElement r = q.nodeResponses().getResponsesElementAt(2);

What is still the problem?

Armin

Message was edited by:

Armin Reichert

Former Member
0 Kudos

Armin,

I tried to implement the code as suggest and changed the context as suggest. What I get using the code below is the responses listed for the 3 questions are the same (responses from question 1). I've tried several permutations but am getting nowhere -- except frustrated.

Thanks,

Greg



<context root>
   + Question_Responses ( 0..n, s=true )
      - Answer
      - Qtext
       ...
      + Responses ( 0..n, s=false)
         - Rtext
         - Rvalue
         ... 
       + AReponses ( 0..n, s=false)
        - Qid
        - Rtext
        - Rvalue



if (firstTime) {

		IWDUIElement theUIElement = null;
		IWDLabel theLabel = null;
		IWDGroup theGroup = (IWDGroup)view.getElement("InputGroup");

		
		int noQuestions = wdContext.nodeQuestion_Responses().size();
		for (int i = 0; i < noQuestions; i++) {

			qElem = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i);
			int noResponses = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i).nodeResponses().size();
			for (int x = 1; x < noResponses; x++) {
				/* Here I will filter responses.  For now we'll
				 *  just skip the first one.
				 */				
				rElem = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i).getResponsesElementAt(x);
				IPrivateQuestionView.IAResponsesElement arElem = qElem.nodeAResponses().createAResponsesElement();
				arElem.setQid( qElem.getQid() );
				arElem.setRtext( rElem.getRtext() );
				arElem.setRvalue( rElem.getRvalue() );
				qElem.nodeAResponses().addElement( arElem );

			}

			IWDDropDownByIndex dropDown = (IWDDropDownByIndex)view.createElement(IWDDropDownByIndex.class, null );
			dropDown.bindTexts("Question_Responses.AResponses.Rtext");
			
			dropDown.setWidth("113");
			
			theUIElement = dropDown;
			theLabel = (IWDLabel)view.createElement( IWDLabel.class, null );
			theLabel.setText( qElem.getQtext());
			theLabel.setLabelFor( theUIElement.getId());
	
			//	 add UI elements to container
			theGroup.addChild(theLabel);
			theGroup.addChild(theUIElement);
			

		}

Message was edited by:

Greg Preston

Message was edited by:

Greg Preston

Former Member
0 Kudos

Are you sure that singleton=false for the inner nodes? How did you fill the nodes?

Armin

Former Member
0 Kudos

I've checked and rechecked. I've since updated the context (revised below) to introduce a parent node so I could set Questions to singleton = false.

The context in the view controller was loaded using the WDCopyService command below. The Component Controller (ccContext) was loaded

from an RFC. Do you think this could be my issue?

IContextNode ccContext = wdThis.wdGetMini_vc_prototypeController().wdGetContext();
WDCopyService.copySubtree(ccContext.nodeQuestion_Responses(), wdContext.nodeRFQ().nodeQuestions() );

FYI - I placed two tables in a view and bound the context structure to them -- table1 = RFQ.Questions and table2 = RFQ.Questions.Responses.

When questions were selected in table one the proper responses would appear in table2. Not sure that tells us anything.

<Context>
	+ RFQ (c=1..n,s=true)
	  - ID
	+ Questions (c=1..n,s=false)
	  - Qid
	  ...
	  + Responses (c=1..n,s=false)
	    - Rtext
	    - Rvalue

Former Member
0 Kudos

The "Questions" node does not need to be non-singleton. My guess is that you don't fill the nodes correctly.

Perhaps you can build first a simple test view with 2 DropDownByIndex elements and data binding as I showed in my earlier post.

In wdDoInit(), create some sample data with code like

String[] questions = { "Q1", "Q2" };
String[][] responses = { {"R11", "R12"}, {"R21", "R22", "R23"} };
for (int ix = 0; ix < questions.length; ++ix)
{
  IQuestionsElement q = wdContext.createAndAddQuestionsElement();
  q.setQid(questions[ix]);
  for (int j = 0; j < responses[ix].length; ++j)
  {
    IResponsesElement r = q.nodeResponses().createAndAddResponsesElement();
    r.setRtext(responses[ix][j]);
  }
}

What do you get?

Armin

Message was edited by:

Armin Reichert

Former Member
0 Kudos

Armin,

Thanks again for your time. I’ve implemented your example and it works as designed. This scenario being I have a DropDownByIndex of Questions (QuestionSelector) and a DropDownByIndex of responses (ResponseSelector). As the Questions change so do their associated responses. Presentation is shown below.

QuestionSelector (dropdownbyindex)     
   Q1
   Q2

ResponseSelector (dropdownbyindex)
   R11
   R12
   R21
   R22
   R23

The scenario I’m trying to implement would look the one below; where both questions are shown individually along with their associated responses. The code I’ve posted was my attempt to do so. The problem with what I've done so far is that Q1_Responses and Q2_Responses both show Q1_Reponses.

“Q1” (label)  
Q1_Responses (dropdownbyindex)
   R11
   R12

“Q2” (label)  
Q2_Responses (dropdownbyindex)
   R21
   R22
   R23

Any ideas? I assume this is possible.

Thanks again,

/Greg

Former Member
0 Kudos

If the following layout is ok for you, you can use a Table element with two columns:

Q1 (TextView) Q1_Responses (DDByIndex)

Q2 (TextView) Q2_Responses (DDByIndex)

...

Table.dataSource = "Questions"

TableColumn1.TableCellEditor = TextView1

TextView1.text = "Questions.Text"

TableColumn2.TableCellEditor = DropDownByIndex1

DropDownByIndex1.texts = "Questions.Responses.Text"

If available in your Web Dynpro release, you can also use a RowRepeater.

Armin

Former Member
0 Kudos

I saw the Table object and did some testing. Would that be my only option? verses being able to position the UI elements independently?

Thanks again.

/Greg

Former Member
0 Kudos

With the given context structure it would be easiest to use a Table or RowRepeater to achieve what you want. Otherwise you will have to create individual context nodes for the questions which make things more complicated

Armin

Former Member
0 Kudos

Armin,

Thanks for all your help!!!!

/Greg

Points awarded.

Answers (3)

Answers (3)

Former Member
0 Kudos

Gentlemen,

I've appologize for not understanding what you're trying to tell me. I just don't understand. I believe I've modified the code appropriately to use DropDownByIndex however now the lists are blank -- you probably knew this.

Below is the updated code -- please let me know where I went wrong.

BTW: Given each of you points!!!! Thanks.

/Greg

if (firstTime) {

		IWDUIElement theUIElement = null;
		IWDLabel theLabel = null;
		IWDGroup theGroup = (IWDGroup)view.getElement("InputGroup");
		
		int noQuestions = wdContext.nodeQuestion_Responses().size();
		for ( int i = 0; i < noQuestions; i++ ) {
			qElem = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i);
			int noResponses = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i).nodeResponses().size();	
	 		IWDDropDownByIndex dropDown = (IWDDropDownByIndex)view.createElement(IWDDropDownByIndex.class, null );
	        	IWDAttributeInfo attrinfo = wdContext.nodeQuestion_Responses().getNodeInfo().getAttribute(IPrivateQuestionView.IQuestion_ResponsesElement.ANSWER);	
			
			ISimpleTypeModifiable simple = attrinfo.getModifiableSimpleType();
			IModifiableSimpleValueSet valueSet = simple.getSVServices().getModifiableSimpleValueSet();
			
			for ( int x=0; x< noResponses; x++ ) {
					/* Code will eventually go here to filter out
					 * reponses that are not applicable.
					 */
					rElem = wdContext.nodeQuestion_Responses().getQuestion_ResponsesElementAt(i).getResponsesElementAt(x);
					valueSet.put(rElem.getRvalue(), rElem.getRtext());
			}
    			dropDown.bindTexts(attrinfo);
			dropDown.setWidth("113");
			theUIElement = dropDown;
			theLabel = (IWDLabel)view.createElement( IWDLabel.class, null );
			theLabel.setText( qElem.getQtext());
			theLabel.setLabelFor( theUIElement.getId());
	
			theGroup.addChild(theLabel);
			theGroup.addChild(theUIElement);
			
		}
    }

Former Member
0 Kudos

I guess I should have explained my issue better. What Maksim said I believe to be correct and is exactly the sympton that I'm experiecing....where all reponses are being bound to the same attribute.

I think what I need to to understand how -- hopefully in my current programming structure to selected the attribute of the element being processed by the for...loop.

As always .. thank you for your time.

/Greg

former_member182372
Active Contributor
0 Kudos

Greg, as Armin said, your scenario is perfect for drop down by index especially combination with table - ddbi as column.

former_member182372
Active Contributor
0 Kudos

Hi Greg,

Your code is not really correct. Let`s say you have:

Question 1:

Answer 1_1;

Answer 1_2;

Answer 1_3;

Question 2:

Answer 2_1;

Answer 2_2;

Question 3:

Answer 3_1;

Answer 3_2;

You are binding DDbK`s selected key to Question_Responses.ANSWER context attribute and you change the same attribute info. And with your code Question_Responses.ANSWER at the end will contain

Answer 1_1;

Answer 1_2;

Answer 1_3;

Answer 2_1;

Answer 2_2;

Answer 3_1;

Answer 3_2;

all of answers. And because you bind all your drop downs to the same context attribute, content of drop down will be the same.

Best regards, Maksim Rashchynski.

Former Member
0 Kudos

Yes. That is exactly was is happening and what I tried to communicate in my post. How do I correct it?

Thanks for the quick response.

/Greg

Former Member
0 Kudos

As I wrote earlier: forget about the DropDownByKey and use DropDownByIndex, but do not mix both binding models.

Armin