JSF - 自定义标签 - 动态值在刷新后消失 [英] JSF - Custom Tags - Dynamic values disappear after refresh
问题描述
我遵循 此 教程在 JSF 2.1
中实现了一个marquee标签,并且部分成功。由于此标签支持动态数据,因此例如 。 #{bean.var}
作为一个值,我决定在组件内部弄脏它。然而,重新加载我的页面该值消失。
- 您可以告诉我如何正确实施,以便我可以使用我的动态在$
value-attribute ? - 中的值也可以指向正确的方向,即代码导致我的
元组类
?
非常感谢!
http:// myjavabuddy.blogspot.de/2013/04/writing-custom-components-for-jsf-20.html
这是我的JSF
< customJSF:marquee value =/>
这是我的组件
@FacesComponent(amelunxenfast.prog3.wissensmanagement.components.marquee)
public class MarqueeComponent extends UIComponentBase {
public static final字符串COMPONENT_TYPE =com.himanshu.jsf.custom.marquee;
字符串值= null;
@EJB
FeedEJB ejb;
public String getValue(){
返回值;
}
@Override
public String getFamily(){
return COMPONENT_TYPE;
$ b @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);
$ b @Override
public void encodeEnd(FacesContext arg0)throws IOException {
super.encodeEnd(arg0);
}
public void setValue(String value){
this.value = value;
}
}
太长的评论...
我不认为注入 @EJB 里面
@FacesComponent
,我不认为这是一个好习惯,在这个特定情况下。
我认为一个更好的方法应该是用你自己的类扩展 TextRenderer
,在faces-config中声明一个新组件,并以与<$ c相同的方式使用它$ c> h:outputText (在 value
属性中传递 ValueExpression
)
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;
}
}
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)
这篇关于JSF - 自定义标签 - 动态值在刷新后消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!