我需要您通过ajax侦听器使用所选行的onclick事件来获取列值。
数据表代码是:
<p:dataTable id="availableCars" var="car" rowKey="#{car}" value="#{CarsView.carDetails}">
<p:column style="width:20px">
<h:outputText id="dragIcon" styleClass="ui-icon ui-icon-arrow-4"/>
<p:draggable for="dragIcon" revert="true" helper="clone"/>
</p:column>
<p:column headerText="Id">
<h:outputText value="#{car.employeeName}"/>
</p:column>
<p:column headerText="Id">
<h:outputText value="#{car.employeeCode}"/>
</p:column>
<p:column style="width:32px">
<p:commandButton icon="ui-icon-search" action="#{CarsView.getDetails}">
<f:setPropertyActionListener target="#{CarsView.employee}" value="#{car.employeeName}"/>
<f:setPropertyActionListener target="#{CarsView.code}" value="#{car.employeeCode}"/>
<p:ajax event="click" listener="#{CarsView.onclickbutton}"/>
</p:commandButton>
</p:column>
</p:dataTable>
检索List的代码:
@PostConstruct
public void init() {
cars= new ArrayList<Car>();
droppedCars = new ArrayList<Car>();
Car earn = new Car();
earn.setEmployeeCode("1111");
earn.setEmployeeName("James");
cars.add(earn);
}
public void onclickbutton(ClickEvent event)
{
System.out.println("Clicked");
DataTable objDataTable = (DataTable) event.getSource();
}
在我的情况下,如何在datatable
方法中访问availableCars onclickbutton
中的对象(employeeCode和employeeName),并获取列值并将它们分配给变量。
答案 0 :(得分:0)
您可以通过传递迭代器变量&#34; car &#34;来实现此目的。 p:datatable方法CarsView.onclickbutton
传递迭代器变量&#34; 汽车&#34;如下:
<p:commandButton icon="ui-icon-search" action="#{CarsView.getDetails}">
<f:setPropertyActionListener target="#{CarsView.employee}" value="#{car.employeeName}"/>
<f:setPropertyActionListener target="#{CarsView.code}" value="#{car.employeeCode}"/>
<p:ajax event="click" listener="#{CarsView.onclickbutton(car)}"/>
</p:commandButton>
你可以访问&#34;汽车&#34;按照以下方法对方法进行ojbect:
public void onclickbutton(Car car)
{
System.out.println("Clicked");
System.out.println("employeeeName ==> "+car.getEmployeeName());
}