我想在JSF中构建自定义组件,可能会:
value
属性中检索值<t:myComponent value="#{myBean.value}" />
将显示
<div>
<input id="my_input" type="text" value="my_value" />
<button onclick="update_value(document.getElementById('my_input').value)">update</button>
</div>
<script>
function update_value(val) {
// ???
}
</script>
并且当我们单击按钮时,它将根据输入的当前内容更改myBean.value
(用户可以明显更改)。
据我所知,用ResponseWriter
在组件中显示值看起来很容易,但是我不明白如何构建Javascript来调用组件以更改组件的值。
示例
// myBean.value = "foo"
<t:myComponent value="#{myBean.value}" />
// displays
<div>
<input id="my_input" type="text" value="foo" />
<button ...>update</button>
</div>
// user change input content by "bar"
// user click the update button
// myBean.value = "bar" now