|
1 | 1 | package com.ocpsoft.rewrite.showcase.view; |
2 | | -import java.util.List; |
| 2 | + |
3 | 3 | import java.util.ArrayList; |
| 4 | +import java.util.List; |
| 5 | + |
4 | 6 | import javax.ejb.Stateful; |
5 | 7 | import javax.enterprise.context.RequestScoped; |
6 | 8 | import javax.inject.Named; |
| 9 | + |
| 10 | +import org.jboss.forge.scaffold.metawidget.persistence.PaginationHelper; |
| 11 | +import org.jboss.forge.scaffold.metawidget.persistence.PersistenceUtil; |
| 12 | + |
7 | 13 | import com.ocpsoft.rewrite.showcase.domain.DomainEntity; |
8 | | -import org.metawidget.forge.persistence.PaginationHelper; |
9 | | -import org.metawidget.forge.persistence.PersistenceUtil; |
10 | | -import org.jboss.seam.transaction.Transactional; |
11 | | -@Transactional @Named @Stateful @RequestScoped public class DomainBean extends PersistenceUtil { |
12 | | - private static final long serialVersionUID=1L; |
13 | | - private List<DomainEntity> list=null; |
14 | | - private DomainEntity domain=new DomainEntity(); |
15 | | - private long id=0; |
16 | | - private PaginationHelper<DomainEntity> pagination; |
17 | | - public void load(){ |
18 | | - domain=findById(DomainEntity.class,id); |
19 | | - } |
20 | | - public String create(){ |
21 | | - create(domain); |
22 | | - return "view?faces-redirect=true&id=" + domain.getId(); |
23 | | - } |
24 | | - public String delete(){ |
25 | | - delete(domain); |
26 | | - return "list?faces-redirect=true"; |
27 | | - } |
28 | | - public String save(){ |
29 | | - save(domain); |
30 | | - return "view?faces-redirect=true&id=" + domain.getId(); |
31 | | - } |
32 | | - public long getId(){ |
33 | | - return id; |
34 | | - } |
35 | | - public void setId( long id){ |
36 | | - this.id=id; |
37 | | - if (id > 0) { |
38 | | - load(); |
39 | | - } |
40 | | - } |
41 | | - public DomainEntity getDomain(){ |
42 | | - return domain; |
43 | | - } |
44 | | - public void setDomain( DomainEntity domain){ |
45 | | - this.domain=domain; |
46 | | - } |
47 | | - public List<DomainEntity> getList(){ |
48 | | - if (list == null) { |
49 | | - list=getPagination().createPageDataModel(); |
50 | | - } |
51 | | - return list; |
52 | | - } |
53 | | - public void setList( List<DomainEntity> list){ |
54 | | - this.list=list; |
55 | | - } |
56 | | - public PaginationHelper<DomainEntity> getPagination(){ |
57 | | - if (pagination == null) { |
58 | | - pagination=new PaginationHelper<DomainEntity>(10){ |
59 | | - @Override public int getItemsCount(){ |
60 | | - return count(DomainEntity.class); |
61 | | - } |
62 | | - @Override public List<DomainEntity> createPageDataModel(){ |
63 | | - return new ArrayList<DomainEntity>(findAll(DomainEntity.class,getPageFirstItem(),getPageSize())); |
64 | | - } |
| 14 | + |
| 15 | +@Named |
| 16 | +@Stateful |
| 17 | +@RequestScoped |
| 18 | +public class DomainBean extends PersistenceUtil |
| 19 | +{ |
| 20 | + private static final long serialVersionUID = 1L; |
| 21 | + private List<DomainEntity> list = null; |
| 22 | + private DomainEntity domain = new DomainEntity(); |
| 23 | + private long id = 0; |
| 24 | + private PaginationHelper<DomainEntity> pagination; |
| 25 | + |
| 26 | + public void load() |
| 27 | + { |
| 28 | + domain = findById(DomainEntity.class, id); |
| 29 | + } |
| 30 | + |
| 31 | + public String create() |
| 32 | + { |
| 33 | + create(domain); |
| 34 | + return "view?faces-redirect=true&id=" + domain.getId(); |
| 35 | + } |
| 36 | + |
| 37 | + public String delete() |
| 38 | + { |
| 39 | + delete(domain); |
| 40 | + return "list?faces-redirect=true"; |
| 41 | + } |
| 42 | + |
| 43 | + public String save() |
| 44 | + { |
| 45 | + save(domain); |
| 46 | + return "view?faces-redirect=true&id=" + domain.getId(); |
| 47 | + } |
| 48 | + |
| 49 | + public long getId() |
| 50 | + { |
| 51 | + return id; |
| 52 | + } |
| 53 | + |
| 54 | + public void setId(final long id) |
| 55 | + { |
| 56 | + this.id = id; |
| 57 | + if (id > 0) { |
| 58 | + load(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + public DomainEntity getDomain() |
| 63 | + { |
| 64 | + return domain; |
| 65 | + } |
| 66 | + |
| 67 | + public void setDomain(final DomainEntity domain) |
| 68 | + { |
| 69 | + this.domain = domain; |
| 70 | + } |
| 71 | + |
| 72 | + public List<DomainEntity> getList() |
| 73 | + { |
| 74 | + if (list == null) { |
| 75 | + list = getPagination().createPageDataModel(); |
| 76 | + } |
| 77 | + return list; |
| 78 | + } |
| 79 | + |
| 80 | + public void setList(final List<DomainEntity> list) |
| 81 | + { |
| 82 | + this.list = list; |
| 83 | + } |
| 84 | + |
| 85 | + public PaginationHelper<DomainEntity> getPagination() |
| 86 | + { |
| 87 | + if (pagination == null) { |
| 88 | + pagination = new PaginationHelper<DomainEntity>(10) { |
| 89 | + @Override |
| 90 | + public int getItemsCount() |
| 91 | + { |
| 92 | + return count(DomainEntity.class); |
| 93 | + } |
| 94 | + |
| 95 | + @Override |
| 96 | + public List<DomainEntity> createPageDataModel() |
| 97 | + { |
| 98 | + return new ArrayList<DomainEntity>(findAll(DomainEntity.class, getPageFirstItem(), getPageSize())); |
| 99 | + } |
| 100 | + }; |
65 | 101 | } |
66 | | -; |
67 | | - } |
68 | | - return pagination; |
69 | | - } |
| 102 | + return pagination; |
| 103 | + } |
70 | 104 | } |
0 commit comments