我想在我的自定义组件上添加Method Expression支持。 我已经看到我必须写一个tagHandler。
我看过这篇文章: How to add Method Expression to a custom JSF component
我不明白methodRule方法的参数“void.class”和“moveEvent”是什么。
这是我的customComponent代码:
public class Link extends UIOutput{
private StringBuilder style = new StringBuilder();
private String id = "";
private Boolean active = false;
private String alt = "";
private String href = "";
private String hreflang = "";
private String rel = "";
private String target = "";
private String download = "";
private String media = "";
private String type = "";
public Boolean isActive() {
return active;
}
public void setActive(Boolean active) {
this.active = active;
}
public String getAlt() {
return alt;
}
public void setAlt(String alt) {
this.alt = alt;
}
public String getHref() {
return href;
}
public void setHref(String href) {
this.href = href;
}
public String getHreflang() {
return hreflang;
}
public void setHreflang(String hreflang) {
this.hreflang = hreflang;
}
public String getRel() {
return rel;
}
public void setRel(String rel) {
this.rel = rel;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public String getDownload() {
return download;
}
public void setDownload(String download) {
this.download = download;
}
public String getMedia() {
return media;
}
public void setMedia(String media) {
this.media = media;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public void encodeBegin(FacesContext context)throws IOException {
ResponseWriter writer = context.getResponseWriter();
String clientId = getClientId(context);
if("".equals(id) || id == null){
id = clientId;
}
Object styleClass = (getAttributes().get("styleClass") != null) ? (Boolean)getAttributes().get("styleClass") : "";
writer.startElement("li", this);
if(active){
style.append(" active ");
}
if(!"".equals(styleClass)){
style.append(styleClass);
}
writer.writeAttribute("id", id, null);
writer.writeAttribute("class", style.toString().trim(), null);
writer.startElement("a", this);
writer.writeAttribute("href", href, null);
if(!"".equals(alt)) { writer.writeAttribute("alt", alt, null); }
if(!"".equals(hreflang)) { writer.writeAttribute("hreflang", hreflang, null); }
System.out.println("rel = " + rel);
if(!"".equals(rel)) { writer.writeAttribute("rel", rel, null); }
if(!"".equals(target)) { writer.writeAttribute("target", target, null); }
if(!"".equals(download)) { writer.writeAttribute("download", download, null); }
if(!"".equals(media)) { writer.writeAttribute("media", media, null); }
if(!"".equals(type)) { writer.writeAttribute("type", type, null); }
for (UIComponent child : getChildren()) {
child.encodeAll(context);
}
}
@Override
public Object saveState(FacesContext context) {
Object values[] = new Object[10];
values[0] = super.saveState(context);
values[1] = id;
values[2] = style;
values[3] = active;
values[4] = alt;
values[5] = href;
values[6] = hreflang;
values[7] = rel;
values[8] = target;
values[9] = download;
values[10] = media;
values[110] = type;
return ((Object) (values));
}
@Override
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
id = (String)values[1];
style.insert(0, values[2]);
active = (Boolean)values[3];
alt = (String)values[4];
href = (String)values[5];
hreflang = (String)values[6];
rel = (String)values[7];
target = (String)values[8];
download = (String)values[9];
media = (String)values[10];
type = (String)values[11];
}
}