primefaces commandbutton oncomplete未被触发

时间:2014-10-28 16:24:06

标签: jsf primefaces

我有以下代码:

XHTML:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/template.xhtml">
<ui:define name="content">

<h:form id="serviceForm">
<h3 class="title">Services</h3>
<p:growl id="msg" showDetail="true" life="3000" autoUpdate="true"/>

<h:panelGrid width="100%">
.... some code....
<p:row>
<p:column colspan="4"> 
<p:dataTable id="search" var="service" value="#{bean.services}" editable="true"> 
<p:ajax event="rowEdit" listener="#{bean.onEdit}" update=":serviceForm:msg" />
<p:ajax event="rowEditCancel" listener="#{bean.onCancel}" update=":serviceForm:msg" />    
... some rows that works fine  .....          
</p:dataTable>
</p:column>
</p:row>
<p:row>
<p:column>&#160;</p:column>
</p:row>
<p:row>
<p:column>
<h:form id="addForm">
... this call work perfectly ....
<p:commandButton id="btnAdd" value="New  Service" onclick="PF('add').show()" immediate="true"/>

<p:dialog id="add" widgetVar="add" header="Add New Service" showEffect="clip" 
hideEffect="explode" position="center,center" width="520" modal="true" closable="false"
closeOnEscape="true" resizable="false" 
>
<h:panelGrid width="100%">
<p:row>
<p:column>
<h:outputLabel value="Cve Service" />
</p:column>
</p:row>
... some another fields that works ok ...
<p:row>
<p:column>
.... HERE IS THE PROBLEM ON COMPLETE TO CLOSE DIALOG ITS NOT WORKING ...
<p:commandButton id="addServ" value="Adding" onComplete="PF('add').hide()"  actionListener="#{bean.add}"/>
.. this button its working fine
<p:commandButton immediate="true" id="cancela" value="Cancelar" onclick="PF('add').hide()" />
<p:growl id="msgAdd" showDetail="true" life="5000" autoUpdate="true"/>
</p:column>
</p:row>
</h:panelGrid>
</p:dialog>
</h:form>
</p:column> 
</p:row>

</h:panelGrid>  
</h:form>
</ui:define>

</ui:composition>

支持bean:

@ManagedBean
@ViewScoped
@SuppressWarnings("serial")
public class Bean implements Serializable{

private ServiceRemote ejb;
private Service addService;

.... some code ok ....

public void add(){

if( addService.getId().getCve() == null || addService.getId().getCve().equals("") ){

FacesContext.getCurrentInstance().addMessage( null, 
new FacesMessage(FacesMessage.SEVERITY_ERROR, 
"some title", 
"some msg."));         

}else{

Service ser = ejb.findService("some" , "some another",  null);

if(ser == null){
... some code to insert that works ok ..

int result = ejb.insertService( this.addService );

if(result > 0)
FacesContext.getCurrentInstance().addMessage( null, 
new FacesMessage(FacesMessage.SEVERITY_WARN, 
"some title", 
"some msg"
)
);
else
FacesContext.getCurrentInstance().addMessage( null, 
new FacesMessage(FacesMessage.SEVERITY_ERROR, 
"some title", 
"some text")
);

}else
FacesContext.getCurrentInstance().addMessage( null, 
new FacesMessage(FacesMessage.SEVERITY_WARN, 
"some", 
"some msg")
);

}

}
.... some getters y setters...
}

这个想法是,在执行操作之后,commandbutton关闭了打开的对话窗口,但实际上并没有发出简单的警告来查看onComplete事件是否正在触发,但我没有工作......

我尝试了几件事,可能是错的?

非常感谢。

1 个答案:

答案 0 :(得分:3)

我还没有测试,但我想解决方法是使用

oncomplete="PF('add').hide()"

我相信事件处理程序(on ...)总是完全小写。

相关问题