将h:inputText值传递给f:ajax侦听器 [英] Pass h:inputText value to f:ajax listener
问题描述
我正在尝试创建一个可以完全编辑并在单个页面上显示的sql数据表. 我正在使用jsf和一个命名的bean. 我使用arraylist bean对象存储和显示数据.
I am trying to create a sql data table that can be fully edited and displayed on a single page. I am using jsf and a named bean. I use a arraylist bean object to store and display the data.
public List<RegionBean> getRegions()throws SQLException{
数据显示在inputText元素中.当我尝试在后备bean中使用sql方法更新信息时,无法将更新后的文本添加到sql数据库中. 它将简单地输入与原始显示相同的值. 我想做的是让输入文本框显示数组列表中的数据值,然后在对它们进行编辑后将它们存储在bean的另一个字段中.
The data is displayed in an inputText element. When I try to update the information using a sql method in the backing bean it fails to add the updated text to sql data base. It will simply put the same value as was originally displayed. What I want to do is have the input text box display the data values from the array list and then store them in a different field in the bean after they have been edited.
这是我现在的代码.
<h:dataTable value="#{regionBean.regions}" var="regions"/>
<h:column>
<f:facet name="header">Region ID</f:facet>
#{regions.regionID}
</h:column>
<h:column>
<f:facet name="header">Region Description</f:facet>
<h:inputText id="des" value="#{regions.regionDescription}">
<f:ajax event="change"
listener="#{regionBean.updateText(event)}"
render="des"/>
</h:inputText>
<h:column>
<f:facet name="header">Save</f:facet>
<h:commandButton action="#{regionBeanupdate(regions.regionID)}" value="Update">
</h:commandButton>
</h:column>
我遇到的问题 UIComponent-ClientId =,消息= javax.el.PropertyNotWritableException:
The problem I am having with this UIComponent-ClientId=, Message=javax.el.PropertyNotWritableException:
在豆子中我有
public void updateText(AjaxBehaviorEvent event)
throws AbortProcessingException { }
如何将新的输入文本框值传递给此方法,以便将其作为String存储在Bean中,从而能够使用它来更新sql数据库.
How can I pass the new input text box value to this method so as I can store it as String in the bean and thus able to use it to update the sql database.
请理解我熟悉sql,并且之前已经构建了多个CRUD应用程序,而我的问题与sql语法或其他方面无关.
Please understand that I am familiar with sql and I have built several CRUD applications before and my question is not related to sql syntax or other wise.
推荐答案
从<f:ajax>
中删除listener
和render
,然后在<h:inputText>
中添加valueChangeListener
.
Remove listener
and render
from <f:ajax>
then add a valueChangeListener
to <h:inputText>
.
<h:inputText value="#{regions.regionDescription}" valueChangeListener="#{region.updateText}">
<f:ajax event="change"/>
</h:inputText>
然后在您的bean中:
Then in your bean:
public void updateText(ValueChangeEvent event){
input = event.getNewValue().toString();
}
注意:input
是用于存储新值的变量.
Note: input
is the variable in which the new value is stored.
这篇关于将h:inputText值传递给f:ajax侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!