I'm stuck on this current Problem, maybe somebody can help me out on this: I try to build a dynamic Ruleseditor based on JSF 2.2 and the latest primefaces version (5.0). Therefor I construct a p:dataTable which display rule values in seperate columns. To edit the values the Editor generates a pickable Valuelist from the used database table.
Everything works fine but if I try to select another value in the pickable value list and click the save Button the old Value is submitted to the bean and the h:selectOneMenu display the last used value.
I tried many solutions but this is the current on JSF Side:
<h:form id="ruleTableForm">
<p:dataTable value="#{table.rules}" var="rule">
<p:columns var="column" value="#{table.columns}" headerText="#{column.header}" width="250">
<h:selectOneMenu id="columnSelectMenu" value="#{rule.ruleColumnToValueMap[column].value}">
<f:selectItems value="#{column.pickList.entrySet()}"
var="pickItem" itemLabel="#{pickItem.value}"
itemValue="#{pickItem.key}" />
</h:selectOneMenu>
</p:columns>
</p:dataTable>
<div class="button_group">
<h:commandLink styleClass="add_button" action="#{regelEditorViewController.saveRuleset()}">Save</h:commandLink>
</div>
</h:form>
The parts used in the xhtml-File from my ViewController look like this:
@ManagedBean
@ViewScoped
public class RegelEditorViewController implements Serializable {
private RegelEditorViewData viewData;
@Produces
public RegelEditorViewData getViewData() {
if (this.viewData == null) {
this.viewData = this.viewDataService.produceViewData(0L,20L);
}
return this.viewData;
}
public void saveRuleset() {
RulesetViewData rulesetViewData = this.viewData.getCurrentRuleset();
this.viewDataService.saveRuleset(rulesetViewData);
this.refreshViewData();
}
}
The ruleColumnToValueMap is a Map:
private Map<RuleTableColumnViewData, Value> ruleColumnToValueMap = new LinkedHashMap<RuleTableColumnViewData, Value>();
...and the "pickList" in the "ruleTableColumnViewData"-object is also a Map with Strings:
private Map<String, String> pickList = new LinkedHashMap<String, String>();
The solutions I tried and but do not worked:
work with an ajax setter, which select the value (but the value is null in the setter method)
<f:ajax listener="#{regelEditorViewController.selectedRuleColumnValueChanged(table, rule, column, rule.ruleColumnToValueMap[column].value)}" render="@form" />
work with an immediate ajax setter, which sends always the last setted value to the bean:
<f:ajax listener="#{regelEditorViewController.selectedRuleColumnValueChanged(table, rule, column, rule.ruleColumnToValueMap[column].value)}" immediate="true" render="@form" />
tried to work with p:selectOneMenu but it seems to be very buggy: it is not possible to change the selected item, the component do not show a menu
tried to work with "SelectItem" in a "pickList" List and a "SelectItem" for the column in the "ruleColumnToValueMap" Map
Maybe someone have a possible solution that can help me?
Primefaces have an row/cell editor, but that thing do not help, because it also do not set the client information to the viewdata objects. – Bomber Bob Jul 10 '14 at 07:07