I'm new to programming and new to the Forum. I have a college exercise that I am not able to do, I need to create a screen called Intersection, which receives 2 intervals and returns a message on the screen informing if there is an intersection between the intervals.
This is my Manager
@ManagedBean
@ViewScoped
public class InterseccaoManaged implements Serializable {
private List<Integer> valorA = new ArrayList<Integer>();
private List<Integer> valorB = new ArrayList<Integer>();
private Integer tamanho = 0;
FacesContext context = FacesContext.getCurrentInstance();
public void verificarInterseccao() {
for(int i = 0; i < valorA.size(); i++) {
for(int j = 0; j < valorB.size(); j++) {
if(valorB.add(j) == valorA.add(i)) {
tamanho ++;
FacesMessage facesMessage = new FacesMessage("Existe interseção entre as faixas A e B");
context.addMessage(null, facesMessage);
}else {
FacesMessage facesMessage = new FacesMessage("Não há interseção entre as faixas A e B");
context.addMessage(null, facesMessage);
}
}
}
}
..:/Getters e Setters/:..
This MyScreen
<h:form id="formInterseccao">
<p:messages severity="info,error,fatal" closable="true"/>
<div class="ui-fluid">
<p:panelGrid
columns="2"
columnClasses="ui-grid-col-3,ui-grid-col-3"
layout="grid">
<h:panelGroup>
<p:outputLabel value="Faixa A:"/>
<p:inputText value="#{interseccaoManaged.valorA[0]}"/>
<p:inputText value="#{interseccaoManaged.valorA[1]}"/>
</h:panelGroup>
<h:panelGroup>
<p:outputLabel value="Faixa B:"/>
<p:inputText value="#{interseccaoManaged.valorB[0]}"/>
<p:inputText value="#{interseccaoManaged.valorB[1]}"/>
</h:panelGroup>
</p:panelGrid>
<h:panelGroup layout="block" style="text-align:center">
<p:commandButton
value="Consultar"
update="@form"
action="#{lancamentoManaged.verificarInterseccao()}"
style="width:120px"/>
</h:panelGroup>
</div>
</h:form>
And the moment I run the Error
com.sun.faces.context.AjaxExceptionHandlerImpl handlePartialResponseError
GRAVE: javax.el.PropertyNotFoundException: /interseccao.xhtml @30,61 value="#{interseccaoManaged.valorA[0]}": Array index out of range: 0
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:100)
at org.primefaces.util.ComponentUtils.getConverter(ComponentUtils.java:152)
at org.primefaces.renderkit.InputRenderer.getConvertedValue(InputRenderer.java:199)
at javax.faces.component.UIInput.getConvertedValue(UIInput.java:1046)
at javax.faces.component.UIInput.validate(UIInput.java:976)
at javax.faces.component.UIInput.executeValidate(UIInput.java:1249)
at javax.faces.component.UIInput.processValidators(UIInput.java:712)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
at javax.faces.component.UIForm.processValidators(UIForm.java:253)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1258)
at javax.faces.component.UIViewRoot.processValidators(UIViewRoot.java:1195)
at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at filtro.ConexaoHibernateFilter.doFilter(ConexaoHibernateFilter.java:35)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.el.PropertyNotFoundException: Array index out of range: 0
at javax.el.ListELResolver.getType(ListELResolver.java:51)
at com.sun.faces.el.DemuxCompositeELResolver._getType(DemuxCompositeELResolver.java:215)
at com.sun.faces.el.DemuxCompositeELResolver.getType(DemuxCompositeELResolver.java:242)
at org.apache.el.parser.AstValue.getType(AstValue.java:60)
at org.apache.el.ValueExpressionImpl.getType(ValueExpressionImpl.java:174)
at com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:98)
... 41 more
If you can help me.
Thank you in advance.