JSF模型豆没有更新为动态创建的表单域
问题描述:
我有一个表单,其中一些表单域是根据用户选择的产品动态生成的。当用户选择产品时,从数据库中提取产品的属性,并添加相应的表单字段以查看。当提交表单时,动态添加的字段的值也会发送到服务器。然而,保存动态字段的值的模型对象没有更新(使用ViewScoped) 我已经尝试了ui:repeat和p:dataGrid(我读过ui:mojarra的重复实现有问题)没有任何改变。JSF模型豆没有更新为动态创建的表单域
下面您可以看到创建动态字段的facelet。当属性列表更新时,'attributeFilterPanel'用ajax调用更新。
attributeFilters是一个Map。对于每个属性,过滤器映射都使用attribute.name作为键预填充条目。
任何帮助真的很感激。 谢谢。
注意:我正在运行Mojarra 2.2.12。
<h:panelGroup id="attributeFilterPanel">
<h:panelGroup id="filtersGroup" rendered="#{not empty attributes }">
<p:dataGrid columns="3" var="attribute" value="#{attributes}" layout="grid" paginator="false">
<h:panelGroup>
<p:outputLabel value="#{attribute.label}"/>
<p:selectOneMenu id="match_mode_${attribute.name}"
rendered="#{attribute.valueType =='STRING'}"
value="#{attributeFilters[attribute.name].matchMode}">
<f:selectItem itemValue="EQUALS" itemLabel="#{msg.equals}"/>
<f:selectItem itemValue="CONTAINS" itemLabel="#{msg.contains}"/>
<f:selectItem itemValue="STARTS_WITH" itemLabel="#{msg.startsWith}"/>
<f:selectItem itemValue="ENDS_WITH" itemLabel="#{msg.endsWith}"/>
</p:selectOneMenu>
<p:selectOneMenu id="amatch_mode_${attribute.name}"
rendered="#{attribute.valueType =='INTEGER' or attribute.valueType == 'NUMERIC'}"
value="#{attributeFilters[attribute.name].matchMode}">
<f:selectItem itemValue="EQUALS" itemLabel="#{msg.equals}"/>
<f:selectItem itemValue="LESS_OR_EQUAL" itemLabel="#{msg.lessOrEqual}"/>
<f:selectItem itemValue="GREATER_OR_EQUAL" itemLabel="#{msg.greaterOrEqual}"/>
</p:selectOneMenu>
<p:inputText id="sattribute_${attribute.name}"
rendered="#{attribute.valueType =='STRING'}"
value="#{attributeFilters[attribute.name].value}"/>
<p:inputNumber id="iattribute_${attribute.name}"
rendered="#{attribute.valueType == 'INTEGER'}" decimalPlaces="0"
value="#{attributeFilters[attribute.name].value}"/>
<p:inputNumber id="nattribute_${attribute.name}"
rendered="#{attribute.valueType == 'NUMERIC'}" decimalPlaces="3"
value="#{attributeFilters[attribute.name].value}"/>
<p:selectBooleanCheckbox id="battribute_${attribute.name}"
rendered="#{attribute.valueType == 'BOOLEAN'}"
value="#{attributeFilters[attribute.name].value}"/>
</h:panelGroup>
</p:dataGrid>
</h:panelGroup>
</h:panelGroup>
过滤器是一个简单的pojo。
public class Filter {
private String name;
private Object value;
private MatchMode matchMode;
public Filter(String name) {
this.name = name;
this.matchMode = MatchMode.EQUALS;
}
public void setValue(Object value) {
this.value = value;
}
public Object getValue() {
return value;
}
public void setMatchMode(MatchMode matchMode) {
this.matchMode = matchMode;
}
public String getName() {
return name;
}
public MatchMode getMatchMode() {
return matchMode;
}
}
答
,我可以得到它的工作是将Ajax价值变动事件每个窗体域的唯一途径。模型bean使用ajax更新进行更新。模型bean不会更新post请求,但价值变化事件会被反映出来。
<p:ajax event="valueChange" process="@this"
update="@widgetVar(productAttibuteGrid)"/>