use of com.liferay.faces.alloy.component.commandlink.CommandLink in project liferay-faces-alloy by liferay.
the class CommandLinkRenderer method processEvent.
@Override
public void processEvent(ComponentSystemEvent componentSystemEvent) throws AbortProcessingException {
CommandLink commandLink = (CommandLink) componentSystemEvent.getComponent();
// If the specified event indicates that the command link was added to the component tree, then
if (componentSystemEvent instanceof PostAddToViewEvent) {
// Add the default Ajax behavior in order to support the ajax attribute. This effectively simulates the
// presence of a child f:ajax tag.
RendererUtil.addDefaultAjaxBehavior(commandLink, commandLink.getExecute(), commandLink.getProcess(), "@all", commandLink.getRender(), commandLink.getUpdate(), "@none");
} else // Otherwise, the specified event indicates that the command link is about to be rendered. If the ajax
// attribute is true, then ensure that the AjaxBehavior is rendered. Otherwise, ensure that the AjaxBehavior is
// not rendered.
{
AjaxBehavior ajaxBehavior = RendererUtil.getDefaultAjaxBehavior(commandLink);
ajaxBehavior.setDisabled(!commandLink.isAjax());
}
}
use of com.liferay.faces.alloy.component.commandlink.CommandLink in project liferay-faces-alloy by liferay.
the class PaginatorRenderer method encodeUnorderedListItem.
protected void encodeUnorderedListItem(FacesContext facesContext, ResponseWriter responseWriter, Paginator paginator, String clientId, String paginatorAction, String text, boolean enabled, boolean current) throws IOException {
// Encode the starting <li> element that contains the Bootstrap pagination control.
responseWriter.startElement("li", paginator);
// If the pagination control is enabled, then
if (enabled) {
// If the alloy:paginator has a nested f:ajax tag, then encode a hyperlink that contains the client
// behavior script in the onclick attribute.
String clientBehaviorScript = getClientBehaviorScript(facesContext, paginator, clientId, paginatorAction);
if (clientBehaviorScript != null) {
responseWriter.startElement("a", paginator);
responseWriter.writeAttribute("href", "javascript:void(0);", null);
responseWriter.writeAttribute("onclick", clientBehaviorScript, null);
responseWriter.write(text);
responseWriter.endElement("a");
} else // Otherwise, encode an alloy:commandLink that can submit the form via full-page postback.
{
Application application = facesContext.getApplication();
CommandLink commandLink = (CommandLink) application.createComponent(facesContext, CommandLink.COMPONENT_TYPE, CommandLink.RENDERER_TYPE);
commandLink.setAjax(paginator.isAjax());
OutputText outputText = (OutputText) application.createComponent(facesContext, OutputText.COMPONENT_TYPE, OutputText.RENDERER_TYPE);
List<UIComponent> paginatorChildren = paginator.getChildren();
paginatorChildren.add(commandLink);
UIParameter uiParameter = new UIParameter();
String paginatorActionParamName = clientId.concat("_paginatorAction");
uiParameter.setName(paginatorActionParamName);
uiParameter.setValue(paginatorAction);
List<UIComponent> commandLinkChildren = commandLink.getChildren();
commandLinkChildren.add(uiParameter);
commandLinkChildren.add(outputText);
outputText.setEscape(false);
outputText.setValue(text);
commandLink.encodeAll(facesContext);
commandLinkChildren.remove(outputText);
commandLinkChildren.remove(uiParameter);
paginatorChildren.remove(commandLink);
}
} else // Otherwise, since the pagination control is not enabled, simply encode a span containing the label of the
// control.
{
if (current) {
responseWriter.writeAttribute("class", "active", null);
} else {
responseWriter.writeAttribute("class", "disabled", null);
}
responseWriter.startElement("span", paginator);
responseWriter.write(text);
responseWriter.endElement("span");
}
// Encode the closing <li> element that contains the Bootstrap pagination link.
responseWriter.endElement("li");
}
use of com.liferay.faces.alloy.component.commandlink.CommandLink in project liferay-faces-alloy by liferay.
the class DataTableRenderer method encodeHeaderText.
protected void encodeHeaderText(FacesContext facesContext, ResponseWriter responseWriter, DataTable dataTable, Column column, String headerText) throws IOException {
ValueExpression sortByValueExpression = column.getValueExpression("sortBy");
if (sortByValueExpression == null) {
responseWriter.writeText(headerText, column, null);
} else {
responseWriter.startElement("div", dataTable);
responseWriter.writeAttribute("class", "table-sort-liner", null);
// If the alloy:column has a nested f:ajax tag, then encode a hyperlink that contains the client
// behavior script in the onclick attribute.
String dataTableClientId = dataTable.getClientId(facesContext);
String clientBehaviorScript = getColumnClientBehaviorScript(facesContext, dataTable, column, dataTableClientId);
if (clientBehaviorScript != null) {
// Write the client behavior script in the onclick attribute on the <div> element because writing it on
// the <a> element will have the side-effect of a new browser tab opening for each sort column that is
// selected with Left Click + Meta.
responseWriter.writeAttribute("onclick", clientBehaviorScript, null);
responseWriter.startElement("a", null);
responseWriter.writeText(headerText, null);
responseWriter.startElement("span", dataTable);
responseWriter.writeAttribute("class", "table-sort-indicator", null);
responseWriter.endElement("span");
responseWriter.endElement("a");
} else // Otherwise, encode an alloy:commandLink that can submit the form via full-page postback.
{
Application application = facesContext.getApplication();
CommandLink commandLink = (CommandLink) application.createComponent(facesContext, CommandLink.COMPONENT_TYPE, CommandLink.RENDERER_TYPE);
commandLink.setAjax(column.isAjax());
OutputText outputText1 = (OutputText) application.createComponent(facesContext, OutputText.COMPONENT_TYPE, OutputText.RENDERER_TYPE);
outputText1.setValue(headerText);
OutputText outputText2 = (OutputText) application.createComponent(facesContext, OutputText.COMPONENT_TYPE, OutputText.RENDERER_TYPE);
outputText2.setStyleClass("table-sort-indicator");
List<UIComponent> paginatorChildren = column.getChildren();
paginatorChildren.add(commandLink);
UIParameter uiParameter = new UIParameter();
String sortColumnClientIdParamName = dataTableClientId.concat("_sortColumnClientId");
uiParameter.setName(sortColumnClientIdParamName);
uiParameter.setValue(column.getClientId(facesContext));
List<UIComponent> commandLinkChildren = commandLink.getChildren();
commandLinkChildren.add(uiParameter);
commandLinkChildren.add(outputText1);
commandLinkChildren.add(outputText2);
outputText2.setEscape(false);
commandLink.encodeAll(facesContext);
commandLinkChildren.remove(outputText2);
commandLinkChildren.remove(outputText1);
commandLinkChildren.remove(uiParameter);
paginatorChildren.remove(commandLink);
}
responseWriter.endElement("div");
}
}
Aggregations