如何将JSF定制组件的提交值传递给托管bean? [英] How to pass submitted value of JSF custom component to managed bean?

查看:103
本文介绍了如何将JSF定制组件的提交值传递给托管bean?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义组件。我向它添加了一个动态输入文本框(来自encode函数)。

I have created a custom component. I add a dynamic input text box to it (from the encode function).

该组件正确呈现为HTML。

The component is correctly is rendered as HTML.

但是我想将文本框的值绑定到Managed Bean上的某些属性。因此,其他开发人员可以将其jsp上的组件与托管bean一起使用。

But I want to bind the value of the text box to some property on the Managed Bean. So some other developer can use the component on his jsp with his managed bean.

我想知道,该怎么办,以便在文本框中输入值(由我的组件动态创建的)设置为某些Managed bean属性。

I want to know, what should I do, so that the value entered in the text box (which my component dynamically creates) is set to the some Managed bean property.

推荐答案

好,问题就解决了。

Well, the problem is solved.

在encodeEnd()方法中,我将元素添加为

In the encodeEnd() method I added the element as

HtmlInputHidden hidden = new HtmlInputHidden();
hidden.setParent(this);
hidden.setId("someId");
ValueExpression ve = getValueExpression("value");
hidden.setValueExpression("value", ve);
hidden.encodeBegin(context);
hidden.encodeEnd(context);

这似乎有问题。

然后我将其更改为...

Then I changed this to ...

HtmlInputHidden hidden = new HtmlInputHidden();
hidden.setId("someId");
ValueExpression ve = getValueExpression("value");
hidden.setValueExpression("value", ve);
this.getChildren().add(hidden);
hidden.encodeBegin(context);
hidden.encodeEnd(context);

this.getChildren()。add();的使用解决了我的问题

The use of this.getChildren().add(); solved my problem

P.S。显然,在添加元素之前,需要检查该元素是否已经存在。

P.S. Obviously before adding the element, it needs to be checked if the element is already present.

这篇关于如何将JSF定制组件的提交值传递给托管bean?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆