1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.portals.applications.desktop.calendar;
18
19 import java.text.SimpleDateFormat;
20 import java.util.Date;
21 import java.util.Locale;
22
23 import javax.faces.context.FacesContext;
24 import javax.portlet.PortletPreferences;
25 import javax.portlet.PortletRequest;
26
27 /***
28 * CalendarBean
29 *
30 * @author <a href="mailto:taylor@apache.org">David Sean Taylor </a>
31 * @version $Id: CalendarBean.java 517068 2007-03-12 01:44:37Z ate $
32 */
33
34 public class CalendarBean
35 {
36 private Date date = new Date();
37 private String notes = "";
38
39 public Date getDate()
40 {
41 return date;
42 }
43
44 public void setDate(Date date)
45 {
46 if (date != null)
47 {
48 this.date = date;
49 }
50 }
51
52 public String getNotes()
53 {
54 return notes;
55 }
56
57 public void setNotes(String notes)
58 {
59 this.notes = notes;
60 }
61
62 public String getDateKey(Date date)
63 {
64 SimpleDateFormat formatter = new SimpleDateFormat ("yyyy-MM-dd", Locale.getDefault());
65 return formatter.format(date);
66
67 }
68
69
70
71
72 public String save()
73 {
74 if (this.date != null)
75 {
76 PortletRequest request = (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
77 PortletPreferences prefs = request.getPreferences();
78 try
79 {
80
81 prefs.setValue(getDateKey(this.date), this.notes);
82 prefs.store();
83 }
84 catch (Exception e)
85 {
86 System.err.println("error storing prefs " + e);
87 }
88 }
89 return "returnFromNotes";
90 }
91
92 public String selectDate()
93 {
94 if (this.date == null)
95 {
96 return "editNotes";
97 }
98 String selectedDate = getDateKey(this.date);
99 PortletRequest request = (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
100 notes = request.getPreferences().getValue(selectedDate, "");
101 return "editNotes";
102 }
103 }