-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWidgetBean.java
More file actions
95 lines (80 loc) · 2.08 KB
/
WidgetBean.java
File metadata and controls
95 lines (80 loc) · 2.08 KB
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
92
93
94
95
package org.javaee7.chapter07;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.inject.Instance;
import javax.faces.bean.ManagedBean;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.Produces;
import org.javaee7.beans.WidgetOne;
import org.javaee7.beans.WidgetTwo;
import org.javaee7.beans.WidgetX;
import org.javaee7.interfaces.Widget;
import org.javaee7.jsf.AcmeBean;
/**
*
* @author Juneau
*/
@ManagedBean(name="widgetBean")
public class WidgetBean implements java.io.Serializable {
@Inject
OrderProcessor processor;
private List<Widget> widgets;
private String widgetType = Widget.GENERIC;
private Widget selectedWidget;
// Programmatic Lookup of Acmebean
@Inject Instance<AcmeBean> acmeBean;
public WidgetBean() {
widgets = new ArrayList();
widgets.add(new WidgetOne());
widgets.add(new WidgetTwo());
}
@Produces
public Widget getWidget() {
switch (widgetType) {
case Widget.PLASTIC:
return new WidgetOne();
case Widget.METAL:
return new WidgetTwo();
default:
return new WidgetX();
}
}
/**
* @return the widgetType
*/
public String getWidgetType() {
return widgetType;
}
/**
* @param widgetType the widgetType to set
*/
public void setWidgetType(String widgetType) {
this.widgetType = widgetType;
}
/**
* @return the widget
*/
public Widget getSelectedWidget() {
selectedWidget = getWidget();
return selectedWidget;
}
/**
* @param widget the widget to set
*/
public void setSelectedWidget(Widget widget) {
this.selectedWidget = widget;
}
public String getAcmeBean(){
AcmeBean bean = acmeBean.get();
return bean.getMsg();
}
public String getOrderProcessor(){
return processor.getBeanName();
}
@Produces
@Named
public List<Widget> getWidgets(){
return widgets;
}
}