[英]ajax listener not called for component in datatable
The ajax listener is not called for a checkbox that is in a datatable. 没有为数据表中的复选框调用ajax侦听器。 I reduced the problematic code to the following simple (and not very meaningful) example. 我将有问题的代码简化为以下简单(但意义不大)的示例。
I have a datatable and in every row a checkbox. 我有一个数据表,每一行都有一个复选框。 By clicking the checkbox the ajax listener shall be called but it isn't called. 通过单击复选框,应调用ajax侦听器,但不调用它。 I have also a checkbox outside the datatable. 我在数据表外还有一个复选框。 When clicking this checkbox the ajax listener is called. 单击此复选框时,将调用ajax侦听器。 What is wrong with the checkboxes in the datatable or what should I do to get it working? 数据表中的复选框有什么问题,或者应该怎么做才能使其正常工作?
Here is the xhtml file (I'm using tomahawk): 这是xhtml文件(我正在使用战斧):
<h:form>
<h:selectBooleanCheckbox id="selectAssignmentOutside" value="#{myController.assignments[100000]}">
<f:ajax render="selectionStateOutside" listener="#{myController.processAjaxBehavior}"/>
</h:selectBooleanCheckbox>
<h:outputText id="selectionStateOutside" value="#{myController.assignments[100000] ? 'selected' : 'not selected'}"/>
<p/>
<t:dataTable id="assignmentsTable" value="#{myController.allEntities}" var="row" forceIdIndexFormula="#{row.id}" preserveDataModel="false">
<h:column>
<h:outputText value="#{row.id}"/>
</h:column>
<h:column>
<h:selectBooleanCheckbox id="selectAssignment" value="#{myController.assignments[row.id]}">
<f:ajax render="selectionState" listener="#{myController.processAjaxBehavior}"/>
</h:selectBooleanCheckbox>
<h:outputText id="selectionState" value="#{myController.assignments[row.id] ? 'selected' : 'not selected'}"/>
</h:column>
</t:dataTable>
</h:form>
the controller: 控制器:
@ManagedBean
@ViewScoped
public class MyController
{
private List<Entity> entities;
private Map<Long, Boolean> assignments;
public Map<Long, Boolean> getAssignments() {
if (assignments == null) {
assignments = new HashMap<>();
assignments.put( 100000L, true );
assignments.put( 100001L, true );
assignments.put( 100002L, false );
assignments.put( 100003L, false );
}
return assignments;
}
public List<Entity> getAllEntities() {
entities = new ArrayList<>();
entities.add( new Entity( 100000L ));
entities.add( new Entity( 100001L ) );
entities.add( new Entity( 100002L ) );
entities.add( new Entity( 100003L ) );
return entities;
}
public void processAjaxBehavior(AjaxBehaviorEvent event)
{
System.out.println("#### processAjaxBehavior");
// here some things should be done in model
// and the component re-rendered by ajax component shows the result
}
}
Tomahawk's datatable has a bug in generating the client id if the attribute "forceIdIndexFormula" is set. 如果设置了属性“ forceIdIndexFormula”,则战斧的数据表在生成客户端ID时会出现错误 。 After removing the attribute "forceIdIndexFormula" from "t:datatable" it works as expected. 从“ t:datatable”中删除属性“ forceIdIndexFormula”后,它将按预期工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.