ui: For table rows created with repeat, press the f:ajax Add button to add rows.

Asked 2 years ago, Updated 2 years ago, 125 views

ui: I'd like to add more rows to the table row that I created with repeat.

The line is added, but the entire table is redrawn, so the value being entered disappears.
テーブルThe table uses jquery datatable.

Add rows to the list in MnagedBean, add rows only to tables in HTML, and
How can I prevent other lines from being redrawn?
I'm in trouble because I don't know.
I would appreciate it if you could let me know.

ajax jsf

2022-09-30 18:12

1 Answers

Thank you for watching.Excuse me, please.

<table jsf:id="tableid">
    <thead>
        <tr>
            <th>AAA</th>
            <th>BBB</th>
            <th>CCC</th>
        </tr>
    </thead>
    <tbody jsf:id="tbodyid">
        <ui: repeat id="repeatid" varStatus="sts" var="record" value="#{XXXXBean.dataList}">
            <trjsf:id="trid">
                <td>
                    <input type="text" jsf:value="#{record.aaa}" jsf:id="recordaaa" />
                </td>
                <td>
                    <input type="text" jsf:value="#{record.bb}"jsf:id="recordbb"/>
                </td>
                <td>
                    <input type="text" jsf:value="#{record.cccc}" jsf:id="recordccc"/>
                </td>
            </tr>
        </ui: repeat>
    </tbody>
</table>

<f:ajax execute="@this" listener="#{XXXXBean.addRow}" render="tbodyid">
    <h:commandButton id="addbtn" value="addbtn" />
</f:ajax>

****XXXXBean.java********************************************************************

@Named("XXXXBean")
@SessionScoped
public class XXXXBean extensions BaseBean {
    private List <dataListBean>dataList=null;

    // Initial display processing
    @ PostConstruct
    public void init() {
        // Add only one line
        dataList = new ArrayList <>();
        dataList.add (new dataListBean());
        dataList.get(0).setAaa(1);
        dataList.get(0).setBbb(1);
        dataList.get(0).setCcc(1);
    }

    // Add Row
    public void addRow() {
        dataList.add (new dataListBean());
    }

    publicList<dataListBean>getDataList(){
        return dataList;
    }

    public void setDataList(List<dataListBean>dataList){
        This.dataList=dataList;
    }
}

********************************************************************************************

public class dataListBean{
    private int aaa;
    private int bbb;
    private int ccc;

    public int getAa(){
        return aaa;
    }
    public void setAaa(intaaa){
        This.aaa = aaa;
    }
    public int getBbb(){
        return bbb;
    }
    public void setBbb(intbbb){
        This.bbb = bbb;
    }
    public int getCcc(){
        return ccc;
    }
    public void setCcc(intcccc){
        This.ccc =cc;
    }
}


2022-09-30 18:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.