public CommandRendererHelper(final FacesContext facesContext, final AbstractUICommandBase base, final Tag tag) {
if (!(base instanceof AbstractUICommand)) {
return;
}
final AbstractUICommand command = (AbstractUICommand) base;
disabled = ComponentUtils.getBooleanAttribute(command, Attributes.DISABLED);
if (disabled) {
onclick = "";
href = "";
} else {
href = "#"; // this is to make the link "active", needed for focus, cursor, etc.
final UIPopup popup = (UIPopup) command.getFacet(Facets.POPUP);
if (popup != null) {
if (!ComponentUtils.containsPopupActionListener(command)) {
command.addActionListener(new PopupFacetActionListener());
}
}
final boolean transition = ComponentUtils.getBooleanAttribute(command, Attributes.TRANSITION);
if (StringUtils.isNotEmpty(command.getLink()) || StringUtils.isNotEmpty(command.getResource())) {
final String url = RenderUtils.generateUrl(facesContext, command);
if (tag == Tag.ANCHOR) {
onclick = null;
href = url;
target = command.getTarget();
} else {
// TODO target
onclick = "Tobago.navigateToUrl('" + url + "');";
}
} else if (StringUtils.isNotEmpty(command.getOnclick())) {
onclick = prepareOnClick(facesContext, command);
} else if (command.getRenderedPartially().length > 0) {
final String clientId = command.getClientId(facesContext);
final String[] componentIds = command.getRenderedPartially();
// TODO find a better way
final boolean popupAction = ComponentUtils.containsPopupActionListener(command);
if (popupAction) {
if (componentIds.length != 1) {
LOG.warn("more than one partially rendered component is not supported for popup! using first one: "
+ Arrays.toString(componentIds));
}
onclick = "Tobago.Popup.openWithAction(this, '"
+ HtmlRendererUtils.getComponentId(facesContext, command, componentIds[0]) + "', '" + clientId + "');";
} else {
onclick = "Tobago.reloadComponent(this, '"
+ HtmlRendererUtils.getComponentIds(facesContext, command, componentIds) + "','" + clientId + "', {});";
}
} else {
final String clientId = command.getClientId(facesContext);
final String target = ComponentUtils.getStringAttribute(command, Attributes.TARGET);
onclick = HtmlRendererUtils.createSubmitAction(clientId, transition, target, null);
}
if (command.getAttributes().get(Attributes.POPUP_CLOSE) != null
&& ComponentUtils.isInPopup(command)) {
final String value = (String) command.getAttributes().get(Attributes.POPUP_CLOSE);
if (value.equals("immediate")) {
onclick = "Tobago.Popup.close(this);";
} else if (value.equals("afterSubmit")
&& command instanceof org.apache.myfaces.tobago.component.UICommand
&& ((org.apache.myfaces.tobago.component.UICommand) command).getRenderedPartially().length > 0) {