@Override public void decode(FacesContext context, UIComponent component) { CommandLink link = (CommandLink) component; if (link.isDisabled()) { return; } String param = component.getClientId(); if (context.getExternalContext().getRequestParameterMap().containsKey(param)) { component.queueEvent(new ActionEvent(component)); } }
@Override public void encodeEnd(FacesContext context, UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); CommandLink link = (CommandLink) component; String clientId = link.getClientId(context); Object label = link.getValue(); if (!link.isDisabled()) { String request; boolean ajax = link.isAjax(); String styleClass = link.getStyleClass(); styleClass = styleClass == null ? CommandLink.STYLE_CLASS : CommandLink.STYLE_CLASS + " " + styleClass; RequestContext requestContext = RequestContext.getCurrentInstance(); boolean csvEnabled = requestContext.getApplicationContext().getConfig().isClientSideValidationEnabled() && link.isValidateClient(); StringBuilder onclick = new StringBuilder(); if (link.getOnclick() != null) { onclick.append(link.getOnclick()).append(";"); } String onclickBehaviors = getOnclickBehaviors(context, link); if (onclickBehaviors != null) { onclick.append(onclickBehaviors); } writer.startElement("a", link); writer.writeAttribute("id", clientId, "id"); writer.writeAttribute("href", "#", null); writer.writeAttribute("class", styleClass, null); if (link.getTitle() != null) { writer.writeAttribute("aria-label", link.getTitle(), null); } if (ajax) { request = buildAjaxRequest(context, link, null); } else { UIComponent form = ComponentUtils.findParentForm(context, link); if (form == null) { throw new FacesException( "Commandlink \"" + clientId + "\" must be inside a form component"); } request = buildNonAjaxRequest(context, link, form, clientId, true); } if (csvEnabled) { CSVBuilder csvb = requestContext.getCSVBuilder(); request = csvb.init() .source("this") .ajax(ajax) .process(link, link.getProcess()) .command(request) .build(); } onclick.append(request); if (onclick.length() > 0) { if (link.requiresConfirmation()) { writer.writeAttribute("data-pfconfirmcommand", onclick.toString(), null); writer.writeAttribute("onclick", link.getConfirmationScript(), "onclick"); } else writer.writeAttribute("onclick", onclick.toString(), "onclick"); } renderPassThruAttributes(context, link, HTML.LINK_ATTRS, HTML.CLICK_EVENT); if (label != null) writer.writeText(label, "value"); else renderChildren(context, link); writer.endElement("a"); } else { String styleClass = link.getStyleClass(); styleClass = styleClass == null ? CommandLink.DISABLED_STYLE_CLASS : CommandLink.DISABLED_STYLE_CLASS + " " + styleClass; writer.startElement("span", link); writer.writeAttribute("id", clientId, "id"); writer.writeAttribute("class", styleClass, "styleclass"); if (link.getStyle() != null) writer.writeAttribute("style", link.getStyle(), "style"); if (label != null) writer.writeText(label, "value"); else renderChildren(context, link); writer.endElement("span"); } }