사용자가 선택한 제품을 기반으로 양식 필드가 동적으로 생성되는 양식이 있습니다. 사용자가 제품을 선택하면 데이터베이스의 속성이 가져오고 해당 양식 필드가 추가되어 표시됩니다. 양식이 제출되면 동적으로 추가 된 필드의 값도 서버로 전송됩니다. 그러나 동적 필드 의 값을 유지하는 모델 객체는으로 업데이트되지 않습니다. (ViewScoped가 사용됩니다.) 나는 ui : repeat와 p : dataGrid를 모두 시도했습니다. (moiarra의 반복 구현에는 문제가 있습니다.) 변경된 사항은 없습니다.동적으로 작성된 양식 필드에 대해 JSF 모델 Bean이 갱신되지 않습니다.
아래에서 동적 필드를 만드는 facelet을 볼 수 있습니다. 속성 목록이 업데이트되면 'attributeFilterPanel'이 ajax 호출로 업데이트됩니다.
attributeFilters는지도입니다. 각 속성에 대해 필터 맵은 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;
}
}