0

I'm facing some problems in the following scenario. I've a page where I have multiple fields and I need to add multiple item, using an autocomplete component. For instance, I've a checkout object, and I need to add different product, with quantity, into a table and others fields such as the date etc... This is the part I'm facing some problems:

<p:panelGrid columns="3" layout="grid"
                                styleClass="ui-panelgrid-blank form-group">
                                <h:panelGroup styleClass="md-inputfield">
                                    <p:autoComplete id="acEquipment"
                                        value="#{createOrderSelectionView.equipment}"
                                        completeMethod="#{createOrderSelectionView.completeTextEquipment}"
                                        style="margin-bottom:10px;" var="equipment"
                                        itemLabel="#{equipment}" converter="equipmentConverter"
                                        itemValue="#{equipment.pk}" forceSelection="true">
                                    </p:autoComplete>
                                </h:panelGroup>
                                <h:panelGroup styleClass="md-inputfield">
                                    <p:inputText value="#{createOrderSelectionView.quantity}"
                                        required="true"
                                        requiredMessage="Inserisci la quantità del materiale"
                                        label="Quantità" />
                                    <p:outputLabel value="Quantità" />
                                </h:panelGroup>
                                <h:panelGroup styleClass="md-inputfield">
                                    <p:commandButton type="reset" value="Aggiungi materiale"
                                        icon="ui-icon-plus"
                                        style="width:auto;margin-bottom:10px; float:left;"
                                        action="#{createOrderSelectionView.addEquipmentQuantity()}"
                                        update="equipmentQuantityTable">
                                        <f:ajax execute="@this" render="@form" />
                                    </p:commandButton>
                                </h:panelGroup>
                            </p:panelGrid>

This panelGrid is inside a big form, that I'm using with a command button to save the object. The beans has the following method:

public void addEquipmentQuantity() {
    System.out.println(productionOrder.getEquipmentQuantities().size());
    if (quantity != null) {
        productionOrder.getEquipmentQuantities().add(new EquipmentQuantity(quantity, equipment));
        this.equipment = null;
        this.quantity = null;
    }

    System.out.println(productionOrder.getEquipmentQuantities().size());
}

public void onRemoveEquipmentQuantity(EquipmentQuantity equipmentQuantity) {
    productionOrder.getEquipmentQuantities().remove(equipmentQuantity);
}

The problem is that the object isn't inserted in the datable; where am I wrong?

EDIT

The question was not duplicated as reported. The problem, which has been fixed by me and with the help of the comments, was due to the not correct usage of the session. For other, please use the @ViewScoped and render="@Id of the table".

I love coding
  • 1,183
  • 3
  • 18
  • 47
  • What happens on click? Is your method invoked? Why is that button `type="reset"`? – Selaron Jan 28 '19 at 14:41
  • By deleting the type="reset" the method is trigged, but there is submit operation and I lost the data of the other fields. How Can I fix? Is there a simple solution to perform some logics operations, without reload the page? – I love coding Jan 28 '19 at 14:50
  • Don't only `execute="@this" `. And you have competing ajax render advices: `render="@form"` and `update="equipmentQuantityTable"` are in conflict, I do not know who wins. – Selaron Jan 28 '19 at 14:54
  • Why does a `p:commandButton` have `f:ajax` inside it? Please read https://stackoverflow.com/questions/15267958/primefaces-command-button-vs-default-command-button and both have different update/render attribute values. This might result in weird behaviour. – Kukeltje Jan 28 '19 at 14:58
  • And please learn about creating a [mcve] when posting question (or for debugging yourself) – Kukeltje Jan 28 '19 at 15:16
  • I think the problem may be I have a big form and I submit something. I have to understand better, how to manage different forms in the same xhtml page. – I love coding Jan 29 '19 at 11:52

0 Answers0