/*
* Copyright 2009-2014 PrimeTek.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
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");
}
}
}