Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 调用方法并在InputText更改时重新提交datatable_Jsf_Jsf 2_Datatable - Fatal编程技术网

Jsf 调用方法并在InputText更改时重新提交datatable

Jsf 调用方法并在InputText更改时重新提交datatable,jsf,jsf-2,datatable,Jsf,Jsf 2,Datatable,我正在学习一些JSF,我想知道一些事情。我已经在Stack Overflow和著名网站中搜索了很多,但我没有找到解决方案 实际上,我在同一页中有一个输入文本和一个数据表。代码如下所示: <h:form> <h:inputText id="discipline" value="#{disciplineMBean.name}" valueChangeListener="#{disciplineMBean.updateList}"> &

我正在学习一些JSF,我想知道一些事情。我已经在Stack Overflow和著名网站中搜索了很多,但我没有找到解决方案

实际上,我在同一页中有一个输入文本和一个数据表。代码如下所示:

<h:form>
    <h:inputText id="discipline" 
    value="#{disciplineMBean.name}" 
    valueChangeListener="#{disciplineMBean.updateList}">
       <f:ajax event="keyup" reRender="myTable"/>  
    </h:inputText>
    <h:commandButton value="Add" action="#{disciplineMBean.create}">
    </h:commandButton>
</h:form>

<h:form>
    <h:dataTable id="myTable" var="disciplina" 
    value="#{disciplinaMBean.disciplineList}">

        <h:column>
            <f:facet name="header">Name</f:facet>       
            <h:outputText value="#{discipline.name}" />
        </h:column>

    </h:dataTable>
</h:form>
总而言之,我希望当用户在输入字段中键入某个内容时,规程列表会随着匹配规程的更新而更新,而无需重新加载页面,当用户更改输入字段时,表会随着匹配规程的更新而实时更新

我能做那样的事吗?

编辑: 我已经解决了我的问题,但我不知道我的方式是否是做这件事的最佳方式。因此,我将保留这个问题,等待回答,解释一个更好的方法来做到这一点(为未来需要类似功能的用户)。当一个好的答案被张贴,我会给这个最好的答案


注意:我翻译了变量名,如果我忘了什么,很抱歉

您的帖子中有一个标签“jsf-2”。但是在JSF2中,
reRender
属性被重命名为
render
。你使用JSF2吗?是的,JavaServerFaces2.0。我必须将
reRender
重命名为
render
?如果我更改为“render”,我会出现以下错误:
包含未知id“myTable”-无法在组件规程的上下文中找到它
这是因为您有两种不同的表单。要解析
myTable
,请设置
render=“:myTable”
@noone:
reRender
在JSF 1.x中从未存在过,甚至整个
在JSF 1.x中也不存在。
reRender
属性可从RichFaces 3.x
组件中识别。所以实际上在JSF2.x中没有任何东西被重命名。整个
在JSF2.0中是全新的。所有JSF2.x书籍、教程甚至标记文档都正确地将
render
显示为有效属性。该OP只是粗心地在谷歌上搜索/猜测,而不是简单地查看官方文件。
public void updateList(){
    if( getName() != null && getName().length() > 0){
        this.setDisciplineList( <working_connection_with_db_sending_getName()> );
    }else{
        this.setDisciplineList( <working_connection_with_db_all_results> );
    }   
}
<h:inputText id="discipline" value="#{disciplineMBean.name}">
    <f:ajax event="keyup" action="#{disciplineMBean.updateList}" reRender="myTable" />
</h:inputText>