我对 JSF 页面上的可能 AJAX 有疑问。他没有调用bean方法。转换器工作并返回一个正确的对象,但 bean 方法不调用。如果我删除执行部分方法调用。如果我删除转换器并仅发送 Id 方法调用。他们一起失败了。
JSF 页面
<h:form id="jewelForm">
<!-- ... -->
<h:selectOneMenu id="material" value="#{jewelBean.material}" >
<f:converter converterId="materialConverter"/>
<f:selectItems value="#{jewelBean.materialList}" var="c"
itemLabel="#{c.name}" itemValue="#{c.id}" />
</h:selectOneMenu>
<h:commandButton id="but1" value="#{titles.addThisMat}">
<f:ajax id ="aj1"
listener="#{jewelBean.addMaterial}"
render="jewelForm:matTable"
execute="material"/>
</h:commandButton>
<h:dataTable id ="matTable"
</h:dataTable>
<h:commandButton value="#{titles.createThisJ}"
action="#{jewelBean.saveJewel()}" />
</h:form>
豆
@ManagedBean(name = "jewelBean")
@SessionScoped
public class JewelBean implements Serializable {
private Material material;
public void addMaterial() {
MaterialJewel mj = new MaterialJewel();
mj.setMaterial(material);
mj.setWeight(materialWeight);
materialJewels.add(mj);
}
public Material getMaterial() {
return material;
}
public void setMaterial(Material material) {
this.material = material;
}
}
转换器
@FacesConverter("materialConverter")
public class materialConverter implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
try {
//finding object with DAO
return material;
}
} catch (NumberFormatException ex) {
}
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return value.toString();
}
}
感谢您的评论。