Search in sources :

Example 1 with TabView

use of com.liferay.faces.alloy.component.tabview.TabView in project liferay-faces-alloy by liferay.

the class TabViewRenderer method decodeClientState.

@Override
public void decodeClientState(FacesContext facesContext, UIComponent uiComponent) {
    // Apply the client-side state of the selected index.
    TabView tabView = (TabView) uiComponent;
    String hiddenFieldName = tabView.getClientId(facesContext) + "selectedIndex";
    Map<String, String> requestParameterMap = facesContext.getExternalContext().getRequestParameterMap();
    String selectedIndex = requestParameterMap.get(hiddenFieldName);
    if (selectedIndex != null) {
        tabView.setSelectedIndex(IntegerHelper.toInteger(selectedIndex, -1));
    }
}
Also used : TabView(com.liferay.faces.alloy.component.tabview.TabView)

Example 2 with TabView

use of com.liferay.faces.alloy.component.tabview.TabView 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 3 with TabView

use of com.liferay.faces.alloy.component.tabview.TabView in project liferay-faces-alloy by liferay.

the class TabViewRendererBase method encodeAlloyAttributes.

@Override
public void encodeAlloyAttributes(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
    TabView tabView = (TabView) uiComponent;
    boolean first = true;
    String height = tabView.getHeight();
    if (height != null) {
        encodeHeight(responseWriter, tabView, height, first);
        first = false;
    }
    Boolean stacked = tabView.getStacked();
    if (stacked != null) {
        encodeStacked(responseWriter, tabView, stacked, first);
        first = false;
    }
    String width = tabView.getWidth();
    if (width != null) {
        encodeWidth(responseWriter, tabView, width, first);
        first = false;
    }
    encodeHiddenAttributes(facesContext, responseWriter, tabView, first);
}
Also used : TabView(com.liferay.faces.alloy.component.tabview.TabView)

Example 4 with TabView

use of com.liferay.faces.alloy.component.tabview.TabView 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 5 with TabView

use of com.liferay.faces.alloy.component.tabview.TabView in project liferay-faces-alloy by liferay.

the class TabViewRenderer method encodeClientState.

@Override
public void encodeClientState(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
    // Encode the hidden field that contains the client-side state of the selected index.
    TabView tabView = (TabView) uiComponent;
    responseWriter.startElement("input", tabView);
    String hiddenFieldName = tabView.getClientId(facesContext) + "selectedIndex";
    responseWriter.writeAttribute("id", hiddenFieldName, null);
    responseWriter.writeAttribute("name", hiddenFieldName, null);
    responseWriter.writeAttribute("type", "hidden", null);
    responseWriter.writeAttribute("value", tabView.getSelectedIndex(), null);
    responseWriter.endElement("input");
}
Also used : TabView(com.liferay.faces.alloy.component.tabview.TabView)

Aggregations

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