In my project, on click of checkbox and add more button, I am trying to add one row and on click of remove button, remove exact row.
Sometimes I get wrong parameter valu
There is no logical bug in my code. It was just JSF
bug in older version.
As per BalusC's comment, I have followed these steps :
Mojarra
(jsf-api-2.2.9.jar
,jsf-impl-2.2.10.jar
) in JBoss AS 7.1
. Refer thisc:forEach
loop to ui:repeat
and h:dataTable
in JSF page.var
instead of index
in method parameter.Now, the new changed code is looked something like this :
Index.xhtml
<h:form id="form">
<h:panelGroup id="shipmentTermsBox">
<ui:repeat value="#{postOffer.shipmentTerms}" var="shipment">
<h:selectBooleanCheckbox value="#{shipment.status}">
<f:ajax event="change" listener="#{postOffer.addShipmentTermsRow(shipment)}" render=":form:shipmentTermsBox" />
</h:selectBooleanCheckbox>
<label for="stayin">#{shipment.name} </label> <br/>
<h:dataTable var="shipmentRow" value="#{shipment.shipmentRowList}">
<h:column>
<h:selectOneMenu value="#{shipmentRow.priceChoice}">
<f:selectItem itemValue="Above Price" itemLabel="Above Price"/>
<f:selectItem itemValue="+ (more)" itemLabel="+ (more)"/>
<f:selectItem itemValue="- (more)" itemLabel="- (more)"/>
<f:ajax event="change" listener="#{postOffer.processPriceDiffChoice(shipmentRow)}" render=":form:shipmentTermsBox"/>
</h:selectOneMenu>
</h:column>
<h:column>
<h:panelGroup rendered="#{shipmentRow.priceEnable}">
<h:inputText value="#{shipmentRow.price}">
<f:ajax/>
</h:inputText>
</h:panelGroup>
</h:column>
<h:column>
<h:commandButton value="Remove">
<f:ajax event="action" listener="#{postOffer.removeShipmentTermsRow(shipment,shipmentRow)}" render=":form:shipmentTermsBox"/>
</h:commandButton>
</h:column>
</h:dataTable>
<h:panelGroup rendered="#{shipment.status}">
<h:commandButton value="Add More">
<f:ajax event="action" listener="#{postOffer.addShipmentTermsRow(shipment)}" render=":form:shipmentTermsBox"/>
</h:commandButton>
<br/><br/>
</h:panelGroup>
</ui:repeat>
</h:panelGroup>
</h:form>
PostOffer.java
public void processPriceDiffChoice(ShipmentRow row) {
if (row.getPriceChoice().equals("Above Price")) {
row.setPriceEnable(false);
} else {
row.setPriceEnable(true);
}
}
public void addShipmentTermsRow(ShipmentProxy proxy) {
if (proxy.isStatus()) {
proxy.getShipmentRowList().add(new ShipmentRow());
} else {
proxy.getShipmentRowList().clear();
}
}
public void removeShipmentTermsRow(ShipmentProxy proxy,ShipmentRow row) {
proxy.getShipmentRowList().remove(row);
}
Note : Rest of the code is same exactly mentioned in question.