Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Now you are doing:</p> <ol> <li>Sending single <code>Id</code> to the <code>processAction</code> method</li> <li>Executing the action based on the button <code>edit</code> or <code>delete</code></li> </ol> <p>You want:</p> <ol> <li>Select multiple check-boxes</li> <li>Click <code>Delete</code> button somewhere</li> <li>All the selected items gets deleted</li> </ol> <p>Solution (there might be many other ways):</p> <ol> <li><p>You checkbox should be like this:</p> <pre><code>&lt;input type="checkbox" name="&lt;portlet:namespace/&gt;row_sel" class="row_sel" value="&lt;%=temprest.getPrimaryKey() %&gt;" /&gt; </code></pre> <p>If you use <code>&lt;aui:input /&gt;</code> tags you won't have to bother about prepending the <code>name</code> attribute with <code>&lt;portlet:namespace/&gt;</code></p></li> <li><p>Collecting all the <code>Id</code>s in a hidden input field <code>&lt;input type="hidden" name="&lt;portlet:namespace/&gt;allCheckedIds" /&gt;</code> with comma-separated format and then sending it to the server.</p></li> <li>This can be done using javascript, on click of the <code>Delete</code> button call a javascript method which would construct a string of all the <code>Id</code>s from the checked check-box's values. You can take help of <a href="http://www.javascript-coder.com/javascript-form/javascript-get-check.phtml" rel="nofollow">this link</a> to construct the javascript method.</li> <li>Then <code>submit</code> the <code>form</code> with the help of the javascript method itself.</li> <li><p>Then in your <code>processAction</code> method you can separate the <code>Id</code>s from the comma-separated string received as:</p> <pre><code>String allIds = ParamUtil.getString(actionRequest, "allCheckedIds"); //allIds = "1,2,3,4,5,6"; // this is how the Ids might look long[] idArray = StringUtil.split(allIds, ",", 0); // were 0 is the default value </code></pre></li> <li><p>Now pass these Ids to the service layer to delete them.</p></li> </ol> <p>That's it. Simple isn't it.</p> <p>There is also a similar method used by liferay, you can check the <code>Document Library Display</code> portlet for this. If you use <code>&lt;liferay-ui:searchContainer&gt;</code> to display your list then you can take advantage of how liferay does this for you.</p> <p>I will provide some pointers in this direction, you can check the source:<br> <a href="https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/portlet/document_library_display/view_file_entries.jspf" rel="nofollow"><code>view_file_entries.jspf</code></a>, check out the line <a href="https://github.com/liferay/liferay-portal/blob/6.1.x/portal-web/docroot/html/portlet/document_library_display/view_file_entries.jspf#L43" rel="nofollow"><code>rowChecker="&lt;%= entriesChecker %&gt;"</code></a> whick creates the check-boxes for you and then check-out [<code>'&lt;portlet:namespace /&gt;deleteEntries'][4],</code> javascript method which actually sends the request to the action class. There are jsps and action classes which you can check-out, but I will that upto you to explore. :-)</p> <p>Happy Exploring.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload