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