Using the selection AJAX event to handle item selection on the server side.
Right-click here to select a Node action
▶Node1
Create Node1 Action1
Create Node1 Action2
▶Node2
Create Node2 Action1
Create Node2 Action2
Source
<h:panelGroup id="paletteTarget" layout="block"
style="border:2px solid #c8c8c8; border-radius:3px; padding:40px; text-align:center; cursor:context-menu;
background:#f9f9f9; font-size:14px; color:#555; user-select:none;">
Right-click here to select a Node action
</h:panelGroup>
<pe:commandPalette id="palette2" for="paletteTarget"
label="Nodes" filterPlaceholder="Search nodes..." width="260">
<pe:commandPaletteItem group="Node1" value="1" label="Create Node1 Action1"
itemTitle="Creates a new Node1 action"/>
<pe:commandPaletteItem group="Node1" value="2" label="Create Node1 Action2"
itemTitle="Creates another Node1 action"/>
<pe:commandPaletteItem group="Node2" value="3" label="Create Node2 Action1"
itemTitle="Creates a new Node2 action"/>
<pe:commandPaletteItem group="Node2" value="4" label="Create Node2 Action2"
itemTitle="Creates another Node2 action"/>
<p:ajax event="select" listener="#{commandPaletteController.onItemSelect}"
update="messages"/>
</pe:commandPalette>
@Named
@ViewScoped
public class CommandPaletteController implements Serializable {
private static final long serialVersionUID = 1L;
public void onItemSelect(final SelectEvent<CommandPaletteSelection> event) {
final CommandPaletteSelection selection = event.getObject();
final FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_INFO,
"Item Selected",
"Group: " + selection.getGroup()
+ ", Value: " + selection.getValue()
+ ", Label: " + selection.getLabel());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}