Displaying news feed

To displays the Chatter news feed for the current user, use the <Chatter:Newsfeed> tag.

The sample code is given as follows:

<apex:page >
<Chatter:Newsfeed />
</apex:page>

The preceding code will give you the current user's news feed. To make it dynamic in nature as with the preceding code, use the controller class with the Visualforce Page. By using the following code, you will make the page behavior dynamic; once you select the user name in the dropdown, it will show the news feed according to that.

The code for the Visualforce Page is given as follows:

<apex:outputPanel id="feed">
  <apex:dataList value="{!newsfeeds}" var="Nf">
    <apex:outputText value="{!Nf.body}"></apex:outputText>
  </apex:dataList>
</apex:outputPanel>

We have taken an output panel with the id attribute, the data list that is bound with the newsfeeds list, and the variable Nf. The following screenshot is the output that shows the body of the newsfeed:

Displaying news feed

The controller code is given as follows:

public List
<feedItem>
  getNewsfeeds() 
  {
  newsfeeds= [SELECT Type, CreatedDate, CreatedBy.name, Body FROM FeedItem WHERE ParentId=:uid and type='TEXTPOST' ORDER BY CreatedDate DESC LIMIT 10];
  return newsfeeds;
  }

News feeds are stored in the feeditem object. The preceding code will give you the news feed, extract those posts whose type equals TEXTPOST, and once you get the required list, pass it to DataList in the Visualforce page for printing.

Displaying feed with followers

To display a news feed with followers, you can use the <chatter:feedWithFollowers> tag.

The sample code is given as follows:

<apex:page >
<chatter:feedWithFollowers entityId="00590000001qt4z"/> 
</apex:page>

Here, the entity is nothing but the ID of the record user for which you want to display the feed. The preceding code will give you the news feed with a list of followers for the ID used in the code.

To make the preceding code dynamic as in the following screenshot, select the user name from the Select user dropdown, and it will dynamically change the feed with the follower:

Displaying feed with followers

The following is the code for the Visualforce page:

<apex:outputPanel id="feed">
  <chatter:feedWithFollowers entityId="{!uid}"/>
</apex:outputPanel>
<apex:actionStatus id="loadStatus" startText="Loading..." />

We have taken an output panel with the id attribute to show the output. This has the Chatter component, <chatter:feedWithFollowers>. This component takes the argument entity ID, which is the user ID.

The controller code is given as follows:

public PageReference followchange() 
{

  uid=uName;
  return null;
}

On changing the user, the pageReference method, which is the followChange method, is always called. It assigns the current userid of the selected user to uid. The uid ID is bound on the page with the <chatter:feedWithFollowers> Chatter component that shows the output. On the Visualforce page, the output panel is used to display the output.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.226.24