Primables Datatable and InputText Element for Creating a Dynamic Form

I have a question about using inputText element in datatable format.

Xhtml looks below

<h:form >
                 <h:panelGrid columns="2">
                    <p:commandButton action="#{offerController.addNewOfferRow}" update="panel1" id="iconOnly1"  
           icon="ui-icon-circle-plus" value="Yeni Satır" title="Icon Add"  style="width:220px;" /> 


                 </h:panelGrid>
                <p:dataTable id="panel1" var="offer" value="#{offerController.offerIds}"  style="align: center;">
                    <p:column id="modelHeader"  style=" margin-left: auto; margin-right: auto; width:70%;" >
                        <f:facet name="header">
                            Eklenecek Offerlar
                        </f:facet>

                        <p:inputText id="addOfferId" value="#{offer}"   style=" margin-left: auto; margin-right: auto; width:70%;"  />

                    </p:column>


                </p:dataTable>

And my java bean looks like this:

@ManagedBean
@ViewScoped


public class OfferController implements Serializable{

    /**
     * 
     */

    private static final long serialVersionUID = -1552493989687233258L;
    private static final int defaultNumberOfRows = 6;
    private List<String> offerIds = new LinkedList<String>();


    public OfferController() {
         super();
    for(int i=0;i<defaultNumberOfRows;i++){
        offerIds.add("");
         }

    }

    public void addOffers(){
         // do some op.
    }

    public void addNewOfferRow(){
         offerIds.add("");
    }

    public getOfferIds(){
         return offerIds;
    }

    public setOfferIds(List<String> offerIds){
          this.offerIds = offerIds;
    }


}

When using the above codes. I want to display a list of string elements in inputText elements that are in a datatable.

And the addNewOfferRow operation adds a new item to the list, and the datatable is updated on the client side.

However, after submitting the form, all inputText elements do not retain the values ​​entered by the user.

How can I use this dtatable end inputText element to create a dynamic string form.

Thank.

+3
source share
1 answer

( ), inputText .

, .

<p:dataTable var="item" value="#{listBean.list}">
     <p:column>
         <p:inputText value="#{item.name}" />
     </p:column>
</p:dataTable>
0

All Articles