Skip to main content

Profile tabs

The header contains a link to display the current user’s profile in a widget. The default implementation displays two tabs in the widget: Profile and History.

Default profile tabs

You can add custom tabs to the profile widget by extending the ProfilePanelTab class. The following example creates a My Articles profile tab that lists the current user’s 10 most recently published articles.

showLineNumbers {4,7,11,18,37}
1
import com.psddev.dari.util.PaginatedResult;
2
import content.article.Article;
3
4
public class MySummaryTab extends ProfilePanelTab {
5
6
@Override
7
public void writeHtml(ToolPageContext page) throws IOException, ServletException {
8
9
UUID uuid = page.getUser().getId();
10
11
PaginatedResult<Article> articles = Query.from(Article.class)
12
.where("cms.content.publishUser = ?", uuid)
13
.sortDescending("cms.content.publishDate")
14
.select(0, 10);
15
16
List<Article> myArticles = articles.getItems();
17
18
page.writeStart("div",
19
"class", "p-tud-lg tabbed",
20
"data-tab", "My Articles");
21
page.writeStart("h1");
22
page.writeHtml("My Articles");
23
page.writeEnd();
24
page.writeStart("h2");
25
page.writeHtml("The following table lists your 10 most recently published articles.");
26
page.writeEnd();
27
page.writeStart("table");
28
page.writeStart("tr");
29
page.writeStart("th");
30
page.writeHtml("Headline");
31
page.writeEnd(); /* th */
32
page.writeStart("th");
33
page.writeHtml("Date Activity");
34
page.writeEnd(); /* th */
35
page.writeEnd(); /* tr */
36
37
for (Article article : myArticles) {
38
page.writeStart("tr");
39
page.writeStart("td");
40
page.writeHtml(article.getHeadline());
41
page.writeEnd(); /* td */
42
page.writeStart("td");
43
page.writeHtml(article.getPublishDate());
44
page.writeEnd(); /* td */
45
page.writeEnd(); /* tr */
46
}
47
48
page.writeEnd(); /* table */
49
page.writeEnd(); /* div */
50
}
51
}
  • 4. Declares a class that extends from ProfilePanelTab—the class that outputs to a custom profile widget.
  • 7. Overrides the method writeHtml, which directs output to the custom tab.
  • 11. Retrieves the current user’s 10 most recently published articles.
  • 18. Creates the new tab with the label My Articles. Any nested page.write statements write to this tab.
  • 37. Loops through the found articles and output the headline and date published for each.

Custom profile tab

See also: