CustomLayout - problem with multiple items

Hi,

So, i’ve got 2 holders i use with CustomLayout.

PersonHolder:

<div class='persons_holder' location='persons_list'></div>

PersonsHolder:

<div class='single_person_holder'>
<div class='person_action' location='person_action'></div>
<div class='person_data'>
   <div class='person_name' location='person_name'></div>
   <div class='person_shares' location='person_shares'></div>
</div>
</div>

Now, i want to use it with some for(;:wink: instructions. In nutshell:


CustomLayout personsHolderLayout = new CustomLayout(PERSONSHOLDER);
Panel tmpPanelPersons = new Panel();
for (PersonView personView : personViews) {
  Component compToAdd2 = magicWithData(2); 
  Component compToAdd3 = magicWithData(3); 
  CustomLayout singlePersonHolderLayout =  new CustomLayout(SINGLEPERSONHOLDER);  
  singlePersonHolderLayout.addComponent(compToAdd2, "person_action"); 
  singlePersonHolderLayout.addComponent(compToAdd3, "person_name"); 

  Panel tmpPanelPerson = new Panel(); 
  for (SingleEntryView chng : ((PersonWithSharesView) personView.getEntries()) {
     Component comp2add = magicWithAnotherData(1); 
     tmpPanelShares.addComponent(comp2add);
     singlePersonHolderLayout.addComponent(tmpPanelShares, "person_shares");
  }
 
  tmpPanelPersons.addComponent(singlePersonHolderLayout);
}
personsHolderLayout.addComponent(tmpPanelPersons, "persons_list"); 

After one loop, it’s done. I’ve got indexOutOfBound at:


  CustomLayout singlePersonHolderLayout =  new CustomLayout(SINGLEPERSONHOLDER);  

Can someone tell me what i did wrong ?
I’m new at Vaadin :slight_smile: So be gentle please.

Thanks in return
Lukasz

Here’s the print stack trace:


16:10:06,705 ERROR http-8880-exec-4 ui.SpgApp$1:15 - class com.vaadin.terminal.gwt.server.ChangeVariablesErrorEvent com.vaadin.terminal.gwt.server.ChangeVariablesErrorEvent@13b63e6
java.lang.ArrayIndexOutOfBoundsException
	at java.lang.System.arraycopy(Native Method)
	at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:516)
	at java.lang.StringBuilder.append(StringBuilder.java:189)
	at com.vaadin.ui.CustomLayout.initTemplateContentsFromInputStream(CustomLayout.java:119)
	at com.vaadin.ui.CustomLayout.<init>(CustomLayout.java:96)
	at ln.spg.ui.metrics.MetricsDataPanel.appendPeopleViews(MetricsDataPanel.java:700)
	at ln.spg.ui.metrics.MetricsDataPanel.addPeopleComponentToForm(MetricsDataPanel.java:850)
	at ln.spg.ui.metrics.MetricsDataPanel.render(MetricsDataPanel.java:391)
	at ln.spg.ui.metrics.MetricsNewPanel$1.action(MetricsNewPanel.java:150)
	at ln.spg.ui.components.TimeAxis.changeVariables(TimeAxis.java:95)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariableBurst(AbstractCommunicationManager.java:1297)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.handleVariables(AbstractCommunicationManager.java:1217)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:733)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:296)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:483)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:366)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.session.ConcurrentSessionFilter.doFilter(ConcurrentSessionFilter.java:109)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:167)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:242)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:203)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:108)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:558)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:379)
	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:242)
	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:259)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:281)
	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
	at java.lang.Thread.run(Thread.java:619)

Aaand the problem was:

new ByteArrayInputStream(TemplateHtmlClass.templateSinglePersonHolder().getBytes()) 

Or as U prefer in my code it looks like that:



ByteArrayInputStream SINGLEPERSONHOLDER = new ByteArrayInputStream(
				TemplateHtmlClass.templateSinglePersonHolder().getBytes());
//and later on... 
singlePersonHolderLayout = new CustomLayout(SINGLEPERSONHOLDER); 
 

On the other side:

Is there any way to put more than one Component into one location in CustomLayout, without using Panels ? Using just CL features ?

Using just CL features, no - and what would it mean to have multiple Components there? Just appending more divs? Quite a bit more API would be required to manage them etc.

You could use any layout there, though - including CssLayout, which should be quite light-weight there especially if you don’t use relative sizes.

Alternatively, if you know the number of components in each location when generating the HTML for the CustomLayout, you could expand placeholders in your template to multiple divs with generated “location” attribute names, and then put your components in these new locations.