使用素数面可以生成一个对话框并设置一个窗体来控制渲染内容。示例代码如下:
public void enterGroup(){
if(!AuthorizationUtils.isUserInRoles(new String[]{"UPDATER"})){
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_FATAL,
"Error", "The user does not have permissions to perform this
action."));
return;
}
else{
Map<String,Object> options = new HashMap<String, Object>();
options.put("resizable", false);
options.put("draggable", false);
options.put("modal", true);
options.put("width", 500);
options.put("height", 90);
options.put("contentWidth", "100%");
options.put("contentHeight", "100%");
PrimeFaces.current().dialog().openDynamic("entergroup",options,null);
}
}
我的问题是,是否有人知道是否有一种方法可以控制对话框被X’ed掉时发生的事情,而不是由用户在对话框上执行操作。我知道你可以将closable设置为false并完全消除X,但这并不完全是用户友好的。我只需要能够在点击X时重置我的对话框,或者执行一个方法来清除我的一些Beans,我想知道是否有办法做到这一点。任何帮助都将不胜感激!我已经包含了下面的xhtml,如果这有助于绘画的话。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 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">
<h:head>
<title>Enter the Name of the new group</title>
<style type="text/css">
.ui-widget {
font-size: 90%;
}
</style>
</h:head>
<h:body>
<div class="main">
<h:form method="post">
<p:panelGrid columns="3" styleClass="ui-noborder">
<p:outputLabel for="newgroupname" value="Group Name: ">
</p:outputLabel>
<p:inputText id="newgroupname" value="#{addgroup.newGroupName}"
/>
<p:commandButton action="#{addgroup.addNewGroup}"
value="Submit"></p:commandButton>
</p:panelGrid>
<h:outputText value="#{addgroup.dialogMessage}" style="color: red;">
</h:outputText>
</h:form>
</div>
</h:body>
</html>
你可以用这种巧妙的方法:
MyBean.java
:
import static java.util.Collections.emptyMap;
import java.util.HashMap;
import java.util.Map;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import org.primefaces.PrimeFaces;
@Named
@RequestScoped
public class MyBean {
public void dfShow() {
Map<String, Object> options = new HashMap<>();
// ...
PrimeFaces.current().dialog().openDynamic("entergroup", options, emptyMap());
}
public void dfClosed() {
PrimeFaces.current().dialog().closeDynamic("X");
}
}
在你的entergroup.xhtml
:
<h:body>
<h:outputScript>
$(document).ready(function(){
// try to get a reference to the DF widget from top window context:
var dfWidgetVar = window.top.$('[data-pfdlgcid]').attr('data-widgetvar');
var dfWidget = window.top.PF(dfWidgetVar);
// clear closeIcon click event listener stack and add your remoteCommand:
dfWidget.closeIcon.unbind('click').on('click', dfClosed);
});
</h:outputScript>
<h:form>
...
<p:remoteCommand name="dfClosed" action="#{myBean.dfClosed}"/>
</h:form>
</h:body>