2014-02-22 34 views
0

我跟着this教程實現marquee標籤在JSF 2.1併成功部分。由於這個標籤的確如此,不是支持動態數據,e.g. #{bean.var}作爲一個值,我決定在組件內部弄髒它。JSF - 自定義標籤 - 動態值刷新後消失

但是,重新加載我的頁面後,該值消失。標籤仍然存在,但內容不見了。

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

}

回答

1

太長一個COM ...

我不認爲這是合法的注入@EJB@FacesComponent,我不認爲這是一個很好的做法,在這種特殊情況下。

我想一個更好的辦法應該延長TextRenderer用你自己的類,在faces-配置聲明一個新的組件,並使用它,你使用h:outputText以同樣的方式(在value屬性傳遞ValueExpression

+0

你的意思是使用'TextRenderer'而不是'UIComponentBase'? – JustBasti