Création de composantes, les expresion #{ } ne sont pas calculées
Bonjour,
J'ai essayer de créer des composantes JSF, mais le problème que j'ai c'est que les EL ne sont pas calculées.
Ma class de composante:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| package bf.component;
import java.io.IOException;
import javax.faces.component.UIOutput;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
public class MyOutput extends UIOutput{
private String myField;
public String getMyField() {
return myField;
}
public void setMyField(String myField) {
this.myField = myField;
}
@Override
public Object saveState(FacesContext context) {
Object[] values = new Object[2];
values[0] = super.saveState(context);
values[1] = myField;
return (Object)values;
}
@Override
public void restoreState(FacesContext context, Object state) {
Object values[] = (Object[])state;
super.restoreState(context, values[0]);
}
@Override
public String getFamily() {
return "myOutput";
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("p", this);
writer.write("Salam: "+myField);
writer.endElement("p");
}
@Override
public void encodeEnd(FacesContext context) throws IOException {
super.encodeEnd(context);
}
} |
mon tag:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| package bf.component;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.webapp.UIComponentELTag;
public class MyOutputTag extends UIComponentELTag {
private ValueExpression myField;
public ValueExpression getMyField() {
return myField;
}
public void setMyField(ValueExpression myField) {
this.myField = myField;
}
@Override
public String getComponentType() {
return "myOutput";
}
@Override
public String getRendererType() {
return null;
}
@Override
protected void setProperties(UIComponent component) {
// TODO Auto-generated method stub
super.setProperties(component);
MyOutput myOutput = (MyOutput)component;
if(myField != null){
if(myField.isLiteralText()){
String test = (String)myField.getValue(FacesContext.getCurrentInstance().getELContext());
component.setValueExpression("myField", myField);
}
else{
myOutput.setMyField(myField.getExpressionString());
}
}
}
} |
mon tld:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>0.03</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>arcmind</short-name>
<uri>http://faico.com/jsf/component/tags</uri>
<description>Faico tags</description>
<tag>
<name>myOutput</name>
<tag-class>bf.component.MyOutputTag</tag-class>
<body-content>JSP</body-content>
<attribute>
<name>myField</name>
<description>The value of the label</description>
<deferred-value>
<type>
java.lang.String
</type>
</deferred-value>
</attribute>
</tag>
</taglib> |
faces-config.xml:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
|
<component>
<component-type>myOutput</component-type>
<component-class>bf.component.MyOutput</component-class>
<property>
<description>
Hotspot coordinates if we synthesize an ImageArea bean.
</description>
<property-name>myField</property-name>
<property-class>java.lang.String</property-class>
</property>
</component> |