我的基于IceFaces 1.8的应用程序以一个非常简单的xhtml开头,其中包含一个基于bean属性的不同的xhtml。此属性绑定到每个页面中包含的组合项。如果用户从此组合中选择布局,则页面将更新为新布局。
没关系,除了在每次单页布局更改后,布局选择器组合中的项目都会重复,重复三次等等。
这是“多路复用器”xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<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:ice="http://www.icesoft.com/icefaces/component">
<ui:include src="#{system.layout}">
</ui:include>
</html>
这是布局选择器,包含在每个布局xhtml中:
<ice:form id="layoutSelectForm">
<ice:outputLabel for="layoutSelector">#{msgs['LayoutSelect.Label']}: </ice:outputLabel>
<ice:selectOneMenu id="layoutSelector" binding="#{layoutSelect.som}" value="#{layoutSelect.selectedLayout}"
valueChangeListener="#{layoutSelect.processValueChange}" partialSubmit="true">
<f:selectItems value="#{layoutSelect.allLayouts}" />
</ice:selectOneMenu >
</ice:form>
以下是LayoutSelect支持bean的代码:
public class JSFLayoutSelect implements InitializingBean, ValueChangeListener {
private EventManager eventManager;
private String mainApplFrmURL;
private HtmlSelectOneMenu som;
public List<SelectItem> allLayouts;
private String selectedLayout;
@Override
public void processValueChange(ValueChangeEvent event)
throws AbortProcessingException {
eventManager.publish("layout-select/change", event.getNewValue());
logger.info("Layout changed event occured: " + event.getNewValue());
try {
FacesContext.getCurrentInstance().getExternalContext().redirect(mainApplFrmURL);
} catch (IOException e) {
logger.error(e.getMessage());
}
}
@Override
public void afterPropertiesSet() throws Exception {
allLayouts = new ArrayList<SelectItem>();
allLayouts.add(new SelectItem("dev", "Core Dev"));
allLayouts.add(new SelectItem("classic", "Core Classic"));
allLayouts.add(new SelectItem("modern", "Core Modern"));
selectedLayout = "dev";
}
public List<SelectItem> getAllLayouts() {
return allLayouts;
}
public String getSelectedLayout() {
return selectedLayout;
}
/* some unimportant methods are not here */
}
<bean name="layoutSelect" class="hu.hgap.comp.impl.JSFLayoutSelect" scope="session">
<property name="eventManager" ref="SessionEventManager"/>
<property name="mainApplFrmURL" value="/ICEFacesSpringDemoV2/secured/ApplFrm.faces" />
</bean>
你能告诉我怎么做才能避免重复组合条目吗?我看到在更改布局后,再次呈现相同的组合,并再次从服务器将组合项目推入其中。
答案 0 :(得分:0)
你的支持豆是什么样子的?它有哪个范围?
我在会话范围bean中有类似的绑定变量经验。当我将变量移动到请求scopre bean时,问题就消失了。