[jboss-user] [JBoss Seam] - Re: DataModel and DataModelSelection question
w17chm4n
do-not-reply at jboss.com
Tue Oct 16 04:09:46 EDT 2007
I found the sollution.
| @Stateful
| @Scope(ScopeType.SESSION)
| @Name("QuestionCategoryController")
| public class QuestionCategoryControllerBean implements QuestionCategoryController {
|
| @Logger
| private Log log;
|
| @In(create = true)
| private QuestionCategoryManager questionCategoryManager;
|
| @DataModel
| private List<QuestionCategory> questionCategoryList;
|
| @DataModelSelection
| @In(required = false)
| private QuestionCategory questionCategory;
|
| public void addCategory() {
| questionCategoryManager.addCategory(questionCategory);
| getAllQuestionsCategories();
| }
|
| public void removeCategory() {
| questionCategoryList.remove(questionCategory);
| questionCategoryManager.removeCategory(questionCategory);
| questionCategory = null;
| getAllQuestionsCategories();
| }
|
| @Factory(value="questionCategoryList")
| public void getAllQuestionsCategories() {
| questionCategoryList = questionCategoryManager.getAllQuestionCategories();
| }
|
| @Remove @Destroy
| public void destroy() {}
|
| }
|
| @Stateful
| @Scope(ScopeType.APPLICATION)
| @Name("questionCategoryManager")
| public class QuestionCategoryManagerBean implements QuestionCategoryManager {
|
| @Logger
| Log log;
|
| @PersistenceContext(type = PersistenceContextType.EXTENDED)
| private EntityManager entityManager;
|
| public void addCategory(QuestionCategory category) {
| category.setCreated(new Date());
| entityManager.persist(category);
| }
|
| public void removeCategory(QuestionCategory category) {
| entityManager.remove(category);
| }
|
| public List<QuestionCategory> getAllQuestionCategories() {
| return entityManager.createQuery("from QuestionCategory qc").getResultList();
| }
|
| @Destroy @Remove
| public void destroy() {
| }
| }
|
| @Entity
| @Scope(ScopeType.EVENT)
| @Name("questionCategory")
| @Table(name="QuestionCategories")
| public class QuestionCategory implements Serializable {
|
| @Id @GeneratedValue
| private Long id;
|
| @NotNull @Length(min=3, max=100)
| private String categoryName;
|
| @OneToMany
| private List<Question> questionList;
|
| @Temporal(value = TemporalType.TIMESTAMP)
| private Date created;
|
| /** Creates a new instance of QuestionCategory */
| public QuestionCategory() {
| this.questionList = new ArrayList<Question>();
| }
|
| public QuestionCategory(String categoryName) {
| this.categoryName = categoryName;
| this.questionList = new ArrayList<Question>();
| }
|
| public Long getId() {
| return id;
| }
|
| public void setId(Long id) {
| this.id = id;
| }
|
| public String getCategoryName() {
| return categoryName;
| }
|
| public void setCategoryName(String categoryName) {
| this.categoryName = categoryName;
| }
|
| public List<Question> getQuestionList() {
| return questionList;
| }
|
| public void setQuestionList(List<Question> questionList) {
| this.questionList = questionList;
| }
|
| public Date getCreated() {
| return created;
| }
|
| public void setCreated(Date created) {
| this.created = created;
| }
| }
|
It was all about setting correct scopes ! Notice that entity bean has to have set Scope to event, without it, it won`t work.
Thx dhinojosa for all your support !
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4095508#4095508
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4095508
More information about the jboss-user
mailing list