KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > forum > component > UICategoryForm


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.communication.forum.component;
6
7 import org.exoplatform.faces.core.component.UIForm;
8 import org.exoplatform.faces.core.event.ExoActionEvent;
9 import org.exoplatform.faces.core.event.ExoActionListener;
10 import org.exoplatform.faces.core.validator.EmptyFieldValidator;
11 import org.exoplatform.services.communication.forum.Category;
12 import org.exoplatform.services.communication.forum.ForumService;
13
14 /**
15  * Sat, Jan 03, 2004 @ 11:16
16  * @author: Tuan Nguyen
17  * @email: tuan08@users.sourceforge.net
18  * @version: $Id: UICategoryForm.java,v 1.7 2004/10/17 13:46:25 tuan08 Exp $
19  */

20 public class UICategoryForm extends UIForm {
21   private static String JavaDoc CATEGORY_NAME = "categoryName" , CATEGORY_DESC = "categoryDesc" ,
22                         CATEGORY_ORDER = "order";
23   
24   private ForumService service_ ;
25   private Category category_ ;
26   
27   public UICategoryForm(ForumService service) throws Exception JavaDoc {
28     super("category") ;
29     setId("UICategoryForm") ;
30     service_ = service ;
31     addContainer("#{UICategoryForm.header.title}").
32       add(new StringField(CATEGORY_NAME, "#{UICategoryForm.label.name}", "")).
33       add(new TextAreaField(CATEGORY_DESC, "#{UICategoryForm.label.description}", "")).
34       add(new IntegerField(CATEGORY_ORDER, "#{UICategoryForm.label.category-order}", 0));
35     addButton(new Button("#{UICategoryForm.button.save}", SAVE_ACTION)) ;
36     addButton(new Button("#{UICategoryForm.button.cancel}", CANCEL_ACTION)) ;
37     addFieldValidator(EmptyFieldValidator.class) ;
38     addActionListener(CancelActionListener.class, CANCEL_ACTION) ;
39     addActionListener(SaveActionListener.class, SAVE_ACTION) ;
40   }
41   
42   public void setCategory(Category category) {
43     category_ = category ;
44     if (category == null) {
45       resetFields() ;
46     } else {
47       setStringFieldValue(CATEGORY_NAME, category.getCategoryName()) ;
48       setStringFieldValue(CATEGORY_DESC, category.getDescription()) ;
49       setIntegerFieldValue(CATEGORY_ORDER, category.getCategoryOrder()) ;
50     }
51   }
52   
53   static public class CancelActionListener extends ExoActionListener {
54         public void execute(ExoActionEvent event) throws Exception JavaDoc {
55             UICategoryForm uiForm = (UICategoryForm) event.getComponent() ;
56             uiForm.setRenderedSibling(UIAdminViewCategories.class) ;
57         }
58   }
59   
60   static public class SaveActionListener extends ExoActionListener {
61         public void execute(ExoActionEvent event) throws Exception JavaDoc {
62             UICategoryForm uiForm = (UICategoryForm) event.getComponent() ;
63       Category category = uiForm.category_ ;
64        boolean isNew = false ;
65        if(category == null) {
66          category = uiForm.service_.createCategoryInstance() ;
67          isNew = true ;
68        }
69        category.setCategoryName(uiForm.getStringFieldValue(CATEGORY_NAME) ) ;
70        category.setDescription(uiForm.getStringFieldValue(CATEGORY_DESC)) ;
71        category.setCategoryOrder(uiForm.getIntegerFieldValue(CATEGORY_ORDER)) ;
72        if(isNew) uiForm.service_.addCategory(category) ;
73        else uiForm.service_.updateCategory(category) ;
74        UIAdminViewCategories uiCategories =
75         (UIAdminViewCategories) uiForm.getSibling(UIAdminViewCategories.class) ;
76        uiCategories.update() ;
77              uiForm.setRenderedSibling(UIAdminViewCategories.class) ;
78         }
79   }
80 }
Popular Tags