+ Start a Discussion
Vetriselvan ManoharanVetriselvan Manoharan 

Binding values in tree view

Hi, Guys.

I need to bind values in tree view based on field in the same object. For eg: I have article object which has a field called special notes. Now the special notes should be the parent in the tree and article should be child. I tried something.

public List<Article__c> articles {get; set;}
    public Map<String, Article__c> articlesMap {get; set;}
    public Hydra_MarshTreeViewController (){
        articles = [ SELECT Id, Name, SpecialisedNotes__c from Article__c ];
        System.debug('Hi' + articles);
        articlesMap = new Map<String, Article__C>();
        for(Article__c article : articles)
        {
            articlesMap.put(article.SpecialisedNotes__c, article);
        }
        System.debug('ArticleMap' +articlesMap);
    }

Here is My VF page:

<apex:repeat value="{!articlesMap}" var="arc">
            <li class="closed"><span class="folder">{!arc}</span>
            <ul>
                <apex:repeat value="{!articlesMap[arc]}" var="c">
                <li><span class="file"><a href="Article?id={!articlesMap[arc]}" target="_blank">{!articlesMap[arc]}</a></span></li>
                </apex:repeat>
            </ul>
        </li>
        </apex:repeat>

Please help me
Best Answer chosen by Vetriselvan Manoharan
Nitin PaliwalNitin Paliwal
Hi,
Use this Controller method and vf page.

Controller,

public List<Article__c> articles {get; set;}
public Map<String, list<Article__c>> articlesMap {get; set;}
    public Hydra_MarshTreeViewController (){
        articles = [ SELECT Id, Name, SpecialisedNotes__c from Article__c ];
        System.debug('Hi' + articles);
        articlesMap = new Map<String, list<Article__C>>();
        for(Article__c article : articles)
        {
   if(!articlesMap.containsKey(article.SpecialisedNotes__c))
    articlesMap.put(article.SpecialisedNotes__c, new list<Article__c>());
            articlesMap.get(article.SpecialisedNotes__c).add(article);
        }
        System.debug('ArticleMap' +articlesMap);
    }

VF Page

<ul>
 <apex:repeat value="{!articlesMap}" var="arc">
  <li class="closed"><span class="folder">{!arc}</span>
   <ul>
  <Apex:repeat value="{!articlesMap[arc]}" var="article">
   <li><span class="file"><a href="Article?id={article.Id}" target="_blank">{!article.Name}</a></span></li>
  </apex:repeat>
   </ul>
  </li>
 </apex:repeat>
</ul>


Thanks
Nitin

All Answers

Nitin PaliwalNitin Paliwal
HI,
Please try this vf page code

<ul>
 <apex:repeat value="{!articlesMap}" var="arc">
  <li class="closed"><span class="folder">{!arc}</span>
   <ul>
    <li><span class="file"><a href="Article?id={!articlesMap[arc]}" target="_blank">{!articlesMap[arc]}</a></span></li>
   </ul>
  </li>
 </apex:repeat>
</ul>

Thanks
Nitin
Vetriselvan ManoharanVetriselvan Manoharan
Hi Nitin,

Nope it doesn't work. The child may have more than one article. So it should display all the article based on Special notes(Parent) field in article. Also I need the article name in the child. But now it is displaying only Id. 

Thanks,
Vetri
Nitin PaliwalNitin Paliwal
Hi,
Use this Controller method and vf page.

Controller,

public List<Article__c> articles {get; set;}
public Map<String, list<Article__c>> articlesMap {get; set;}
    public Hydra_MarshTreeViewController (){
        articles = [ SELECT Id, Name, SpecialisedNotes__c from Article__c ];
        System.debug('Hi' + articles);
        articlesMap = new Map<String, list<Article__C>>();
        for(Article__c article : articles)
        {
   if(!articlesMap.containsKey(article.SpecialisedNotes__c))
    articlesMap.put(article.SpecialisedNotes__c, new list<Article__c>());
            articlesMap.get(article.SpecialisedNotes__c).add(article);
        }
        System.debug('ArticleMap' +articlesMap);
    }

VF Page

<ul>
 <apex:repeat value="{!articlesMap}" var="arc">
  <li class="closed"><span class="folder">{!arc}</span>
   <ul>
  <Apex:repeat value="{!articlesMap[arc]}" var="article">
   <li><span class="file"><a href="Article?id={article.Id}" target="_blank">{!article.Name}</a></span></li>
  </apex:repeat>
   </ul>
  </li>
 </apex:repeat>
</ul>


Thanks
Nitin
This was selected as the best answer
Vetriselvan ManoharanVetriselvan Manoharan
Hi Nitin,

Thanks. But still the child is not looping it.. Any ideas?

Vetri
Nitin PaliwalNitin Paliwal
Can you paste the code which you have applied, and did you happen to see the debug logs for the article map?
And what it is printing right now?

Thanks
Nitin
Vetriselvan ManoharanVetriselvan Manoharan
Hi Nitin,

This is how I done it nitin. Added an else part worked.

            else
            {
                articlesMap.get(article.SpecialisedNotes__c).add(article);
            }

Thanks,
Vetri