Source
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" xmlns:pm="http://primefaces.org/mobile"> <f:view renderKitId="PRIMEFACES_MOBILE" /> <h:head> </h:head> <h:body> <pm:page id="first"> <pm:header title="Twitter" theme="b"></pm:header> <pm:content> <h:form id="main"> <p:growl id="messages" showDetail="true" /> <h2>See what’s happening right now.</h2> <p:inputText id="search" value="#{twitterView.keyword}" type="search" placeholder="Search"/> <p:commandButton value="Search" icon="search" actionListener="#{twitterView.search}" update="tweets search"/> <p:dataList id="tweets" value="#{twitterView.tweets}" var="tweet" styleClass="ui-listview-inset ui-corner-all"> <p:graphicImage value="#{tweet.user.biggerProfileImageURL}" /> <h2>#{tweet.user.screenName}</h2> <p>#{tweet.text}</p> <p class="ui-li-aside">Retweets: <strong>#{tweet.retweetCount}</strong></p> </p:dataList> </h:form> </pm:content> </pm:page> </h:body> </html>
package org.primefaces.showcase.mobile; import java.util.List; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.context.FacesContext; import org.primefaces.context.RequestContext; import twitter4j.Query; import twitter4j.Status; import twitter4j.Twitter; import twitter4j.TwitterException; import twitter4j.TwitterFactory; @ManagedBean public class TwitterView { private String keyword; private List<Status> tweets; public String getKeyword() { return keyword; } public void setKeyword(String keyword) { this.keyword = keyword; } public List<Status> getTweets() { return tweets; } public void setTweets(List<Status> tweets) { this.tweets = tweets; } public void search() { try { Twitter twitter = TwitterFactory.getSingleton(); Query query = new Query(keyword); tweets = twitter.search(query).getTweets(); } catch(TwitterException exception) { FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Please try again"); FacesContext.getCurrentInstance().addMessage(null, msg); RequestContext.getCurrentInstance().update("main:messages"); } } }