aspose file tools*
The moose likes JSF and the fly likes errors during adding dynamic components to panel grid in jsf Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "errors during adding dynamic components to panel grid in jsf" Watch "errors during adding dynamic components to panel grid in jsf" New topic
Author

errors during adding dynamic components to panel grid in jsf

Jabi Vulla
Greenhorn

Joined: Jan 20, 2013
Posts: 7
can any one help me please , im facing this problem from 1 day .. i am creating panel grid dynamically in my bean class ,an set of primefaces components adding to it like combo box,input text field etc... here my code is ..

public PanelGrid getpanelGrid() {
System.out.println("entered in panel grid");
FacesContext context = FacesContext.getCurrentInstance();
System.out.println("entered in panel grid 1");

ELContext elContext = context.getELContext();
Application app = context.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ValueExpression valueExp1 = elFactory.createValueExpression(elContext, "#{transactionSearchBean.selectedDataType1}",Object.class);
ValueExpression valueExp2 = elFactory.createValueExpression(elContext, "#{transactionSearchBean.selectedCondition}",Object.class);
ValueExpression valueExp3 = elFactory.createValueExpression(elContext, "#{transactionSearchBean.textBoxValue1}",String.class);
ValueExpression valueExp4 = elFactory.createValueExpression(elContext, "#{transactionSearchBean.fromDateValueForPanel1}",Date.class);

MethodExpression addLinkExpression1 = elFactory.createMethodExpression(
context.getELContext(), "#{transactionSearchBean.addDynamicRow2}", null, new Class[] { ActionEvent.class });
MethodExpression removeLinkExpression1 = elFactory.createMethodExpression(
context.getELContext(), "#{transactionSearchBean.addDynamicRow2}", null, new Class[] { ActionEvent.class });
System.out.println("entered in panel grid 2");

UISelectItems selectItems1 = new UISelectItems();
selectItems1.setValue(modelFieldStaticDataFilterList);
UISelectItems selectItems2 = new UISelectItems();
selectItems2.setValue(constantsSIList);
List<UIComponent> children = panelGrid.getChildren();

String uniqueId=FacesContext.getCurrentInstance().getViewRoot().createUniqueId();

panelGrid.setRendered(true);
panelGrid.setColumns(11);
panelGrid.setColumnClasses("centered");
panelGrid.setStyle("margin-bottom:0px; margin-top:0px");
System.out.println("entered in panel grid 3"+panelGrid);

SelectOneMenu dropDown1 = new SelectOneMenu();
dropDown1.setValueExpression("value",valueExp1);
dropDown1.getChildren().add(selectItems1);

SelectOneMenu dropDown2 = new SelectOneMenu();
dropDown2.setValueExpression("value",valueExp2);
dropDown2.getChildren().add(selectItems2);

UIComponent inputText1 = new UIInput();
inputText1.setValueExpression("value",valueExp3);
inputText1.getChildren().add(inputText1);

SelectOneRadio selectOneRadio1 = new SelectOneRadio();
selectOneRadio1.setValue("And");
SelectOneRadio selectOneRadio2 = new SelectOneRadio();
selectOneRadio2.setValue("Or");

Calendar calendar1 = new Calendar();
calendar1.setValue(valueExp4);

CommandLink addLink1 = new CommandLink();
addLink1.setValue("Add");
addLink1.setAjax(true);
addLink1.setImmediate(true);
addLink1.setProcess("@form");
addLink1.addActionListener(new MethodExpressionActionListener(addLinkExpression1));
addLink1.setUpdate("@form");

CommandLink removeLink1 = new CommandLink();
removeLink1.setValue("Remove");
removeLink1.setAjax(true);
removeLink1.setImmediate(true);
removeLink1.setProcess("@form");
removeLink1.addActionListener(new MethodExpressionActionListener(removeLinkExpression1));
removeLink1.setUpdate("@form");
panelGrid.getChildren().add(dropDown1);
System.out.println("entered in panel grid 4"+panelGrid);

if(panelGrid.equals(null)){




panelGrid.getChildren().add(dropDown2);

System.out.println("entered in panel grid 5"+panelGrid);

panelGrid.getChildren().add(inputText1);

System.out.println("entered in panel grid 6"+panelGrid);

panelGrid.getChildren().add(selectOneRadio1);
panelGrid.getChildren().add(selectOneRadio1);
System.out.println("entered in panel grid 7"+panelGrid);



panelGrid.getChildren().add(calendar1);

System.out.println("entered in panel grid 8"+panelGrid);

panelGrid.getChildren().add(addLink1);

System.out.println("entered in panel grid 9"+panelGrid);

panelGrid.getChildren().add(removeLink1);

System.out.println("entered in panel grid 10"+panelGrid);
}

java.lang.IllegalStateException: Component ID j_id3 has already been found in the view.
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:824)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.application.view.StateManagementStrategyImpl.saveView(StateManagementStrategyImpl.java:139)
at com.sun.faces.application.StateManagerImpl.saveView(StateManagerImpl.java:130)
at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:416)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.algofusion.reconciliation.opsworkbench.utilities.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:34)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:162)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

return panelGrid;
}


<h:panelGrid binding="#{transactionSearchBean.panelGrid}" >
</h:panelGrid>


Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

That's an awful lot of javax.faces code. I've always maintained that the more JSF-specific your code is, the more likely you're not doing it well, since JSF was intended to be able to do as much as possible using only POJO code.

In the particular example you gave, it looks like you're doing some sort of optional page section or pop-up. Usually you can do that much more easily by defining the UI elements in XHTML and employing only a small amount of backing-bean code (approximately 5 lines) to show/hide the resulting sub-view. Speaking of viewing, the "Code" button in our message editor can wrap tags around Java code, XML, and other pre-formatted text and make it easier to read.

Re-rendering a page can often lead to the "Component ID j_id3 has already been found in the view" message. This is especially true when you have changed the component tree. You can usually get rid of this message by putting explicit IDs on the controls and naming containers. And if that doesn't do it, at least you have less trouble locating the offending component, since the "j_" ids are auto-generated and not very predicatble, whereas an explicit ID will always be what you coded.


Customer surveys are for companies who didn't pay proper attention to begin with.
Jabi Vulla
Greenhorn

Joined: Jan 20, 2013
Posts: 7
Jabi Vulla wrote:can any one help me please , im facing this problem from 1 day .. i am creating panel grid dynamically in my bean class ,an set of primefaces components adding to it like combo box,input text field etc... here my code is ..

public PanelGrid getpanelGrid() {
System.out.println("entered in panel grid");
FacesContext context = FacesContext.getCurrentInstance();
System.out.println("entered in panel grid 1");

ELContext elContext = context.getELContext();
Application app = context.getApplication();
ExpressionFactory elFactory = app.getExpressionFactory();
ValueExpression valueExp1 = elFactory.createValueExpression(elContext, "#{transactionSearchBean.selectedDataType1}",Object.class);
ValueExpression valueExp2 = elFactory.createValueExpression(elContext, "#{transactionSearchBean.selectedCondition}",Object.class);
ValueExpression valueExp3 = elFactory.createValueExpression(elContext, "#{transactionSearchBean.textBoxValue1}",String.class);
ValueExpression valueExp4 = elFactory.createValueExpression(elContext, "#{transactionSearchBean.fromDateValueForPanel1}",Date.class);

MethodExpression addLinkExpression1 = elFactory.createMethodExpression(
context.getELContext(), "#{transactionSearchBean.addDynamicRow2}", null, new Class[] { ActionEvent.class });
MethodExpression removeLinkExpression1 = elFactory.createMethodExpression(
context.getELContext(), "#{transactionSearchBean.addDynamicRow2}", null, new Class[] { ActionEvent.class });
System.out.println("entered in panel grid 2");

UISelectItems selectItems1 = new UISelectItems();
selectItems1.setValue(modelFieldStaticDataFilterList);
UISelectItems selectItems2 = new UISelectItems();
selectItems2.setValue(constantsSIList);
List<UIComponent> children = panelGrid.getChildren();

String uniqueId=FacesContext.getCurrentInstance().getViewRoot().createUniqueId();

panelGrid.setRendered(true);
panelGrid.setColumns(11);
panelGrid.setColumnClasses("centered");
panelGrid.setStyle("margin-bottom:0px; margin-top:0px");
System.out.println("entered in panel grid 3"+panelGrid);

SelectOneMenu dropDown1 = new SelectOneMenu();
dropDown1.setValueExpression("value",valueExp1);
dropDown1.getChildren().add(selectItems1);

SelectOneMenu dropDown2 = new SelectOneMenu();
dropDown2.setValueExpression("value",valueExp2);
dropDown2.getChildren().add(selectItems2);

UIComponent inputText1 = new UIInput();
inputText1.setValueExpression("value",valueExp3);
inputText1.getChildren().add(inputText1);

SelectOneRadio selectOneRadio1 = new SelectOneRadio();
selectOneRadio1.setValue("And");
SelectOneRadio selectOneRadio2 = new SelectOneRadio();
selectOneRadio2.setValue("Or");

Calendar calendar1 = new Calendar();
calendar1.setValue(valueExp4);

CommandLink addLink1 = new CommandLink();
addLink1.setValue("Add");
addLink1.setAjax(true);
addLink1.setImmediate(true);
addLink1.setProcess("@form");
addLink1.addActionListener(new MethodExpressionActionListener(addLinkExpression1));
addLink1.setUpdate("@form");

CommandLink removeLink1 = new CommandLink();
removeLink1.setValue("Remove");
removeLink1.setAjax(true);
removeLink1.setImmediate(true);
removeLink1.setProcess("@form");
removeLink1.addActionListener(new MethodExpressionActionListener(removeLinkExpression1));
removeLink1.setUpdate("@form");
panelGrid.getChildren().add(dropDown1);
System.out.println("entered in panel grid 4"+panelGrid);

if(panelGrid.equals(null)){




panelGrid.getChildren().add(dropDown2);

System.out.println("entered in panel grid 5"+panelGrid);

panelGrid.getChildren().add(inputText1);

System.out.println("entered in panel grid 6"+panelGrid);

panelGrid.getChildren().add(selectOneRadio1);
panelGrid.getChildren().add(selectOneRadio1);
System.out.println("entered in panel grid 7"+panelGrid);



panelGrid.getChildren().add(calendar1);

System.out.println("entered in panel grid 8"+panelGrid);

panelGrid.getChildren().add(addLink1);

System.out.println("entered in panel grid 9"+panelGrid);

panelGrid.getChildren().add(removeLink1);

System.out.println("entered in panel grid 10"+panelGrid);
}
return panelGrid;
}


<h:panelGrid binding="#{transactionSearchBean.panelGrid}" >
</h:panelGrid>

java.lang.IllegalStateException: Component ID j_id3 has already been found in the view.
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:824)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.util.Util.checkIdUniqueness(Util.java:808)
at com.sun.faces.application.view.StateManagementStrategyImpl.saveView(StateManagementStrategyImpl.java:139)
at com.sun.faces.application.StateManagerImpl.saveView(StateManagerImpl.java:130)
at com.sun.faces.application.view.WriteBehindStateWriter.flushToWriter(WriteBehindStateWriter.java:225)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:416)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:273)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at com.algofusion.reconciliation.opsworkbench.utilities.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:34)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:79)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:164)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:563)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:403)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:301)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:162)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)



Jabi Vulla
Greenhorn

Joined: Jan 20, 2013
Posts: 7
can you please tell me clearly how putting explicit ids?..
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

Jabi Vulla wrote:can you please tell me clearly how putting explicit ids?..


In xhtml, code id="xxxxx"" to set an explicit ID. IDs must be unique within a naming container (form, panelGrid, dataTable or similar).

I don't have any example code that sets IDs in Java code. In fact, after 7 years, I only have 3 programs that even build any JSF UIComponent elements via Java code, none of which are as long as yours. And one of them remains with a former employer.
Jabi Vulla
Greenhorn

Joined: Jan 20, 2013
Posts: 7
Jabi Vulla wrote:i set ids explicitly but still same error is coming.[/quote]
Jabi Vulla
Greenhorn

Joined: Jan 20, 2013
Posts: 7
i set ids explicitly but still same error is coming.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16303
    
  21

If it's really the "same" error (j_xxx is not unique), then you didn't set an ID in the right place.
 
 
subject: errors during adding dynamic components to panel grid in jsf