我需要将打开的对话框中的值传递给'parent'bean,
从formBean打开新对话框
@Named(value = FormBean.NAME)
@SessionScoped //or @ViewScoped from omnifaces
public class FormBean extends AbstractBean implements Serializable {
public static final String NAME = "formBean";
@Getter @Setter private boolean updateRequest = false;
@Getter @Setter private String value;
// in some method open dialog
AbstractDialogBean.openDialog(type.getUrl());
public void fillView(ComponentSystemEvent event) {
if(!getFacesContext().isPostback()) {
initialRequest();
} else {
postBackRequest();
}
}
private void postBackRequest() {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, ":" value);
if(updateRequest) {
Ajax.updateAl();
}
}
}
AbstractDialogBean中的
public static void openDialog(String dialogFilePath) {
Map<String, Object> opt = new HashMap() {{
put("modal", true);
put("resizable", false);
}};
RequestContext.getCurrentInstance().openDialog(dialogFilePath, opt, null);
}
一个对话框文件
<ui:composition template="/page.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:cp="http://xmlns.jcp.org/jsf/composite"
xmlns:jl="http://xmlns.jcp.org/jsf/composite/jsflive"
xmlns:fn="http://xmlns.jcp.org/jsp/jstl/functions"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<ui:define name="title">#{locationBean.getTitle()}</ui:define>
<ui:define name="pageContent">
<h:form id="as">
<p:panelGrid columns="2">
<p:outputLabel id="dataLabel" value="data"/>
<p:inputText id="data" value="#{locationBean.value}"/>
</p:panelGrid>
<p:toolbarGroup>
<p:commandButton id="ok" value="ok" actionListener="#{locationBean.actionListener}"/>
<p:commandButton id="cancel" value="cancel" actionListener="#{locationBean.actionListener}"/>
</p:toolbarGroup>
</h:form>
</ui:define>
</ui:composition>
提交ok按钮后,我需要从locationBean将数据值传递给formBean; 但是formBean中的postBackRequest()在locationBean中的actionListener()之前执行,而formBean中的值为null
LocationBean代码;
@Named(value = LocationBean.NAME)
@RequestScoped
public class LocationBean extends AbstractDialogBean implements Serializable {
public static final String NAME = "locationBean";
@Getter private FormBean formBean;
@Getter @Setter private String value;
@PostConstruct
private void init() {
formBean = getFacesContext().getApplication().evaluateExpressionGet(getFacesContext(), "#{" + FormBean.NAME + "}", FormBean.class);
}
public void actionListener(ActionEvent event) {
if (event.getComponent().getId().equals("ok")) {
formBean.setValue(value); //try to pass entered value into mainBean
formBean.setUpdateRequest(true);
}
RequestContext.getCurrentInstance().closeDialog(event.getSource());
}
}