0
我正在使用JSF2.0並構建嚮導。我遇到了SelectBooleanCheckboxes的問題。這裏是工作流程:SelectBooleanCheckbox呈現狀態與後臺bean不匹配
- 加載帶有複選框的頁面(值綁定到支持bean中的SortedMap)。
- 勾選它們,然後單擊下一步。這增加了一個光標,頁面用來確定哪個PanelGroup的負載。
- (正確)值被持久化到bean。
- 點擊返回(光標減少),頁面呈現可編輯的複選框。第一個複選框不勾選(儘管綁定變量對於該框保持true值)。
這種基於光標的方法(其中包含所有的嚮導屏幕)似乎不起作用。但是,如果我稍微修改此以便prev/next按鈕顯示不同的xhtml頁面,則此問題將消失。
不幸的是我不能這樣做。我們將把這個嚮導插入到一個模式對話框中,所以在prev/next上訪問一個新頁面將不起作用
我已經寫了一個這樣的小例子(而不是要求你瀏覽整個嚮導) 。
下面是Java類:
@ConversationScoped
@Named("hashBool")
public class HashBoolTest2 implements Serializable {
private static final long serialVersionUID = 1962031429874426411L;
@Inject private Conversation conversation;
private List<RestrictionItem> list;
private SortedMap<String, Boolean> values;
private int cursor;
public HashBoolTest2() {
List<String> none = new ArrayList<String>();
none.add("");
this.setList(new ArrayList<RestrictionItem>());
this.getList().add(new RestrictionItem("a", "a", none));
...
this.getList().add(new RestrictionItem("e", "e", none));
this.setValues(new TreeMap< String, Boolean >());
this.setCursor(0);
}
@PostConstruct
public void andThis() {
this.conversation.begin();
}
// getters and setters for instance variables
@Override
public String toString() {
return "Values : " + this.values.toString() + " List: " + this.list.toString();
}
public void kill() {
this.conversation.end();
}
public void doNext(ActionEvent e) {
this.cursor++;
}
public void doPrev(ActionEvent e) {
this.cursor--;
}
}
這裏是XHTML片段:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:c="http://java.sun.com/jsp/jstl/core">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>IGNORED</title>
</head>
<body>
<ui:composition>
<h:panelGroup id="container">
<h:form>
<!-- edit state -->
<h:panelGroup id="edit" rendered="#{hashBool.cursor eq 0}">
<code>
<h:outputText value="#{hashBool.toString()}" escape="false"/>
</code>
<ul>
<ui:repeat value="#{hashBool.list}" var="elem">
<li>
<h:selectBooleanCheckbox id="elem" value="#{hashBool.values[elem.id]}" title="#{elem.displayName}" />
<h:outputLabel for="elem" value="#{elem.displayName}"/>
</li>
</ui:repeat>
</ul>
</h:panelGroup>
<!-- view state -->
<h:panelGroup id="view" rendered="#{hashBool.cursor eq 1}">
<code>
<h:outputText value="#{hashBool.toString()}" escape="false"/>
</code>
</h:panelGroup>
<br/>
<!-- buttons -->
<h:panelGroup id="buttons">
<f:ajax render=":container">
<h:commandButton value="Prev" actionListener="#{hashBool.doPrev}"/>
<h:commandButton value="Next" actionListener="#{hashBool.doNext}"/>
</f:ajax>
<h:commandButton value="Kill" actionListener="#{hashBool.kill()}"/>
</h:panelGroup>
</h:form>
</h:panelGroup>
</ui:composition>
</body>
</html>
任何建議,歡迎! (對不起,如果這是一個雙後,我已經能夠找到類似的東西,而在這裏搜索)
如果必須使用Liferay/Glassfish,請使用6.1 GA 1捆綁包。 – asellitt 2012-01-22 23:36:00