JSF 2.0 + Primefaces 富文本编辑器
<p:editor value="#{editorBean.value}" widgetVar="editor" width="686"
height="390" language="en" align="center">
</p:editor>
以下是我从 primefaces 获取的富文本编辑器 bean
@ManagedBean(name = "editorBean")
@SessionScoped
public class EditorBean {
private static final String MANAGED_BEAN_NAME = "editorBean";
private String value;
public static EditorBean getCurrentInstance() {
return (EditorBean) FacesContext.getCurrentInstance()
.getExternalContext().getRequestMap().get(MANAGED_BEAN_NAME);
}
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
除此之外,我还有另一个 bean,称为 A。我在 A 中有一个方法,用于填充 HTML 表。我想要的是当用户打开编辑器时,它应该预先填充 HTML 表数据,当然更改应该反映到 (String: value) 中。因此,你可以说我试图将这两种价值观结合在一起。我认为它需要用 DI 来完成,但不知何故它不起作用。如果有人可以指导或引用一个例子,那将会非常有帮助。
<p:editor value="#{editorBean.value}" widgetVar="editor" width="686"
height="390" language="en" align="center">
</p:editor>
Following is my rich-text editor bean picked up from primefaces
@ManagedBean(name = "editorBean")
@SessionScoped
public class EditorBean {
private static final String MANAGED_BEAN_NAME = "editorBean";
private String value;
public static EditorBean getCurrentInstance() {
return (EditorBean) FacesContext.getCurrentInstance()
.getExternalContext().getRequestMap().get(MANAGED_BEAN_NAME);
}
public void setValue(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
Apart from this I have another bean say A. I have a method inside A that populates a HTML table. What I want is when the user opens the editor, it should be pre-populated with that HTML table data and of course the changes should get reflected into (String: value). Therefore, you can say that I am trying to tie up both the values together. I think it needs to be done with DI but somehow its not working. If someone can guide or quote an example, it would be really helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是重写
getValue()
方法以从 beanA
获取值。是的,对 A bean 的引用应该来自 DI:
或者,使用 CDI,只需:
最后,您的
getValue
方法One way to do it is rewrite your
getValue()
method to pick up the value from beanA
.And yes, the reference to your A bean should come from DI:
Or, with CDI, just:
Finally, your
getValue
method