blob: 4910fffbb6e507f2c2236b9ff06d0e99e82d80b3 (
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
|
/*
* $RCSFile$
*
* Created on 11.06.2007
* for Project:
* by steins
*
* (C) 2005-2006 by
*/
package beans;
import java.io.IOException;
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.EntityManagerFactorySingleton;
import jpa.Product;
@ManagedBean(name = "ProductManager")
@SessionScoped
public class ProductManager
{
private Product current;
public Product getCurrent()
{
return current;
}
public void select(javax.faces.event.ActionEvent actionEvent)
{
FacesContext facesContext = FacesContext.getCurrentInstance();
Map params = facesContext.getExternalContext().getRequestParameterMap();
int selectedId = Integer.valueOf((String) params.get("selectedId"), 10);
// System.out.println(selectedId);
EntityManager manager = EntityManagerFactorySingleton.getInstance()
.getEntityManagerFactory().createEntityManager();
EntityTransaction tx = manager.getTransaction();
tx.begin();
try
{
current = manager.find(Product.class, selectedId);
tx.commit();
}
catch (Exception ex)
{
ex.printStackTrace(System.err);
tx.rollback();
}
FacesContext context = FacesContext.getCurrentInstance();
try
{
context.getExternalContext().redirect("product.jsf");
}
catch (IOException e)
{
e.printStackTrace();
}
context.responseComplete();
manager.close();
}
}
|