在我看来,我的侦听器具有ajax行为,该行为会更新bean属性,然后是执行javascript方法的“未完成”动作
这是ajax事件:
<p:ajax event="rowDblselect" listener="#{backController.onRowDoubleClick}"
oncomplete="openNewTab()" />
<h:inputHidden id="hutchy" value="#{backController.productViewerUrl}" />
这是应该更新属性的bean方法:
public void onRowDoubleClick(final SelectEvent event) {
RecordDTO currentRecordDTO = (RecordDTO) event.getObject();
setProductViewerUrl("https://www.google.com/search?q=" + currentRecordDTO.getName());
}
public String getProductViewerUrl() {
return productViewerUrl;
}
public void setProductViewerUrl(String productViewerUrl) {
this.productViewerUrl = productViewerUrl;
}
此后,使用更新属性的javascript方法:
function openNewTab(){
var url = $('#pbm\\:hutchy').val();
var hiddenCode = "#{backController.productViewerUrl}";
alert(url + hiddenCode);
window.open(url, '_newtab');
}
问题是Javascript代码没有获得属性的更新值(即使带有隐藏字段),我在DoubleClick事件之后进行了一些调试,发现执行未通过执行JS时属性的getter方法(在警报之前)
有人有想法吗?预先感谢!
答案 0 :(得分:0)
Try using <f:param name="productViewerUrl" value="#{backController.productViewerUrl}" />
then getting the value in the Bean with
FacesContext fc = FacesContext.getCurrentInstance();
Map<String, String> params = fc.getExternalContext().getRequestParameterMap();
this.productViewerUrl= params.get("productViewerUrl");
or binding the values in the datatable
答案 1 :(得分:0)
I found a pretty solution for this one, just perform an update to the hidden field after the ajax event so that the view consider the new value of the bean property like:
<p:ajax event="rowDblselect" listener="#{backController.onRowDoubleClick}"
update="form:hutchy" oncomplete="openNewTab()" />