Search code examples
javascriptjavanetui

After creating an array of anchors using netui repeater how do I call a method which will take the anchor id and execute a query


Initially I load the result of a query(select * from table_name) in a pageflow variable a. The query returns an array, now for each object returned in the array I added anchors using netui-data repeater. I kept an anchor to delete the object from the database, however I don't know how I can do so.

Here's the form of the jsp which has the code

<netui:form action="load_answer_main">
<netui:anchor action="add_bot" value="Add Bot"/>
<table id="t4" class="example table-autosort table-autofilter table-autopage:20000 table-page-number:t4page table-page-count:t4pages table-filtered-rowcount:t4filtercount table-rowcount:t4allcount">
        <tr><td>Answer Bot Name</td> <td>Utterances</td> <td>Type</td> <td>Action</td>
        </tr>
        <netui-data:repeater dataSource="pageFlow.a"> 
        <netui-data:repeaterItem>
        <tbody>
            <tr>
            <td style="font-weight:bold;font-size:16px;">   <netui:label value="${container.item.bot_name}" /> </td>            
            <td style="font-weight:bold;font-size:16px;">   <netui:label value="${container.item.utterances}" /> </td>
            <td style="font-weight:bold;font-size:16px;">   <netui:label value="${container.item.bot_type}" /> </td>
            <td> <netui:anchor value="Delete Bot" action="delete_bot" tagId="${container.item.id}"/></td>
            </tr>
            </netui-data:repeaterItem>
            </netui-data:repeater>
        </tbody>
    </table>
</netui:form>

Here is the controller method I want to call where id should be passed from the jsp.

public Forward delete_bot(AnswerForm form){ 
        //TODO Pass ID in the delete action
        try {
            ma.deleteAnswerBot(id);
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return new Forward("home");
    }

I'm using Oracle Workshop for Weblogic as my IDE.

Appreciate any input or advice.


Solution

  • So basically we needed to set a parameter in the jsp say id which can be set to the id which was in the database.

    <netui-data:repeater dataSource="pageFlow.ld">
    <netui-data:repeaterItem>
    <netui:anchor value="${container.item.rd.name}" action="getCharts">
    <netui:parameter name="id" value="${container.item.rd.id}"/>
    </netui:anchor>
    </netui-data:repeaterItem>
    </netui-data:repeater>
    

    Then in the controller we can access this parameter in the request.

    int request_source = Integer.parseInt(this.getRequest().getParameter("id"));