JSF 1.2 自定义组件 - 来自支持 Bean 的主体内容

发布于 2024-07-15 17:38:05 字数 925 浏览 5 评论 0原文

我正在使用 JSF 1.2 开发自定义组件。 我的标记类扩展了 UIComponentELTag 并具有 ValueExpression 类型的变量。 这些值是从标签的相应属性中设置的(使用 setProperties 函数),例如,

<sr:show name="#{backingBean.name}" ...> #{backingBean.mainContent}</sr:show>

当我尝试获取标签的 bodyContent 作为绑定值时,我陷入了困境。 这就是我已经进行的程度:

public int doAfterBody() throws JspException{
    if(bodyContent!=null) {
        String body = bodyContent.getString();
        FacesContext context = FacesContext.getCurrentInstance();
        UIComponent component = super.findComponent(context);
        MyComp myComp= (MyComp) component;
        myComp.setMain(body);
    }
    bodyContent.clearBody();
    return SKIP_BODY;
}

如果标记的主体不包含绑定值,则此代码可以正常工作。 我想检查主体是否具有绑定值,然后从 bean 设置该值。

在 JSF 1.1 中,我使用 isValueReference(body) 检查了这一点。 如何在 JSF 1.2 中实现这一目标? 我在任何地方都找不到任何将正文内容作为绑定值的示例。

I am developing a custom component using JSF 1.2. My tag class extends UIComponentELTag and has variables of type ValueExpression. The values for these are getting set from the corresponding attributes of the tag (using setProperties function), for example

<sr:show name="#{backingBean.name}" ...> #{backingBean.mainContent}</sr:show>

I am stuck when I try to get the bodyContent of the tag as a binding value.
This is how far I have proceeded:

public int doAfterBody() throws JspException{
    if(bodyContent!=null) {
        String body = bodyContent.getString();
        FacesContext context = FacesContext.getCurrentInstance();
        UIComponent component = super.findComponent(context);
        MyComp myComp= (MyComp) component;
        myComp.setMain(body);
    }
    bodyContent.clearBody();
    return SKIP_BODY;
}

If the body of the tag does not contain binding value, this code works fine. I want to check if the body has binding value and then set the value from the bean.

In JSF 1.1, I checked this using isValueReference(body). How do I achieve this in JSF 1.2? I could not find any examples of getting the body content as binding value anywhere.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

随心而道 2024-07-22 17:38:05

为什么不简单地添加另一个变量(例如“内容”)并将其绑定到您想要呈现的正文文本?

<sr:show name="#{backingBean.name}" text="#{backingBean.mainContent}" />

或者简单地说:

<sr:show bean="#{backingBean} />

渲染全部。

Why not simply add another variable e.g. "contents" and bind that to the body text you want to render?

<sr:show name="#{backingBean.name}" text="#{backingBean.mainContent}" />

Or simply:

<sr:show bean="#{backingBean} />

and render the whole lot.

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