私はJSF2とTomcatサーバーを使用しています。私は、ここで簡単な例をプログラム:<h:selectBooleanCheckbox>の値はバッキングBeanの値に応じて更新されません
- ユーザが「H:selectOneMenu」から教員を選択する選択すると
- 、「H:のinputText」の値が基づいて「奇数」または「偶数」に変更されますfacultyNo また
- 、の選択時に、値「H:selectBooleanCheckBoxは」:のinputText facultyNoが偶数で、facultyNoが奇数の場合
すべては「時間正常に動作し、「チェックしない」場合は「確認」に変更され"一方、 "h:selectBooleanCheckBox"の値は変更されません。なぜこうなった?私が働いているプロジェクトは、HashMapの中にブール値の多くを持っているのでところで
は、HashMapの内部ブール値の使用は意図的です。だから、ハッシュマップを単純なブール値のプロパティに置き換え、getterとsetterを使用することは、私の場合の解決策ではありません。
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">
<head>
<title>Dummy Title</title>
</head>
<body>
<h:form>
<label for="faculty">Faculty</label>
<h:selectOneMenu id="faculty" value="#{test.selectedFaculty}" converter="faccon" valueChangeListener="#{test.facultyChange}" onchange="submit()">
<f:selectItems value="#{start.app.faculties}"/>
</h:selectOneMenu>
<h:selectBooleanCheckbox id="mycheck" value="#{test.x.get(0)}"></h:selectBooleanCheckbox>
<h:outputText value="#{test.res}"></h:outputText>
<h:commandButton value="Save" action="#{test.saveChoices}" />
</h:form>
</body>
</html>
バッキングBeanのコードは
import java.io.Serializable;
import java.util.HashMap;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ValueChangeEvent;
import com.myWork.Application;
import com.myWork.Faculty;
@ManagedBean(name="test")
@RequestScoped
public class TestBean implements Serializable
{
private HashMap<Integer,Boolean> x;
private String res;
private Faculty selectedFaculty;
@PostConstruct
public void init(){
Application app = Application.getInstance();
selectedFaculty = app.getFaculties()[0];
x = new HashMap<Integer, Boolean>();
if (selectedFaculty.getFacultyNo()%2==0)
{
x.put(0, true);
res = "even";
}
else
{
x.put(0, false);
res = "odd";
}
}
public HashMap<Integer,Boolean> getX() {
return x;
}
public void setX(HashMap<Integer,Boolean> x) {
this.x = x;
}
public Faculty getSelectedFaculty() {
return selectedFaculty;
}
public void setSelectedFaculty(Faculty selectedFaculty) {
this.selectedFaculty = selectedFaculty;
}
public String getRes() {
return res;
}
public void setRes(String res) {
this.res = res;
}
public void facultyChange(ValueChangeEvent e){
Faculty fac = (Faculty) e.getNewValue();
if (fac.getFacultyNo()%2==0)
{
x.put(0, true);
res = "even";
}
else
{
x.put(0, false);
res = "odd";
}
}
public String saveChoices(){
return "test";
}
}
未満である任意の助けを大幅に高く評価されています。
は、私はこのAkashさんを理解managedBean –