One approach would be to use callback parameters.
Code: Select all
<f:facet name="footer">
<p:commandButton value="View" image="ui-icon ui-icon-search"
action="#{theBean.handleViewClicked}" update="form:display" oncomplete="handleViewComplete(xhr, status, args)"/>
</f:facet>
public String handleViewClicked() {
RequestContext.getCurrentInstance().addCallbackParam("isCarSelected", getSelectedCar() != null);
return null;
}
<script type="text/javascript">
function handleViewComplete(xhr, status, args) {
if(args.isCarSelected)
carDialog.show();
else
alert("Please select a car.");
}
</script>
Another approach would be to define a widgetVar for the dataTable and use the widgetVars undocumented selection array to find out if something is selected in JavaScript. If something is selected call carDialog.show(), if not, tell the user to select something first.The selection array is empty if nothing is selected.