Search in sources :

Example 1 with DataEncoderBase

use of com.liferay.faces.alloy.component.data.internal.DataEncoderBase in project liferay-faces-alloy by liferay.

the class TabViewRenderer method encodeChildren.

@Override
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // Get the "value" and "var" attributes of the TabView component and determine if iteration should take place
    // using a prototype child tab.
    TabView tabView = (TabView) uiComponent;
    Integer selectedIndex = tabView.getSelectedIndex();
    boolean iterateOverDataModel = DataEncoderBase.isIterateOverDataModel(tabView);
    // Encode the starting <ul> unordered list element that represents the list of clickable tabs.
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    responseWriter.startElement("ul", tabView);
    responseWriter.writeAttribute("class", "nav nav-tabs", null);
    DataEncoderBase dataEncoder = new DataEncoderTabHeaderImpl(selectedIndex);
    dataEncoder.encodeColumns(facesContext, tabView, iterateOverDataModel);
    responseWriter.endElement("ul");
    // Encode the starting <div> element that represents the content for the selected tab.
    responseWriter.startElement("div", uiComponent);
    responseWriter.writeAttribute("class", "tab-content", null);
    // Encode the content for each tab.
    dataEncoder = new DataEncoderTabImpl();
    dataEncoder.encodeColumns(facesContext, tabView, iterateOverDataModel);
    tabView.setRowIndex(-1);
    // Encode the closing </div> element for the content.
    responseWriter.endElement("div");
}
Also used : TabView(com.liferay.faces.alloy.component.tabview.TabView) ResponseWriter(javax.faces.context.ResponseWriter) DataEncoderBase(com.liferay.faces.alloy.component.data.internal.DataEncoderBase) DataEncoderTabImpl(com.liferay.faces.alloy.component.tab.internal.DataEncoderTabImpl)

Example 2 with DataEncoderBase

use of com.liferay.faces.alloy.component.data.internal.DataEncoderBase in project liferay-faces-alloy by liferay.

the class AccordionRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // Encode a script that will handle the client-side state of the selected tab index, as well as submitting
    // Ajax requests to support server-side events.
    Accordion accordion = (Accordion) uiComponent;
    // var accordionClientVarName = Liferay.component('{clientKey}');
    String clientVarName = getClientVarName(facesContext, accordion);
    String clientKey = accordion.getClientKey();
    if (clientKey == null) {
        clientKey = clientVarName;
    }
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
    // Expand the selected tab.
    Integer selectedIndex = accordion.getSelectedIndex();
    if ((selectedIndex != null) && (selectedIndex > -1)) {
        DataEncoderBase dataEncoder = new DataEncoderTabJavaScriptImpl(selectedIndex, clientVarName);
        dataEncoder.encodeColumns(facesContext, accordion);
    }
    // LFAI.initAccordion(multiple, accordionClientVarName, '{clientId}selectedIndex', '{clientId}',
    // [tabExpandClientBehaviorScriptFunction1, tabExpandClientBehaviorScriptFunction2,
    // tabExpandClientBehaviorScriptFunction3], '{clientId}collapsedTabIndex',
    // [tabCollapseClientBehaviorScriptFunction1, tabCollapseClientBehaviorScriptFunction2,
    // tabCollapseClientBehaviorScriptFunction3]);
    boolean multiple = accordion.isMultiple();
    String clientId = accordion.getClientId(facesContext);
    StringBuilder tabExpandedClientBehaviors = new StringBuilder();
    tabExpandedClientBehaviors.append("[");
    StringBuilder tabCollapsedClientBehaviors = new StringBuilder();
    tabCollapsedClientBehaviors.append("[");
    boolean firstTabExpandedClientBehavior = true;
    boolean firstTabCollapsedClientBehavior = true;
    Map<String, List<ClientBehavior>> clientBehaviorMap = accordion.getClientBehaviors();
    Collection<String> eventNames = accordion.getEventNames();
    for (String eventName : eventNames) {
        List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(eventName);
        if (clientBehaviorsForEvent != null) {
            for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {
                ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, accordion, eventName, clientId, null);
                // an Ajax request.
                if (TabExpandEvent.TAB_EXPAND.equals(eventName)) {
                    if (!firstTabExpandedClientBehavior) {
                        tabExpandedClientBehaviors.append(",");
                    }
                    // J-
                    // function(event) {
                    // jsf.ajax.request(this, event, {'javax.faces.behavior.event': 'tabSelect'})
                    // };
                    // J+
                    tabExpandedClientBehaviors.append("function(event){");
                    tabExpandedClientBehaviors.append(clientBehavior.getScript(clientBehaviorContext));
                    tabExpandedClientBehaviors.append("}");
                    firstTabExpandedClientBehavior = false;
                } else // an Ajax request.
                if (TabCollapseEvent.TAB_COLLAPSE.equals(eventName)) {
                    if (!firstTabCollapsedClientBehavior) {
                        tabCollapsedClientBehaviors.append(",");
                    }
                    // J-
                    // function(event) {
                    // jsf.ajax.request(this, event, {'javax.faces.behavior.event': 'tabSelect'})
                    // };
                    // J+
                    tabCollapsedClientBehaviors.append("function(event){");
                    tabCollapsedClientBehaviors.append(clientBehavior.getScript(clientBehaviorContext));
                    tabCollapsedClientBehaviors.append("}");
                    firstTabCollapsedClientBehavior = false;
                }
            }
        }
    }
    tabExpandedClientBehaviors.append("]");
    tabCollapsedClientBehaviors.append("]");
    encodeFunctionCall(responseWriter, "LFAI.initAccordion", multiple, new JavaScriptFragment(clientVarName), clientId + "selectedIndex", clientId, new JavaScriptFragment(tabExpandedClientBehaviors.toString()), clientId + "collapsedTabIndex", new JavaScriptFragment(tabCollapsedClientBehaviors.toString()));
}
Also used : ClientBehaviorContext(javax.faces.component.behavior.ClientBehaviorContext) Accordion(com.liferay.faces.alloy.component.accordion.Accordion) ResponseWriter(javax.faces.context.ResponseWriter) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) DataEncoderBase(com.liferay.faces.alloy.component.data.internal.DataEncoderBase) List(java.util.List) ClientBehavior(javax.faces.component.behavior.ClientBehavior)

Example 3 with DataEncoderBase

use of com.liferay.faces.alloy.component.data.internal.DataEncoderBase in project liferay-faces-alloy by liferay.

the class TabViewRenderer method encodeJavaScriptCustom.

@Override
public void encodeJavaScriptCustom(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    // Encode a script that will handle the client-side state of the selected tab index, as well as submitting
    // Ajax requests to support server-side events.
    TabView tabView = (TabView) uiComponent;
    // var tabViewClientVarName = Liferay.component('{clientKey}');
    String clientVarName = getClientVarName(facesContext, tabView);
    String clientKey = tabView.getClientKey();
    if (clientKey == null) {
        clientKey = clientVarName;
    }
    ResponseWriter responseWriter = facesContext.getResponseWriter();
    encodeLiferayComponentVar(responseWriter, clientVarName, clientKey);
    // Enable the enabled tabs, disable the disabled tabs, and select the selected tab on the client side.
    Integer selectedIndex = tabView.getSelectedIndex();
    DataEncoderBase dataEncoder = new DataEncoderTabJavaScriptImpl(selectedIndex, clientVarName);
    dataEncoder.encodeColumns(facesContext, tabView);
    // LFAI.initTabView(tabViewClientVarName, '{clientId}selectedIndex', '{clientId}',
    // [tabSelectClientBehaviorScriptFunction1, tabSelectClientBehaviorScriptFunction2,
    // tabSelectClientBehaviorScriptFunction3]);
    String clientId = uiComponent.getClientId(facesContext);
    String hiddenFieldId = clientId + "selectedIndex";
    StringBuilder clientBehaviorsArrayStringBuilder = new StringBuilder();
    clientBehaviorsArrayStringBuilder.append("[");
    boolean first = true;
    Map<String, List<ClientBehavior>> clientBehaviorMap = tabView.getClientBehaviors();
    Collection<String> eventNames = tabView.getEventNames();
    for (String eventName : eventNames) {
        List<ClientBehavior> clientBehaviorsForEvent = clientBehaviorMap.get(eventName);
        if (clientBehaviorsForEvent != null) {
            for (ClientBehavior clientBehavior : clientBehaviorsForEvent) {
                ClientBehaviorContext clientBehaviorContext = ClientBehaviorContext.createClientBehaviorContext(facesContext, tabView, eventName, clientId, null);
                // an Ajax request.
                if (TabSelectEvent.TAB_SELECT.equals(eventName)) {
                    if (!first) {
                        clientBehaviorsArrayStringBuilder.append(",");
                    }
                    // J-
                    // function(event) {
                    // jsf.ajax.request(this, event, {'javax.faces.behavior.event': 'tabSelect'})
                    // };
                    // J+
                    clientBehaviorsArrayStringBuilder.append("function(event){");
                    clientBehaviorsArrayStringBuilder.append(clientBehavior.getScript(clientBehaviorContext));
                    clientBehaviorsArrayStringBuilder.append("}");
                    first = false;
                }
            }
        }
    }
    clientBehaviorsArrayStringBuilder.append("]");
    encodeFunctionCall(responseWriter, "LFAI.initTabView", new JavaScriptFragment(clientVarName), hiddenFieldId, clientId, new JavaScriptFragment(clientBehaviorsArrayStringBuilder.toString()));
}
Also used : TabView(com.liferay.faces.alloy.component.tabview.TabView) ClientBehaviorContext(javax.faces.component.behavior.ClientBehaviorContext) ResponseWriter(javax.faces.context.ResponseWriter) JavaScriptFragment(com.liferay.faces.util.render.JavaScriptFragment) DataEncoderBase(com.liferay.faces.alloy.component.data.internal.DataEncoderBase) List(java.util.List) ClientBehavior(javax.faces.component.behavior.ClientBehavior)

Example 4 with DataEncoderBase

use of com.liferay.faces.alloy.component.data.internal.DataEncoderBase in project liferay-faces-alloy by liferay.

the class AccordionRenderer method encodeChildren.

@Override
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    Accordion accordion = (Accordion) uiComponent;
    Integer selectedIndex = accordion.getSelectedIndex();
    DataEncoderBase dataEncoder = new DataEncoderTabMarkupImpl(selectedIndex);
    dataEncoder.encodeColumns(facesContext, accordion);
    accordion.setRowIndex(-1);
}
Also used : Accordion(com.liferay.faces.alloy.component.accordion.Accordion) DataEncoderBase(com.liferay.faces.alloy.component.data.internal.DataEncoderBase)

Example 5 with DataEncoderBase

use of com.liferay.faces.alloy.component.data.internal.DataEncoderBase in project liferay-faces-alloy by liferay.

the class DataListRenderer method encodeChildren.

@Override
public void encodeChildren(FacesContext facesContext, UIComponent uiComponent) throws IOException {
    DataList dataList = (DataList) uiComponent;
    UIComponent facet = dataList.getFacet(DESCRIPTION);
    String itemTag = "li";
    String type = dataList.getType();
    if (DESCRIPTION.equals(type)) {
        itemTag = "dt";
    }
    DataEncoderBase dataEncoder = new DataEncoderDataItemImpl(facet, itemTag);
    dataEncoder.encodeColumns(facesContext, dataList);
}
Also used : DataList(com.liferay.faces.alloy.component.datalist.DataList) UIComponent(javax.faces.component.UIComponent) DataEncoderBase(com.liferay.faces.alloy.component.data.internal.DataEncoderBase)

Aggregations

DataEncoderBase (com.liferay.faces.alloy.component.data.internal.DataEncoderBase)5 ResponseWriter (javax.faces.context.ResponseWriter)3 Accordion (com.liferay.faces.alloy.component.accordion.Accordion)2 TabView (com.liferay.faces.alloy.component.tabview.TabView)2 JavaScriptFragment (com.liferay.faces.util.render.JavaScriptFragment)2 List (java.util.List)2 ClientBehavior (javax.faces.component.behavior.ClientBehavior)2 ClientBehaviorContext (javax.faces.component.behavior.ClientBehaviorContext)2 DataList (com.liferay.faces.alloy.component.datalist.DataList)1 DataEncoderTabImpl (com.liferay.faces.alloy.component.tab.internal.DataEncoderTabImpl)1 UIComponent (javax.faces.component.UIComponent)1