KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > faces > core > component > model > Button


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.faces.core.component.model;
6
7 import java.util.ResourceBundle JavaDoc ;
8 import java.io.IOException JavaDoc;
9
10 import javax.faces.context.ResponseWriter;
11 import org.exoplatform.Constants;
12 import org.exoplatform.faces.core.component.UIExoComponent;
13 import org.exoplatform.faces.core.component.UIGrid;
14 import org.exoplatform.commons.utils.ExpressionUtil ;
15
16 /**
17  * Wed, Dec 22, 2003 @ 23:14
18  * @author: Tuan Nguyen
19  * @email: tuan08@users.sourceforge.net
20  * @version: $Id: Button.java,v 1.10 2004/10/18 22:06:09 benjmestrallet Exp $
21  */

22 public class Button implements HtmlFragment {
23   protected String JavaDoc label_ ;
24   protected String JavaDoc clazz_ ;
25   protected String JavaDoc parameters_ ;
26   protected boolean activate_ ;
27   private boolean visible_ = true;
28   
29   public Button(String JavaDoc name, Parameter[] params) {
30     label_ = name ;
31     StringBuffer JavaDoc b = new StringBuffer JavaDoc() ;
32     for(int i = 0; i < params.length; i++) {
33       b.append(Constants.AMPERSAND);
34       b.append(params[i].getName()).append('=').append(params[i].getValue());
35     }
36     parameters_ = b.toString() ;
37     activate_ = true ;
38   }
39   
40   public void setActivate(boolean b) { activate_ = b ; }
41   public void setVisible(boolean visible) { visible_ = visible;}
42   public boolean isVisible(){return visible_;}
43   
44   public void render(ResponseWriter w, ResourceBundle JavaDoc res, UIGrid uiParent) throws IOException JavaDoc {
45     if(!visible_) return;
46       if (activate_) {
47         String JavaDoc baseURL = uiParent.getBaseURL() ;
48         w.write("<a");
49         if (clazz_ != null) {
50           w.write(" class='"); w.write(clazz_); w.write("'");
51         }
52         w.write(" HREF='"); w.write(baseURL); w.write(parameters_); w.write("'>");
53         w.write(ExpressionUtil.getExpressionValue(res,label_));
54         w.write("</a>");
55       } else {
56         w.write("<span style='border: 1px groove'>");w.write(label_); w.write("<span>");
57       }
58   }
59   
60   public void render(ResponseWriter w, ResourceBundle JavaDoc res,
61                      UIExoComponent uiParent, String JavaDoc objectId) throws IOException JavaDoc {
62     if(!visible_) return;
63     if (activate_) {
64       String JavaDoc baseURL = uiParent.getBaseURL() ;
65       w.write("<a");
66       if (clazz_ != null) {
67         w.write(" class='"); w.write(clazz_); w.write("'");
68       }
69       w.write(" HREF='"); w.write(baseURL); w.write(parameters_) ;
70       if(objectId != null) {
71         w.write(Constants.AMPERSAND + "objectId="); w.write(objectId) ;
72       }
73       w.write("'>");
74       w.write(ExpressionUtil.getExpressionValue(res,label_));
75       w.write("</a>");
76     } else {
77       w.write("<span style='border: 1px groove'>");
78       w.write(ExpressionUtil.getExpressionValue(res,label_));
79       w.write("<span>");
80     }
81   }
82 }
83
Popular Tags