Uploaded image for project: 'PUBLIC - Liferay Faces'
  1. PUBLIC - Liferay Faces
  2. FACES-3172

TabCollapseEvent occurs when a tab is expanded causing a preceding tab to collapse

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Inactive
    • Affects Version/s: alloy-2.0.0, alloy-3.0.0
    • Fix Version/s: None
    • Labels:
      None

      Description

      Steps to reproduce:

      1. Apply the following patch to the Alloy Showcase (in order to show all messages from every event that occurs in the view):

      diff --git a/demo/alloy-showcase-webapp/src/main/java/com/liferay/faces/showcase/bean/AccordionBackingBean.java b/demo/alloy-showcase-webapp/src/main/java/com/liferay/faces/showcase/bean/AccordionBackingBean.java
      index 5adc44e..3ec0d90 100644
      --- a/demo/alloy-showcase-webapp/src/main/java/com/liferay/faces/showcase/bean/AccordionBackingBean.java
      +++ b/demo/alloy-showcase-webapp/src/main/java/com/liferay/faces/showcase/bean/AccordionBackingBean.java
      @@ -24,6 +24,8 @@ import javax.faces.event.AjaxBehaviorEvent;
       import com.liferay.faces.alloy.component.accordion.Accordion;
       import com.liferay.faces.alloy.component.tab.TabCollapseEvent;
       import com.liferay.faces.alloy.component.tab.TabExpandEvent;
      +import java.util.ArrayList;
      +import java.util.List;
       
       
       /**
      @@ -79,9 +81,11 @@ public class AccordionBackingBean {
       		// When using JSF 2.2, this cast is unnecessary, and the method can take the TabCollapseEvent directly.
       		TabCollapseEvent tabCollapseEvent = (TabCollapseEvent) ajaxBehaviorEvent;
       		FacesContext facesContext = FacesContext.getCurrentInstance();
      -		FacesMessage facesMessage = new FacesMessage("Received 'tabCollapseEvent' for tab with header '" +
      +		String message = "Received 'tabCollapseEvent' for tab with header '" +
       				tabCollapseEvent.getTab().getHeaderText() + "' in the " + tabCollapseEvent.getPhaseId().toString() +
      -				" phase.");
      +				" phase.";
      +		getMessages(facesContext).add(message);
      +		FacesMessage facesMessage = new FacesMessage(message);
       		facesContext.addMessage(null, facesMessage);
       	}
       
      @@ -90,9 +94,25 @@ public class AccordionBackingBean {
       		// When using JSF 2.2, this cast is unnecessary, and the method can take the TabExpandEvent directly.
       		TabExpandEvent tabExpandEvent = (TabExpandEvent) ajaxBehaviorEvent;
       		FacesContext facesContext = FacesContext.getCurrentInstance();
      -		FacesMessage facesMessage = new FacesMessage("Received 'tabExpandEvent' for tab with header '" +
      +		String message = "Received 'tabExpandEvent' for tab with header '" +
       				tabExpandEvent.getTab().getHeaderText() + "' in the " + tabExpandEvent.getPhaseId().toString() +
      -				" phase.");
      +				" phase.";
      +		getMessages(facesContext).add(message);
      +		FacesMessage facesMessage = new FacesMessage(message);
       		facesContext.addMessage(null, facesMessage);
       	}
      +
      +	private List<String> getMessages(FacesContext facesContext) {
      +
      +		Map<String, Object> viewMap = facesContext.getViewRoot().getViewMap(true);
      +		List<String> messages = (List<String>) viewMap.get("tabMessages");
      +
      +		if (messages == null) {
      +
      +			messages = new ArrayList<String>();
      +			viewMap.put("tabMessages", messages);
      +		}
      +
      +		return messages;
      +	}
       }
      diff --git a/demo/alloy-showcase-webapp/src/main/webapp/WEB-INF/component/alloy/accordion/server-events/accordion.xhtml b/demo/alloy-showcase-webapp/src/main/webapp/WEB-INF/component/alloy/accordion/server-events/accordion.xhtml
      index 7653023..f818bc9 100644
      --- a/demo/alloy-showcase-webapp/src/main/webapp/WEB-INF/component/alloy/accordion/server-events/accordion.xhtml
      +++ b/demo/alloy-showcase-webapp/src/main/webapp/WEB-INF/component/alloy/accordion/server-events/accordion.xhtml
      @@ -4,7 +4,9 @@
       
       	<showcase:example>
       		<alloy:form id="exampleForm">
      -			<alloy:messages id="feedback" globalOnly="true" layout="table" />
      +			<alloy:dataList id="feedback" value="#{tabMessages}" var="message">
      +				<alloy:dataItem>#{message}</alloy:dataItem>
      +			</alloy:dataList>
       			<alloy:accordion selectedIndex="#{accordionBackingBean.defaultSelectedIndex}">
       				<f:ajax event="tabCollapse" listener="#{accordionBackingBean.tabCollapseListener}"
       					render=":exampleForm:feedback" />
      

      2. Deploy the showcase and navigate to the alloy:accordion Server Events page.
      3. Click the Open Source option.

      If the bug still exists, the following messages will be shown:

      • Received 'tabCollapseEvent' for tab with header 'Powerful Integration' in the APPLY_REQUEST_VALUES 2 phase.
      • Received 'tabExpandEvent' for tab with header 'Open Source' in the APPLY_REQUEST_VALUES 2 phase.

      If the bug is fixed, only the second message will be shown:

      • Received 'tabExpandEvent' for tab with header 'Open Source' in the APPLY_REQUEST_VALUES 2 phase.

      Note that if Compatible is clicked, only one message appears:

      • Received 'tabExpandEvent' for tab with header 'Compatible' in the APPLY_REQUEST_VALUES 2 phase.

      According to the code, this appears to be the correct behavior. In other words, the only time a TabCollapseEvent should occur is when the user clicks on an expanded tab to collapse it. If a tab is collapsed programmatically due to another tab being expanded, a TabCollapseEvent should not fire.

        Attachments

          Activity

            People

            Assignee:
            ui_faces UI Faces
            Reporter:
            kyle.stiemann Kyle Stiemann (Inactive)
            Participants of an Issue:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Packages

                Version Package