Primefaces p:tabView内的confirmDialog
我现在在tabView中使用confirmDialog有问题。 这是我的确认对话框Primefaces p:tabView内的confirmDialog,primefaces,dialog,confirm,tabview,Primefaces,Dialog,Confirm,Tabview,我现在在tabView中使用confirmDialog有问题。 这是我的确认对话框 <p:confirmDialog global="true" showEffect="fade" hideEffect="explode"> <h:form> <p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-ico
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
<h:form>
<p:commandButton value="Yes" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</h:form>
</p:confirmDialog>
在第一个选项卡视图中,我有一个带有确认的按钮
<p:commandButton value="Import" icon="ui-icon-arrowrefresh-1-w"
update=":form:growl">
<p:confirm header="Confirmation" message="Are you sure?" />
</p:commandButton>
在第二个选项卡视图中,我正好有那个按钮
现在我的问题是:在第一个选项卡中,我的confirmDialog有我想要的全文:标题和消息,但是在第二个选项卡中,标题和消息都变为“null”。只有confirmDialog的“是”和“否”按钮仍然有效。我不知道发生了什么,请帮助我,如何使confirmDialog在所有选项卡视图中显示全部内容这似乎对我来说是可行的。见下面的例子
<?xml version="1.0" encoding="UTF-8"?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>JSF User Dialog</title>
</h:head>
<h:body>
<h3>This is a JSF view.</h3>
<h:form id="form">
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode">
<h:form>
<p:commandButton value="Yes" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
<p:commandButton value="No" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</h:form>
</p:confirmDialog>
<p:tabView id="tabView">
<p:tab id="tab1" title="Tab one ">
<p:commandButton value="Import" icon="ui-icon-arrowrefresh-1-w"
update=":form">
<p:confirm header="Confirmation" message="Are you sure?" />
</p:commandButton>
</p:tab>
<p:tab id="tab2" title="Tab two">
<p:commandButton value="Import" icon="ui-icon-arrowrefresh-1-w"
update=":form">
<p:confirm header="Confirmation" message="Are you sure?" />
</p:commandButton>
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>
JSF用户对话框
这是一个JSF视图。
输出:
如果您发布完整的xhtml代码,这样我们就可以看到可能存在的问题了。我对该组件也有同样的问题。建议的删除动态true的解决方案有效,但当我们必须在对话框中工作时,由于数据不再自动更新,导致字段为空,因此无法满足要求。 如果发生这种情况,您必须执行以下操作。 例:
p:confirm没有实现状态保存,因此它在第一个JSF生命周期后会丢失其属性值。它也只在视图构建时计算EL一次 如何修复状态保存。 您可以扩展PrimeFaces的
confirmeHavior
,实现saveState
,restoreState
,并通过行为idorg.PrimeFaces.behavior.confirmeHavior
覆盖faces-config.xml中的原始行为。然后,您将能够在后续请求中渲染和重新渲染p:confirm
如何修复状态保存和重新评估EL绑定属性值。
您应该创建自己的my:confirm,因为您需要一个自定义标记处理程序,并且不能以非丑陋的方式替换另一个taglibrary标记的标记处理程序
创建确认行为。
包我的;
导入javax.faces.FacesException;
导入javax.faces.component.UIComponent;
导入javax.faces.component.behavior.ClientBehaviorContext;
导入javax.faces.context.FacesContext;
导入org.primefaces.behavior.base.AbstractBehavior;
导入org.primefaces.component.api.Confirmable;
导入org.primefaces.json.JSONObject;
公共类ConfirmBehavior扩展了抽象行为{
公共最终静态字符串行为\u ID=“my.ConfirmBehavior”;
@凌驾
公共字符串getScript(ClientBehaviorContext behaviorContext){
FacesContext context=behaviorContext.getFacesContext();
UIComponent=behaviorContext.getComponent();
字符串source=component.getClientId(上下文);
字符串headerText=JSONObject.quote(this.getHeader());
字符串messageText=JSONObject.quote(this.getMessage());
if(可确认的组件实例){
String script=“PrimeFaces.confirm({source:\”“+source+”\”,标题:“+headerText+”,消息:“
+messageText+,图标:\“”+getIcon()+“\”});返回false;“;
((可确认)组件).setConfirmationScript(脚本);
返回null;
}否则{
抛出新的FacesException(“组件”+源+”不是可确认的。ConfirmBehavior只能是“
+“附加到实现org.primefaces.component.api.Confirmable接口的组件”);
}
}
公共字符串getHeader(){
返回eval(PropertyKeys.header,null);
}
公共void setHeader(字符串头){
setLiteral(PropertyKeys.header,header);
}
公共字符串getMessage(){
返回eval(PropertyKeys.message,空);
}
公共无效设置消息(字符串消息){
setLiteral(PropertyKeys.message,message);
}
公共字符串getIcon(){
返回eval(PropertyKeys.icon,null);
}
公共无效设置图标(字符串图标){
setLiteral(PropertyKeys.icon,icon);
}
公共枚举属性{
标题(String.class)、消息(String.class)、图标(String.class);
最后一节课预期类型;
PropertyKeys(类expectedType){
this.expectedType=expectedType;
}
}
@凌驾
受保护的枚举[]getAllProperties(){
返回PropertyKeys.values();
}
}
创建ConfirmBehaviorHandler。
包我的;
导入javax.faces.application.application;
导入javax.faces.view.facelets.BehaviorConfig;
导入javax.faces.view.facelets.FaceletContext;
导入javax.faces.view.facelets.TagAttribute;
导入org.primefaces.behavior.base.AbstractBehaviorHandler;
公共类ConfirmBehaviorHandler扩展了AbstractBehaviorHandler{
私有最终标记属性头;
私有属性消息;
私有属性图标;
公共ConfirmBehaviorHandler(行为配置){
超级(配置);
this.header=this.getAttribute(confirbehavior.PropertyKeys.header.name());
this.message=this.getAttribute(confirbehavior.PropertyKeys.message.name());
this.icon=this.getAttribute(confirbehavior.PropertyKeys.icon.name());
}
@凌驾
受保护的ConfirmBehavior createBehavior(FaceletContext ctx,字符串eventName){
Application Application=ctx.getFacesContext().getApplication();
confirbehavior行为=(confirbehavior)application.createBehavior(confirbehavior.behavior_ID);
setBehaviorAttribute(ctx,behavior,this.header,ConfirmBehavior.PropertyKeys.header.expe
<p:commandButton style="font-size: 12px;width:30px;height:20px;" icon="ui-icon-trash">
<p:confirm header="Confirmação" message="Você realmente quer excluir o item de despacho?" icon="ui-icon-alert" />
</p:commandButton>
<p:growl id="growl" showDetail="true" />
<p:confirmDialog global="true" showEffect="fade" hideEffect="explode" style="font-size: 12px;" closeOnEscape="true" widgetVar="confir">
<p:commandButton id="confirm" value="Sim" ajax="true" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" style="font-size: 12px;">
<p:ajax event="click" listener="#{tableExpedicao.excluiItem}" update="confirm" oncomplete="confir.hide()"> </p:ajax>
</p:commandButton>
<p:commandButton value="Não" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" style="font-size: 12px;" oncomplete="confir.hide()"/>
</p:confirmDialog>