cancel
Showing results for 
Search instead for 
Did you mean: 

problem by creating a dynamic tree

Former Member
0 Kudos

Hello all,

i am new to webDynpro!

I wanna create a dynamic tree. In my application there are 2 views in a ViewSet. One view "Tree"for tree, another view "Question" contains a inputfield for typing a question.

Componentcontroller includes a value node "QuestionNode", in"QuestionNode" there are a value attribute "text." Then mapping the Componnentcontrller to the both views"Tree".

When i types a question in "question" view and Enter, then automatic insert a node in "tree"View.

this tree has only parent node ,no child. text of node is the value attribute"text" . The text ,which i have typed in inputfield in "Question" view, is displayed in the tree.

plx give me some code and tips.

Thx in advance

regards

Yaning

Message was edited by:

Yaning Liu

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Why do you want to use a tree here? I cannot see any hierarchy.

Armin

Former Member
0 Kudos

now there are not any hierachy , nur a example, but the hierachy come later. i need a tree here. in future i will insert subquestion ,which is child of main question.

Former Member
0 Kudos

"nur a example"

Ok, so you perhaps need a recursive tree structure like

Context:
- QuestionText (attribute, string)
- Questions (node)
--- Text (attribute, string)
--- SubQuestions (recursive node, RepeatedNode = Questions)

View Layout:
InputField.value = QuestionText
InputField.onEnter = AddQuestion
Tree.dataSource = Questions
TreeNodeType.dataSource = Questions
TreeNodeType.text = Questions.Text

Action "AddQuestion":

Implement the action handler like

    try
    {
      IQuestionsElement selectedQuestion = (IQuestionsElement) wdContext.nodeQuestions().getTreeSelection();
      IQuestionsElement newQuestion;
      if (selectedQuestion == null)
      {
        newQuestion = wdContext.nodeQuestions().createAndAddQuestionsElement();
      }
      else
      {
        newQuestion = selectedQuestion.nodeSubQuestions().createAndAddQuestionsElement();
      }
      newQuestion.setText(wdContext.currentContextElement().getQuestionText());
    }
    catch (WDContextException e)
    {
      wdComponentAPI.getMessageManager().reportException(e.getMessage());
    }

This will add a new question node under the currently selected node or under the root if no node is selected.

Armin

Former Member
0 Kudos

Thx ammin

Former Member
0 Kudos

Hello Armin,

another problem comes. can you give me some advices?

Now i have three views : "Question" ,"Tree" , "SubQuestion"

all controllers are already mapped.

Context: for ComponentController and 3 ViewController

- Question (node)

-


Text (attribute, string)

-


SubQuestion (recursive node, RepeatedNode = Question)

Question (Node)

--cardinality 0..n

--collectionType list

--initializeLeadSelection true

--selection 0..1

--singleton true

--typedAccessRequired true

"Question" View Layout:

Button.OnAction = ToSubQuestion ---(jump to "SubQuestion" View for choosing the parent, i.e )

InputField.value = QuestionText

"SubQuestion" View Layout: (This view contains a table with a column "Question.Text". all questions stand in this table. i will select a question als parent)

--- Table.dataSource = Question

--- Table.onLeadSelect = Select ( back to "QuestionView" and i hope, the current element is the new created subQuestion)

--- one Column

-


TableCellEditor.Text = Question.Text

"Tree" View LayOut

--- Tree.dataSource = Question

--- TreeNodeType.dataSource = Question

--- TreeNodeType.text = Question.Text

Action "Select":

  public void onActionSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent,
com.sap.tut.wd.test1.wdp.IPrivateSubQuestionView.IQuestionElement selectedElement )
  {
    //@@begin onActionSelect(ServerEvent)
    
		
	IPrivateSubQuestionView.IQuestionNode subQuestionNode = wdContext.currentQuestionElement().nodeSubQuestion();
	IPrivateSubQuestionView.IQuestionElement subQuestion;
	subQuestion = subQuestionNode.createQuestionElement();
	
	subQuestionNode.addElement(subQuestion);

	subQuestionNode.setTreeSelection(subQuestion);

	wdThis.wdFirePlugBackQuestionOut();
    //@@end
  }

The Problem :

when i select a question als parent, jump back to "Question"View. I hope ,the current NodeElement is kind (SubQuestion), but in fact parent .

i don't Know, how set the LeadSelection or TreeSelection of recursive Node (Non-Singleton child node).

i think ,the problem is

subQuestionNode.setTreeSelection(subQuestion);

i can't set the recursive node element als current element.

can you give me some code.

Thx in Adcance.

regards

Yaning

Former Member
0 Kudos

HI Yaning Liu ,

What do you want to diplay in the tree.

With Regards

Naidu

Former Member
0 Kudos

display the text in tree , which i have typed in inputfield in "Question" View.