ajax render 속성은 AH에서 작동하지 않습니다 : JSF2에서 DataTable
문제
JSF 2.0에서 간단한 응용 프로그램이있는 문제가 있습니다.
Ajax 지원으로 TODO 목록을 작성하려고합니다. 데이터 가능을 사용하여 표시하는 Todo 문자열이 있습니다. 이 데이터 가능 안에는 작업을 삭제하기위한 명령 링크가 있습니다. 문제는 이제 DataTable이 다시 렌더링되지 않기 때문입니다.
<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는 다른 요소로 테이블을 감싸고 절대 참조 (즉, 문서의 루트에서 모든 부모 컨테이너를 명명)를 사용하여 참조하는 것을 제안합니다.u003Cf:ajax> 꼬리표.
이 같은:
<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>
그러나 절대 참조를 사용하는 것은 항상 문제의 원천이며 견해가 증가함에 따라 리팩토링 시간을 기하 급수적으로 증가시킵니다.
단지 테이블을 렌더링하는 방법이 없습니다.u003Cf:ajax> 태그 (ajax 이벤트에서 성가신 ": number_of_row"를 추가하지 못하도록 JSF를 방지)?
다른 팁
나는 u003Ch:dataTable> 양식으로 동봉되어 있습니까?
이 문제로 한동안 어려움을 겪은 후에는 쉽고 깨끗한 솔루션을 검색했습니다. @형태 에게 세우다 속성 u003Cf:ajax> 그리고 Voila!
Full example:
<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는u003Cf:ajax> 버튼에 태그. 이 xhtml을 작성하면 :
<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>
나는이 HTML을 얻는다 :
<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 : TABLE'을받을 것으로 예상됩니다.
그것은 문제를 해결하지는 않지만 해결 방법을 찾는 데 도움이 될 수 있습니다.
h : form에 prependid = "false"를 추가해야합니다.
나는 같은 문제에 부딪쳤다.
"작동"하는 한 가지는 추가하는 것입니다 풍부한 프로젝트에, 그리고 교체
h:datatable
a
rich:datatable.
올바른 ID를 생성합니다.