I have build a custom component in JSF 2.0
The tag looks like this:
<x:myTag id="1" name="AAA" />
The corresponding java class:
@FacesComponent("a.b.c.MyTag")
public class UIMyTag extends UIInput {
private String name;
private String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
logger.debug(getName()); //prints null for name="#{dummyBean.name}"
// and AAA for name="AAA"
logger.debug(getAttributes().get("name")); // always correct value
...
}
....
}
If I use
<x:myTag id="1" name="AAA" />
everything works as expected, but when I use EL for myTag attributes the setName()
method never gets called. So for,
<x:myTag id="#{dummyBean.id}" name="#{dummyBean.name}" />
I always get null
for the name
property inside my encodeBegin
method. After debugging I've noticed that the setName
method never gets called. I thought that maybe something regarding EL messes things up (and I still believe that the reason is related to that), but what's really weird is that the id
property works good: the setter gets called, and the value is as expected when the econding begins.
I have to mention that if I call getAttributes().get("name")
from the encodeBegin
method I get the correct name value, but I'm intrigued why it doesn't work with getter and setter.
Any ideas what's missing to my component?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…