JSF 2.0 + Primefaces 富文本编辑器

发布于 2024-10-31 10:02:54 字数 915 浏览 0 评论 0原文

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太阳哥哥 2024-11-07 10:02:54

一种方法是重写 getValue() 方法以从 bean A 获取值。
是的,对 A bean 的引用应该来自 DI:

//injecting a reference to A
@ManagedPropery(value="#{A}") //or whatever is the name of your bean
private A beanA;

public void setBeanA(A beanA) {
    this.beanA = beanA;
}

或者,使用 CDI,只需:

@Inject private A beanA

最后,您的 getValue 方法

public String getValue() {
    return beanA.getValue()
}

One way to do it is rewrite your getValue() method to pick up the value from bean A.
And yes, the reference to your A bean should come from DI:

//injecting a reference to A
@ManagedPropery(value="#{A}") //or whatever is the name of your bean
private A beanA;

public void setBeanA(A beanA) {
    this.beanA = beanA;
}

Or, with CDI, just:

@Inject private A beanA

Finally, your getValue method

public String getValue() {
    return beanA.getValue()
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文