Search in sources :

Example 1 with Accordion

use of com.liferay.faces.alloy.component.accordion.Accordion in project liferay-faces-alloy by liferay.

the class AccordionRenderer 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.
    Accordion accordion = (Accordion) uiComponent;
    responseWriter.startElement("input", accordion);
    String accordionClientId = accordion.getClientId(facesContext);
    String hiddenFieldName = accordionClientId + "selectedIndex";
    responseWriter.writeAttribute("id", hiddenFieldName, null);
    responseWriter.writeAttribute("name", hiddenFieldName, null);
    responseWriter.writeAttribute("type", "hidden", null);
    responseWriter.writeAttribute("value", accordion.getSelectedIndex(), null);
    responseWriter.endElement("input");
    responseWriter.startElement("input", accordion);
    hiddenFieldName = accordionClientId + "collapsedTabIndex";
    responseWriter.writeAttribute("id", hiddenFieldName, null);
    responseWriter.writeAttribute("name", hiddenFieldName, null);
    responseWriter.writeAttribute("type", "hidden", null);
    responseWriter.endElement("input");
}
Also used : Accordion(com.liferay.faces.alloy.component.accordion.Accordion)

Example 2 with Accordion

use of com.liferay.faces.alloy.component.accordion.Accordion 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 Accordion

use of com.liferay.faces.alloy.component.accordion.Accordion 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 4 with Accordion

use of com.liferay.faces.alloy.component.accordion.Accordion in project liferay-faces-alloy by liferay.

the class AccordionRendererBase method encodeAlloyAttributes.

@Override
public void encodeAlloyAttributes(FacesContext facesContext, ResponseWriter responseWriter, UIComponent uiComponent) throws IOException {
    Accordion accordion = (Accordion) uiComponent;
    boolean first = true;
    encodeHiddenAttributes(facesContext, responseWriter, accordion, first);
}
Also used : Accordion(com.liferay.faces.alloy.component.accordion.Accordion)

Example 5 with Accordion

use of com.liferay.faces.alloy.component.accordion.Accordion in project liferay-faces-alloy by liferay.

the class AccordionRenderer method decodeClientState.

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

Aggregations

Accordion (com.liferay.faces.alloy.component.accordion.Accordion)5 DataEncoderBase (com.liferay.faces.alloy.component.data.internal.DataEncoderBase)2 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 ResponseWriter (javax.faces.context.ResponseWriter)1