ActiveIndex on Accordion panel global to DataGrid?

UI Components for JSF
Post Reply
Ray Kleijngeld
Posts: 14
Joined: 07 Feb 2018, 07:15

19 Mar 2018, 05:01

I have a datagrid that displays components and inside each element there is an accordion panel.

I have noticed that after I refresh a datagrid element and if I have 1 tab open in the accordion panel all other tabs on all the other datagrid elements open as well after the refresh.

It looks like that the activeIndex is not acting/set per datagrid element but global to the datagrid element?

Is is possible to update/amend this so that there is an ActiveIndex for each accordion panel for each dataGrid element?

Hmmm.. I tried to replicate this and .... was not able to. I have noticed this several times where in my application it doesn't work and then when I try to replicate in another test application it is working as expected.
Am I the only one experiencing this or this is something other users experience as well?

I am experiencing something else though.. Although I haven't checked this in my application.
I have an inputText field inside my accordionPanel and when I enter a value in this field and submit the request all the other input fields get the same value?

Info: Initializing Mojarra 2.2.12 ( 20150720-0848 https://svn.java.net/svn/mojarra~svn/tags/2.2.12@14885) for context '/JSFTest3'
Info: Running on PrimeFaces 6.2.RC2-SNAPSHOT

Thanks

Ray

Please see the bean below:


/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jsftest3;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Random;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.event.AjaxBehaviorEvent;
import org.fluttercode.datafactory.impl.DataFactory;

/**
*
* @author ray
*/
@ManagedBean
@ViewScoped
public class DataGridExample implements Serializable{

/**
* Creates a new instance of DataGridExample
*/

private ArrayList<Element> elements;
private String new_name;

public DataGridExample() {
elements = new ArrayList<>();
Random x = new Random();
x.setSeed(System.currentTimeMillis());
int num_elements = x.nextInt(15)+5;
DataFactory data = DataFactory.create();
for (int i=0;i<num_elements;i++)
{
elements.add(new Element(""+i, data.getFirstName()));
}
}

public ArrayList<Element> getElements() {
return elements;
}

public void submit(AjaxBehaviorEvent e)
{
String element_id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("element_id");

Element elem=null;
for (Element x : elements)
{
if (x.getElement_id().equals(element_id))
{ elem = x;
break;
}
}
elem.setName(new_name);
UIComponent comp = e.getComponent();
while (!comp.getClientId().endsWith("form1"))
comp = comp.getParent();
String client_id = comp.getClientId();
// RequestContext.getCurrentInstance().update(client_id);

}

public String getNew_name() {
return new_name;
}

public void setNew_name(String new_name) {
this.new_name = new_name;
}


}


package jsftest3;

/**
*
* @author ray
*/
public class Element {

private String element_id;
private String name;

public Element(String id, String name)
{
this.element_id = id;
this.name = name;
}

public String getElement_id() {
return element_id;
}

public void setElement_id(String element_id) {
this.element_id = element_id;
}


public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}


}

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
<f:view contentType="text/html">
<h:head>
<f:facet name="first">
<meta content='text/html; charset=UTF-8' http-equiv="Content-Type"/>
<title>PrimeFaces</title>
</f:facet>
<style>
body {font-family: calibri;font-size:0.85em}
.required {background-color: #b9d3e1 }
.ui-panelgrid td, .ui-widget-content tr {border-style:none !important}
</style>
</h:head>
<h:body>
<p:dataGrid id="results" value="#{dataGridExample.elements}" columns="1" layout="grid" var="element">
<h:form id="form1">
<p:panelGrid columns="2" layout="grid">
<p:outputLabel value="Name"/>
<p:outputLabel value="#{element.element_id} - #{element.name}"/>
</p:panelGrid>
<p:accordionPanel activeIndex="null">
<p:tab>
<f:facet name="title">
<p:outputLabel value="This is a title"/>
</f:facet>
<h:form id="form2">
<p:panelGrid columns="2">
<p:outputLabel value="New Name:"/>
<p:inputText id="new_name" size="50" value="#{dataGridExample.new_name}">
<p:ajax/>
</p:inputText>
<p:outputLabel value=""/>
<p:separator/>

<p:outputLabel value=""/>
<p:commandButton type="button" value="Submit">
<p:ajax listener="#{dataGridExample.submit}" update="@([id$=results])"/>
<f:param name="element_id" value="#{element.element_id}"/>
</p:commandButton>
</p:panelGrid>
</h:form>
</p:tab>

</p:accordionPanel>
</h:form>
</p:dataGrid>
</h:body>
</f:view>
</html>

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 53 guests