1 5 package org.exoplatform.faces.core.component.model; 6 7 import java.util.ResourceBundle ; 8 import java.io.IOException ; 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 22 public class Button implements HtmlFragment { 23 protected String label_ ; 24 protected String clazz_ ; 25 protected String parameters_ ; 26 protected boolean activate_ ; 27 private boolean visible_ = true; 28 29 public Button(String name, Parameter[] params) { 30 label_ = name ; 31 StringBuffer b = new StringBuffer () ; 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 res, UIGrid uiParent) throws IOException { 45 if(!visible_) return; 46 if (activate_) { 47 String 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 res, 61 UIExoComponent uiParent, String objectId) throws IOException { 62 if(!visible_) return; 63 if (activate_) { 64 String 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 |