【问题标题】:JSF - Custom Tags - Dynamic values disappear after refreshJSF - 自定义标签 - 刷新后动态值消失
【发布时间】:2014-03-23 18:40:09
【问题描述】:

我已按照 this 教程在JSF 2.1 中实现选取框标签并部分成功。由于这个标签 NOT 支持动态数据,e.g. #{bean.var} 作为一个值,我决定在组件内部做脏。

但是,重新加载我的页面后,该值消失了。标签还在,但内容不见了。

  1. 能否告诉我如何正确实施,我可以在value-attribute 中使用我的动态值?
  2. 或者您能否指出正确的方向是哪个代码导致了我的component class 中的错误?

非常感谢!

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 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;
}

}

【问题讨论】:

    标签: java html jsf-2 tags


    【解决方案1】:

    评论太长了...

    我认为在 @FacesComponent 中注入 @EJB 是不合法的,在这种特定情况下,我认为这不是一个好的做法。

    我认为更好的方法应该是用你自己的类扩展TextRenderer,在 faces-config 中声明一个新组件并像使用h:outputText 一样使用它(在value 属性中传递ValueExpression

    【讨论】:

    • 您的意思是使用TextRenderer 而不是UIComponentBase
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-22
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多