在JSF2的dataTable:阿贾克斯渲染属性不会再在H工作
题
我有一些问题与在JSF 2.0简单的应用程序。
我尝试建立一个待办事项列表与Ajax支持。我有我的显示用数据表中的一些待办事项字符串。这里面的数据表我有一个commandLink删除任务。现在的数据表没有得到重新呈现出了问题。
<h:dataTable id="todoList" value="#{todoController.todos}" var="todo">
<h:column>
<h:commandLink value="X" action="#{todoController.removeTodo(todo)}">
<f:ajax execute="@this" render="todoList" />
</h:commandLink>
</h:column>
<h:column>
<h:outputText value="#{todo}"/>
</h:column>
</h:dataTable>
感谢您的帮助。
编辑(TodoController):
@ManagedBean
@SessionScoped
public class TodoController {
private String todoStr;
private ArrayList<String> todos;
public TodoController() {
todoStr="";
todos = new ArrayList<String>();
}
public void addTodo() {
todos.add(todoStr);
}
public void removeTodo(String deleteTodo) {
todos.remove(deleteTodo);
}
/* getter / setter */
}
解决方案
(貌似我没有足够的声誉别人的答案,评论)的
我认为FRotthowe表明与另一个元件包裹表,并使用绝对基准(即命名从文档的根的所有父容器。)从
像这样:
<h:form id="form">
<h:panelGroup id ="wrapper">
<h:dataTable value="#{backingBean.data}" var="list">
<h:column>
<h:commandButton value="-" action="#{backingBean.data}">
<f:ajax render=":form:wrapper"/>
</h:commandButton>
</h:column>
</h:dataTable>
</h:panelGroup>
</h:form>
但是,使用绝对引用总是的问题和增加的源极呈指数重构时间作为视图增长。
是不是有没有办法只呈现从
其他提示
假设我的的
这个问题挣扎了一会儿后,我一派容易和清洁溶液:添加的 @form 以<强>呈现强>的属性的
完整的示例:
<h:form id="theForm">
<h:dataTable id="table" value="#{tasksMgr.allTasks}" var="task">
<h:column>
#{task.name}
</h:column>
<h:column>
<h:commandButton id="removeTaskButton" value="X" action="#{tasksMgr.removeTask(task)}">
<f:ajax render="@form" />
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
完整的文章这让我在这里: http://blogs.steeplesoft.com/2009/10/jsf-2-hdatatable-and-ajax-updates/
使用此代码:
<h:form id="form">
<h:panelGroup id="panel">
<h:dataTable id="todoList" value="#{todoController.todos}" var="todo">
<h:column>
<h:commandLink value="X" action="#{todoController.removeTodo(todo)}">
<f:ajax render=":form:panel" />
</h:commandLink>
</h:column>
<h:column>
<h:outputText value="#{todo}"/>
</h:column>
</h:dataTable>
</h:panelGroup>
</h:form>
我遇到了同样的问题,并认为,如果你把一个元素(例如)围着桌子和重新呈现,它会正常工作。不过,我不明白为什么它是这样的。任何人吗?
出于某种原因,JSF被修改所述的
<h:form id="form">
<h:commandButton value="Button">
<f:ajax render="table"/>
</h:commandButton>
<h:dataTable id="table" value="#{tableData.data}">
<h:column>
<h:commandButton value="Button">
<f:ajax render="tocoto"/>
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
我得到这个网站:
<form id="j_idt7" name="j_idt7" method="post" action="/WebApplication1/faces/index.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt7" value="j_idt7" />
<input id="j_idt7:j_idt8" type="submit" name="j_idt7:j_idt8" value="Button" onclick="mojarra.ab(this,event,'action',0,'j_idt7:table');return false" />
<table id="j_idt7:table"><tbody>
<tr>
<td><input id="j_idt7:table:0:j_idt10" type="submit" name="j_idt7:table:0:j_idt10" value="Button" onclick="mojarra.ab(this,event,'action',0,'j_idt7:table:0');return false" /></td>
</tr>
</tbody></table>
<input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-7634557012794378167:1020265910811114103" autocomplete="off" />
</form>
注意的是,在第二个按钮的ID是“j_idt7:表:0”,而我期望得到。“j_idt7:表”如我在第一个做
这并不能解决问题,但可能有助于找到一种解决方法。
您需要添加prependId = “假” 到你的H:形式
不隶属于 StackOverflow