blob: 005b3996f10bbfb56f205c4ba99d71d45adc7573 (
plain)
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
|
/*
* $RCSFile$
*
* Created on 08.03.2007
* for Project:
* by steins
*
* (C) 2005-2006 by
*/
package beans;
import java.io.IOException;
import java.util.Collection;
import java.util.Map;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import jpa.Category;
import jpa.EntityManagerFactorySingleton;
@ManagedBean(name = "CategoryManager")
@SessionScoped
public class CategoryManager
{
private Category current;
public Category getCurrent()
{
return current;
}
public void setCurrent(Category current)
{
this.current = current;
}
public Collection getCategories()
{
EntityManager manager = EntityManagerFactorySingleton.getInstance()
.getEntityManagerFactory().createEntityManager();
Collection categories = manager.createQuery("SELECT c FROM Category c ")
.getResultList();
manager.close();
return categories;
}
public void select(javax.faces.event.ActionEvent actionEvent)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
Map params = facesContext.getExternalContext().getRequestParameterMap();
Integer selectedId = Integer.valueOf((String) params.get("selectedId"));
// System.out.println(selectedId);
EntityManager manager = EntityManagerFactorySingleton.getInstance()
.getEntityManagerFactory().createEntityManager();
EntityTransaction tx = manager.getTransaction();
tx.begin();
try
{
current = manager.find(Category.class, selectedId);
// System.out.println(current.getName());
tx.commit();
}
catch (Exception ex)
{
ex.printStackTrace(System.err);
tx.rollback();
}
FacesContext context = FacesContext.getCurrentInstance();
try
{
context.getExternalContext().redirect("products.jsf");
}
catch (IOException e)
{
e.printStackTrace();
}
context.responseComplete();
manager.close();
}
}
|