@Override protected String getLinkStyleClass(MenuItem menuitem) { String icon = menuitem.getIcon(); if (icon == null) { icon = "ui-icon-carat-r"; } String iconPos = menuitem.getIconPos(); iconPos = (iconPos == null) ? "ui-btn-icon-right" : "ui-btn-icon-" + iconPos; String styleClass = AbstractMenu.MOBILE_MENUITEM_LINK_CLASS + " " + icon + " " + iconPos; String userStyleClass = menuitem.getStyleClass(); if (userStyleClass != null) { styleClass = styleClass + " " + userStyleClass; } return styleClass; }
protected String getLinkStyleClass(MenuItem menuItem) { String styleClass = menuItem.getStyleClass(); return (styleClass == null) ? AbstractMenu.MENUITEM_LINK_CLASS : AbstractMenu.MENUITEM_LINK_CLASS + " " + styleClass; }
@Override public void decode(FacesContext context, UIComponent component) { AbstractMenu menu = (AbstractMenu) component; String clientId = menu.getClientId(context); Map<String, String> params = context.getExternalContext().getRequestParameterMap(); if (params.containsKey(clientId)) { String menuid = params.get(clientId + "_menuid"); MenuItem menuitem = findMenuitem(menu.getElements(), menuid); MenuActionEvent event = new MenuActionEvent(menu, menuitem); if (menuitem.isImmediate()) event.setPhaseId(PhaseId.APPLY_REQUEST_VALUES); else event.setPhaseId(PhaseId.INVOKE_APPLICATION); menu.queueEvent(event); } }
protected void encodeMenuItemContent(FacesContext context, AbstractMenu menu, MenuItem menuitem) throws IOException { ResponseWriter writer = context.getResponseWriter(); String icon = menuitem.getIcon(); Object value = menuitem.getValue(); if (icon != null) { writer.startElement("span", null); writer.writeAttribute("class", AbstractMenu.MENUITEM_ICON_CLASS + " " + icon, null); writer.endElement("span"); } writer.startElement("span", null); writer.writeAttribute("class", AbstractMenu.MENUITEM_TEXT_CLASS, null); if (value != null) { if (menuitem.isEscape()) writer.writeText(value, "value"); else writer.write(value.toString()); } else if (menuitem.shouldRenderChildren()) { renderChildren(context, (UIComponent) menuitem); } writer.endElement("span"); }
protected void setConfirmationScript(FacesContext context, MenuItem item) { if (item instanceof ClientBehaviorHolder) { Map<String, List<ClientBehavior>> behaviors = ((ClientBehaviorHolder) item).getClientBehaviors(); List<ClientBehavior> clickBehaviors = (behaviors == null) ? null : behaviors.get("click"); if (clickBehaviors != null && !clickBehaviors.isEmpty()) { for (int i = 0; i < clickBehaviors.size(); i++) { ClientBehavior clientBehavior = clickBehaviors.get(i); if (clientBehavior instanceof ConfirmBehavior) { ClientBehaviorContext cbc = ClientBehaviorContext.createClientBehaviorContext( context, (UIComponent) item, "click", item.getClientId(), Collections.EMPTY_LIST); clientBehavior.getScript(cbc); break; } } } } }
protected void encodeMenuItem(FacesContext context, AbstractMenu menu, MenuItem menuitem) throws IOException { ResponseWriter writer = context.getResponseWriter(); String title = menuitem.getTitle(); String style = menuitem.getStyle(); boolean disabled = menuitem.isDisabled(); String rel = menuitem.getRel(); writer.startElement("a", null); writer.writeAttribute("tabindex", "-1", null); if (shouldRenderId(menuitem)) { writer.writeAttribute("id", menuitem.getClientId(), null); } if (title != null) { writer.writeAttribute("title", title, null); } String styleClass = this.getLinkStyleClass(menuitem); if (disabled) { styleClass = styleClass + " ui-state-disabled"; } writer.writeAttribute("class", styleClass, null); if (style != null) { writer.writeAttribute("style", style, null); } if (rel != null) { writer.writeAttribute("rel", rel, null); } if (disabled) { writer.writeAttribute("href", "#", null); writer.writeAttribute("onclick", "return false;", null); } else { setConfirmationScript(context, menuitem); String onclick = menuitem.getOnclick(); // GET if (menuitem.getUrl() != null || menuitem.getOutcome() != null) { String targetURL = getTargetURL(context, (UIOutcomeTarget) menuitem); writer.writeAttribute("href", targetURL, null); if (menuitem.getTarget() != null) { writer.writeAttribute("target", menuitem.getTarget(), null); } } // POST else { writer.writeAttribute("href", "#", null); UIComponent form = ComponentTraversalUtils.closestForm(context, menu); if (form == null) { throw new FacesException("MenuItem must be inside a form element"); } String command; if (menuitem.isDynamic()) { String menuClientId = menu.getClientId(context); Map<String, List<String>> params = menuitem.getParams(); if (params == null) { params = new LinkedHashMap<String, List<String>>(); } List<String> idParams = new ArrayList<String>(); idParams.add(menuitem.getId()); params.put(menuClientId + "_menuid", idParams); command = menuitem.isAjax() ? buildAjaxRequest(context, menu, (AjaxSource) menuitem, form, params) : buildNonAjaxRequest(context, menu, form, menuClientId, params, true); } else { command = menuitem.isAjax() ? buildAjaxRequest(context, (AjaxSource) menuitem, form) : buildNonAjaxRequest( context, ((UIComponent) menuitem), form, ((UIComponent) menuitem).getClientId(context), true); } onclick = (onclick == null) ? command : onclick + ";" + command; } if (onclick != null) { if (menuitem.requiresConfirmation()) { writer.writeAttribute("data-pfconfirmcommand", onclick, null); writer.writeAttribute("onclick", menuitem.getConfirmationScript(), "onclick"); } else { writer.writeAttribute("onclick", onclick, null); } } } encodeMenuItemContent(context, menu, menuitem); writer.endElement("a"); }