问题
I've followed this tutorial for implementing a marquee-tag in JSF 2.1
and succeeded partly. As this tag does NOT support dynamic data, e.g. #{bean.var}
as a value, I've decided to do it dirty inside the component.
However, after reloading my page, the value disappears. The tag is still there, but the content is gone.
- Could you show me how to implement is correctly, that I can use my dynamic value inside the
value-attribute
? - Or would you point me into the right direction which code is causing the error in my
component class
?
Thank you very much!
http://myjavabuddy.blogspot.de/2013/04/writing-custom-components-for-jsf-20.html
This is my JSF
<customJSF:marquee value="" />
This is my Component
@FacesComponent ("amelunxenfast.prog3.wissensmanagement.components.marquee")
public class MarqueeComponent extends UIComponentBase {
public static final String COMPONENT_TYPE = "com.himanshu.jsf.custom.marquee";
String value = null;
@EJB
FeedEJB ejb;
public String getValue() {
return value;
}
@Override
public String getFamily() {
return COMPONENT_TYPE;
}
@Override
public void encodeBegin(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
writer.startElement("marquee", this);
writer.writeAttribute("scrollamount", "10", "");
writer.write(ejb.getFeedString());
writer.endElement("marquee");
}
@Override
public void encodeEnd(FacesContext arg0) throws IOException {
super.encodeEnd(arg0);
}
public void setValue(String value) {
this.value = value;
}
}
回答1:
Too long for a comment...
I don't think it's legit to inject @EJB
inside @FacesComponent
and i don't think it's a good practice, in this specific case.
I think a better approach should be extending TextRenderer
with your own class, declare a new component in faces-config and use it the same way you use h:outputText
(passing ValueExpression
in value
attribute)
来源:https://stackoverflow.com/questions/21948157/jsf-custom-tags-dynamic-values-disappear-after-refresh