In the last week I had the task to delete selected items from the component <af: selectManyShuttle>, which are e-mail addresses of users:
In this case, I would like to have removed the addresses 3Email@gmail.com and 4Email@gmail.com. Of course, other values of the list must be unchanged.
I have not found any listeners for component <af: selectManyShuttle>, which I could use so I used a little workaround.
I have not found any listeners for component <af: selectManyShuttle>, which I could use so I used a little workaround.
1 2 3 4 5 6 7 8 9 | <af:selectManyShuttle autoSubmit="true" leadingHeader=" " trailingHeader=" " id="sms2" value="#{pageFlowScope.harmonogramManagementMB.selectedMailsList}"> <f:selectItems value="#{pageFlowScope.harmonogramManagementMB.allMailsListSI}" id="shjki6a"/> <af:clientAttribute name="preventNoteWindow" value="true"/> </af:selectManyShuttle> <af:commandButton text="DELETE HIGHLIGHTES USERS" id="cb22" rendered="#{!pageFlowScope. harmonogramManagementMB.addingMailRecipient}"> <af:clientListener method=" ksed.deleteHighligtedUser" type="action"/> <af:serverListener type="deleteSelectedEmails" method="#{pageFlowScope.harmonogramManagementMB.deleteEmails}"/> </af:commandButton> |
The "DELETE highlightes USERS" calls the js function ksed.deleteHighligtedUser, which extracts a list of selected emails and calls serverListener that performs the method deleteEmails:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ksed.deleteHighligtedUser = function(ev){ try { var selectedEmails = jQuery('.af_selectManyShuttle_item.p_AFSelected '); var emails = []; for(var i=0; i<selectedEmails.length; i++) { emails.push(selectedEmails[i].innerText); } AdfCustomEvent.queue(ev.getSource(), "deleteSelectedEmails", {"emails":emails}, true); } catch(err) { tpl.log(err); } } |
1 2 3 4 5 6 7 8 9 10 | public String deleteEmails(ClientEvent event) { List<String> emailsList =(List<String>)event.getParameters().get("emails"); if(emailsList!=null && emailsList.size()>0){ //DELETING EMAILS FROM DB onRemoveMailRecipientButton(emailsList); } return null; } |
Of course, we also need to manually delete selected values:
1 2 3 4 5 6 7 8 9 10 11 | Iterator<SelectItem> it = allMailsListSI.iterator(); while(it.hasNext()){ SelectItem nextValue = it.next(); emails.contains(nextValue); } Iterator<String> it1 = selectedMailsList.iterator(); while(it1.hasNext()){ String nextValue = it1.next(); emails.contains(nextValue); } |
But it is not everything. During the execution of these methods I encountered two problems. Firstly, after returning to the view displays some adf validation issue:
We can delete it after the creation ControllerClass for the view. In pageDefinition we add:
1 2 3 4 | <pageDefinition xmlns="http://xmlns.oracle.com/adfm/uimodel" version="11.1.1.64.93" id="adminPanelPageDef" ControllerClass="pl.energa.portal.src.view.controllers.HarmonogramController" Package="oracle.webcenter.portalapp.pages.adminPanel"> |
And the we create the Controller:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | public class HarmonogramController implements PagePhaseListener { public HarmonogramController() { super(); } public void afterPhase(PagePhaseEvent pagePhaseEvent) { } public void beforePhase(PagePhaseEvent pagePhaseEvent) { FacesContext ctx = FacesContext.getCurrentInstance(); Iterator<FacesMessage> it = ctx.getMessages(); if(it!=null){ while(it.hasNext()){ FacesMessage fm = it.next(); LoggerHelper.logInfo(fm.getDetail()); System.out.println(fm.getDetail()); if("Enter a value that matches this pattern: {2}".equalsIgnoreCase(fm.getDetail())){ it.remove(); } } } } } |
Of course, when changing localization will change the name of the statement, so hardcodding here is not recommended.
The second problem is that, if removed element is not the last element in the list of selected items.
the next element of the left window jumps to a selection on the right which is wrong. To correct this, we can set a flag in method deleteEmails, which prevents in setter set bad values:
1 2 3 4 5 6 7 | public void setSelectedMailsList(List<String> selectedMailsList) { if(deleteUser){ deleteUser = false; return; } this.selectedMailsList = selectedMailsList; } |
No comments:
Post a Comment