java [ReactiveBean] JavaServer Faces with rxJava。 #rxjava
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java [ReactiveBean] JavaServer Faces with rxJava。 #rxjava相关的知识,希望对你有一定的参考价值。
package com.reactive;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import rx.Observable;
import rx.Subscriber;
@Named
@RequestScoped
public class ReactiveBean implements Serializable {
private Question question;
private String answer;
public void doReactive() {
myObservable.subscribe(mySubscriber);
}
public ReactiveBean() {
question = new Question();
}
public List<Question> getQuestionList() {
List<Question> list = new ArrayList<>();
Question q1 = new Question();
q1.setId(1L);
q1.setQuestion("What is the best development IDE?");
list.add(q1);
Question q2 = new Question();
q2.setId(2L);
q2.setQuestion("What is the best programming language?");
list.add(q2);
Question q3 = new Question();
q3.setId(3L);
q3.setQuestion("What is the best country in the World?");
list.add(q3);
return list;
}
@SuppressWarnings("deprecation")
Observable<String> myObservable = Observable.create(
new Observable.OnSubscribe<String>() {
@Override
public void call(Subscriber<? super String> sub) {
if (question.getId().equals(1L)) {
sub.onNext("NetBeans");
sub.onCompleted();
}
if (question.getId().equals(2L)) {
sub.onNext("Java");
sub.onCompleted();
}
if (question.getId().equals(3L)) {
sub.onNext("Armenia");
sub.onCompleted();
}
}
}
);
private final Subscriber<String> mySubscriber = new Subscriber<String>() {
@Override
public void onNext(String s) {
answer = s;
System.out.println("Subscriber " + s);
}
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
}
};
//////////////////////////////////////////////
public static void hello(String... names) {
Observable.from(names).subscribe((String s) -> {
System.out.println("Hello " + s + "!");
});
}
public String getAnswer() {
return answer;
}
public void setAnswer(String answer) {
this.answer = answer;
}
public Question getQuestion() {
return question;
}
public void setQuestion(Question question) {
this.question = question;
}
}
以上是关于java [ReactiveBean] JavaServer Faces with rxJava。 #rxjava的主要内容,如果未能解决你的问题,请参考以下文章
JavaS:网页中的显示和隐藏
javas入门04——数组的创建及方法
概念简介Javas cript简介
语法基础Javas cript变量的声明和使用
Javas Audio Clips 在频繁播放哔声时出现问题
javas cript入门要了解的知识和书籍