News
Source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | <! DOCTYPE html> < f:view renderKitId = "PRIMEFACES_MOBILE" /> < h:head > < link type = "text/css" rel = "stylesheet" href = "#{request.contextPath}/css/syntaxhighlighter/syntaxhighlighter.css" /> </ h:head > < h:body > < pm:page id = "main" > < pm:header title = "News" swatch = "b" ></ pm:header > < pm:content > < h:form id = "mainForm" > < p:growl id = "messages" showDetail = "true" /> < p:dataList var = "group" value = "#{newsView.groups}" > < p:commandLink value = "#{group.title}" action = "pm:group?transition=slide" update = ":group:groupTitle :group:groupForm:entries" > < f:setPropertyActionListener value = "#{group}" target = "#{newsView.selectedGroup}" /> </ p:commandLink > </ p:dataList > </ h:form > </ pm:content > < pm:footer title = "Feeds from Reuters" /> </ pm:page > < pm:page id = "group" > < pm:header swatch = "b" > < p:button styleClass = "ui-toolbar-header-button-left ui-button-inline" value = "Back" icon = "ui-icon-arrow-l" outcome = "pm:main?transition=slide&reverse=true" /> < h1 >< h:outputText id = "groupTitle" value = "#{newsView.selectedGroup.title}" /></ h1 > </ pm:header > < pm:content > < h:form id = "groupForm" > < p:dataList id = "entries" var = "newsEntry" value = "#{newsView.selectedGroup.entries}" > < p:commandLink value = "#{newsEntry.title}" action = "pm:entry?transition=slide" update = ":entry:entryDetail" > < f:setPropertyActionListener value = "#{newsEntry}" target = "#{newsView.selectedEntry}" /> </ p:commandLink > </ p:dataList > </ h:form > </ pm:content > </ pm:page > < pm:page id = "entry" > < pm:header title = "Detail" swatch = "b" > < p:button styleClass = "ui-toolbar-header-button-left ui-button-inline" value = "Back" icon = "ui-icon-arrow-l" outcome = "pm:group?transition=slide&reverse=true" /> </ pm:header > < pm:content > < h:outputText id = "entryDetail" value = "#{newsView.selectedEntry.content}" escape = "false" /> </ pm:content > </ pm:page > < script language = "javascript" src = "#{request.contextPath}/syntaxhighlighter/scripts/sh.js" ></ script > < script language = "javascript" > SyntaxHighlighter.all(); </ script > </ h:body > </ html > |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | package org.primefaces.showcase.mobile; import com.sun.syndication.feed.synd.SyndEntry; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.XmlReader; import java.io.Serializable; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.PostConstruct; import javax.faces.application.FacesMessage; import javax.faces.bean.ApplicationScoped; import javax.faces.bean.ManagedBean; import javax.faces.context.FacesContext; import org.primefaces.showcase.domain.NewsEntry; import org.primefaces.showcase.domain.NewsGroup; @ManagedBean @ApplicationScoped public class NewsView implements Serializable { private List<NewsGroup> groups; private NewsEntry selectedEntry; private NewsGroup selectedGroup; private Map<String,String> feeds; @PostConstruct public void init() { feeds = new HashMap<String, String>(); groups = fetchNews(); } public List<NewsGroup> getGroups() { return groups; } public NewsEntry getSelectedEntry() { return selectedEntry; } public void setSelectedEntry(NewsEntry selectedEntry) { this .selectedEntry = selectedEntry; } public NewsGroup getSelectedGroup() { return selectedGroup; } public void setSelectedGroup(NewsGroup selectedGroup) { this .selectedGroup = selectedGroup; } public List<NewsGroup> fetchNews() { List<NewsGroup> news = new ArrayList<NewsGroup>(); try { for (String key : feeds.keySet()) { URL feedSource = new URL(feeds.get(key)); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build( new XmlReader(feedSource)); List<NewsEntry> entries = new ArrayList<NewsEntry>(); int i = 0 ; for (Object f : feed.getEntries()) { SyndEntry entry = (SyndEntry) f; String title = entry.getTitle(); title = title.length() <= 25 ? title : title.substring( 0 , 25 ); entries.add( new NewsEntry(i, title + "..." , entry.getDescription().getValue())); i++; } news.add( new NewsGroup(key, entries)); } } catch (Exception exception) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error" , "Please try again" ); FacesContext.getCurrentInstance().addMessage( null , msg); } return news; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | package org.primefaces.examples.domain; import java.io.Serializable; import java.util.List; public class NewsGroup implements Serializable { private String title; private List<NewsEntry> entries; public NewsGroup() { } public NewsGroup(String title, List<NewsEntry> entries) { this .title = title; this .entries = entries; } public String getTitle() { return title; } public void setTitle(String title) { this .title = title; } public List<NewsEntry> getEntries() { return entries; } public void setEntries(List<NewsEntry> entries) { this .entries = entries; } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | package org.primefaces.examples.domain; import java.io.Serializable; public class NewsEntry implements Serializable { private String title; private String content; private int index; public NewsEntry() { } public NewsEntry( int index, String title, String content) { this .index = index; this .content = content; this .title = title; } public String getTitle() { return title; } public void setTitle(String title) { this .title = title; } public String getContent() { return content; } public void setContent(String content) { this .content = content; } public int getIndex() { return index; } public void setIndex( int index) { this .index = index; } } |