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.
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}
1import com.psddev.dari.util.PaginatedResult;2import content.article.Article;34public class MySummaryTab extends ProfilePanelTab {56@Override7public void writeHtml(ToolPageContext page) throws IOException, ServletException {89UUID uuid = page.getUser().getId();1011PaginatedResult<Article> articles = Query.from(Article.class)12.where("cms.content.publishUser = ?", uuid)13.sortDescending("cms.content.publishDate")14.select(0, 10);1516List<Article> myArticles = articles.getItems();1718page.writeStart("div",19"class", "p-tud-lg tabbed",20"data-tab", "My Articles");21page.writeStart("h1");22page.writeHtml("My Articles");23page.writeEnd();24page.writeStart("h2");25page.writeHtml("The following table lists your 10 most recently published articles.");26page.writeEnd();27page.writeStart("table");28page.writeStart("tr");29page.writeStart("th");30page.writeHtml("Headline");31page.writeEnd(); /* th */32page.writeStart("th");33page.writeHtml("Date Activity");34page.writeEnd(); /* th */35page.writeEnd(); /* tr */3637for (Article article : myArticles) {38page.writeStart("tr");39page.writeStart("td");40page.writeHtml(article.getHeadline());41page.writeEnd(); /* td */42page.writeStart("td");43page.writeHtml(article.getPublishDate());44page.writeEnd(); /* td */45page.writeEnd(); /* tr */46}4748page.writeEnd(); /* table */49page.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.writestatements write to this tab. - 37. Loops through the found articles and output the headline and date published for each.
See also: