I'm looking for a how to add a component in my table. My table is using a JPAContainer as datasource. I'm trying using addContainerProperty but doesn't work and returns an exception.
I'm trying this
private final CustomJPAContainer<Curriculum> datasource = new CustomJPAContainer<Curriculum>(Curriculum.class);
Button btnView = new Button();
Table tabela = new Table("",datasource);
tabela.addContainerProperty("View", Button.class, null);
//exception
java.lang.UnsupportedOperationException
at com.vaadin.addon.jpacontainer.JPAContainer.addContainerProperty(JPAContainer.java:666)
at com.vaadin.ui.AbstractSelect.addContainerProperty(AbstractSelect.java:806)
at com.vaadin.ui.Table.addContainerProperty(Table.java:4260)
at br.ind.ibg.views.VisualizarCurriculum.buildLayout(VisualizarCurriculum.java:58)
at br.ind.ibg.views.VisualizarCurriculum.<init>(VisualizarCurriculum.java:36)
at br.ind.ibg.utils.MenuSistema$1.menuSelected(MenuSistema.java:60)
at com.vaadin.ui.MenuBar.changeVariables(MenuBar.java:186)
at com.vaadin.server.communication.ServerRpcHandler.changeVariables(ServerRpcHandler.java:396)
at com.vaadin.server.communication.ServerRpcHandler.handleBurst(ServerRpcHandler.java:221)
at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:111)
at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:91)
at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:37)
at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Any idea ?
/** edited */
I solved the problem using setGeneratedColumn()
Here how I did.
public class ButtonColumnGenerator implements Table.ColumnGenerator{
private static final long serialVersionUID = 1L;
#Override
public Object generateCell(Table source, Object itemId, Object columnId) {
Property prop = source.getItem(itemId).getItemProperty(columnId);
Button btnView = new Button();
btnView.setData(itemId);
btnView.setDescription("Curriculum: " + itemId);
btnView.setIcon(new ThemeResource("../icons/eye.png"));
btnView.setWidth("20px");
btnView.setHeight("20px");
btnView.setStyleName(Reindeer.BUTTON_LINK);
return btnView;
}
}
/*** my app */
Button btnView = new Button();
Table tabela = new Table("",datasource);
tabela.setVisibleColumns(new Object[]{"idCurriculum", "nome", "cpf"});
tabela.setColumnHeaders(new String[] {"#", "Nome", "Cpf"});
tabela.addGeneratedColumn("", new ButtonColumnGenerator());
now works !
Adding UI components to the data source of a select component (Table, Tree, TreeTable, ComboBox, ...) is the wrong approach for your problem. The container data source of a Table component only contains the data model of the table and not the components that will display this data.
So, instead of adding properties to the JPAContainer (which is disallowed for this container as it handles its properties internally), you set a custom com.vaadin.ui.TableFieldFactory to your table with Table.setTableFieldFactory(TableFieldFactory fieldFactory).
Related
My goal is to find out what columns where changed during an update on my MySQL database.
My first idea was to use the Hibernate Event System. I have implemented a PreUpdateEventListener. The event allows access to the changed object and I'm retrieving the older object from the database. I am using the Java Object Diff Library to compare the two objects. Since I only need the first layer to be compared I configured the Comparator as follows:
public static List<String> compareTillFirstLayer(Object pre, Object post) {
ArrayList<String> changedProperties = new ArrayList<String>();
InclusionResolver inclusionResolver = new InclusionResolver() {
#Override
public Inclusion getInclusion(DiffNode node) {
if (node.getParentNode().isRootNode()) {
return Inclusion.INCLUDED;
}
return null;
}
#Override
public boolean enablesStrictIncludeMode() {
return true;
}
};
ObjectDiffer objectDiffer = ObjectDifferBuilder.startBuilding().inclusion().resolveUsing(inclusionResolver)
.and().build();
DiffNode root = objectDiffer.compare(pre, post);
root.visitChildren(new DiffNode.Visitor() {
#Override
public void node(DiffNode node, Visit visit) {
changedProperties.add(node.getPropertyName());
}
});
return changedProperties;
}
This returns the changed properties of the object. To find the connection to the database columns I use the Hibernate Configuration and it's mapping like this:
for (String property : changedProperties) {
PersistentClass persistentClass = HibernateUtil.getHibernateUtil().getConfiguration()
.getClassMapping(Consumer.class.getName());
String columnName = ((Column) persistentClass.getProperty(property).getColumnIterator().next())
.getName();
System.out.println(columnName);
}
This workes just fine for my Consumer object but it fails with other objects like an Appointment or a Vehicle object.
Even the exceptions differ from object to object.
If I try to monitor the changes of the Appointment I recieve the following exception:
java.util.NoSuchElementException
at java.util.ArrayList$Itr.next(ArrayList.java:854)
at de.applicodata.serviceportal.persistence.hibernateEventListeners.PreUpdateEventImpl.onPreUpdate(PreUpdateEventImpl.java:88)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:86)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at de.applicodata.serviceportal.persistence.dao.GeneralDAO.commit(GeneralDAO.java:189)
at de.applicodata.serviceportal.persistence.dao.GeneralDAO.update(GeneralDAO.java:556)
at de.applicodata.serviceportal.logic.entities.Appointment.updatePersistenceObject(Appointment.java:167)
at de.applicodata.serviceportal.faces.beans.MyAppointmentsBean.updateAppointmemt(MyAppointmentsBean.java:777)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.el.parser.AstValue.invoke(AstValue.java:279)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
at org.jboss.weld.module.web.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.module.web.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at net.bull.javamelody.JsfActionListener.processAction(JsfActionListener.java:67)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
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:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:239)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at de.applicodata.serviceportal.faces.listener.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at de.applicodata.serviceportal.faces.listener.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:129)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:199)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1136)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
While monitoring changes on the Vehicle object I receiver the following exception although the Objects are diffrent from another:
java.lang.IllegalStateException: Couldn't find a differ for type: [B
at de.danielbechler.diff.differ.DifferProvider.retrieveDifferForType(DifferProvider.java:55)
at de.danielbechler.diff.differ.DifferDispatcher.compare(DifferDispatcher.java:196)
at de.danielbechler.diff.differ.DifferDispatcher.compareWithCircularReferenceTracking(DifferDispatcher.java:172)
at de.danielbechler.diff.differ.DifferDispatcher.compare(DifferDispatcher.java:159)
at de.danielbechler.diff.differ.DifferDispatcher.dispatch(DifferDispatcher.java:105)
at de.danielbechler.diff.differ.BeanDiffer.compareUsingIntrospection(BeanDiffer.java:114)
at de.danielbechler.diff.differ.BeanDiffer.compareUsingAppropriateMethod(BeanDiffer.java:104)
at de.danielbechler.diff.differ.BeanDiffer.compare(BeanDiffer.java:90)
at de.danielbechler.diff.differ.DifferDispatcher.compare(DifferDispatcher.java:202)
at de.danielbechler.diff.differ.DifferDispatcher.compareWithCircularReferenceTracking(DifferDispatcher.java:172)
at de.danielbechler.diff.differ.DifferDispatcher.compare(DifferDispatcher.java:159)
at de.danielbechler.diff.differ.DifferDispatcher.dispatch(DifferDispatcher.java:105)
at de.danielbechler.diff.ObjectDiffer.compare(ObjectDiffer.java:52)
at de.applicodata.serviceportal.persistence.hibernateEventListeners.HibernateEventObjectComparator.compareTillFirstLayer(HibernateEventObjectComparator.java:34)
at de.applicodata.serviceportal.persistence.hibernateEventListeners.PreUpdateEventImpl.onPreUpdate(PreUpdateEventImpl.java:63)
at org.hibernate.action.EntityUpdateAction.preUpdate(EntityUpdateAction.java:237)
at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:86)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:273)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:265)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
at de.applicodata.serviceportal.persistence.dao.GeneralDAO.commit(GeneralDAO.java:189)
at de.applicodata.serviceportal.persistence.dao.GeneralDAO.update(GeneralDAO.java:556)
at de.applicodata.serviceportal.logic.entities.Vehicle.updatePersistenceObject(Vehicle.java:509)
at de.applicodata.serviceportal.faces.beans.WerWiSalesVehicleBean.updateVehicle(WerWiSalesVehicleBean.java:1892)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.el.parser.AstValue.invoke(AstValue.java:279)
at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:273)
at org.jboss.weld.module.web.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
at org.jboss.weld.module.web.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
at net.bull.javamelody.JsfActionListener.processAction(JsfActionListener.java:67)
at javax.faces.component.UICommand.broadcast(UICommand.java:315)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
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:658)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:89)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:239)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:215)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at de.applicodata.serviceportal.faces.listener.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:36)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at de.applicodata.serviceportal.faces.listener.SessionTimeoutFilter.doFilter(SessionTimeoutFilter.java:129)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:357)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:199)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:1025)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1136)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
I really don't know where to start on this one since the exceptions are so different from eachother. Any tips on what might cause this behaviour are appreciated!
If any further information is needed I'll provide it.
Edit: The Vehicle error is kind of resolved. It was due to a missing feature in the before mentioned Java Object Diff Library. Source I am currently working on a workaround for excluding arrays from the comparison
The first part of the question is answered. Due to the Java Object Diff Library not beeing able to work with arrays I decided to just exclude these from the comparison.
This works just fine with the rewritten compareTillFirstLayer method like this:
public class HibernateEventObjectComparator {
public final static InclusionResolver inclusionResolver = new InclusionResolver() {
#Override
public Inclusion getInclusion(DiffNode node) {
if (node.getParentNode().isRootNode() && node.getValueType().isArray()) {
return Inclusion.EXCLUDED;
} else if (node.getParentNode().isRootNode()) {
return Inclusion.INCLUDED;
} else {
return null;
}
}
#Override
public boolean enablesStrictIncludeMode() {
return true;
}
};
public static List<String> compareTillFirstLayer(Object pre, Object post) {
ArrayList<String> changedProperties = new ArrayList<String>();
ObjectDiffer objectDiffer = ObjectDifferBuilder.startBuilding().inclusion().resolveUsing(inclusionResolver)
.and().build();
DiffNode root = objectDiffer.compare(pre, post);
root.visitChildren(new DiffNode.Visitor() {
#Override
public void node(DiffNode node, Visit visit) {
changedProperties.add(node.getPropertyName());
}
});
return changedProperties;
}
...
EDIT: The second problme is solved as well.
The list of columns I got from hibernate was empty if it referred to a collection. Since I didn't need these columns I'm simply checking if a column is availabe and only iterate over the columns array if there are columns inside. Sadly I have no answer to why the columns array for any collection is empty.
I try to access to a datasource which is defined in tomee.xml (with initial context). My TomEE+ 1.7.2 runs locally on my computer.
DataSource definition in /conf/tomee.xml
<Resource id="as400-ds" type="DataSource">
JdbcDriver com.ibm.as400.access.AS400JDBCDriver
JdbcUrl jdbc:as400://192.168.3.15;errors=full
UserName test
Password 1337
</Resource>
Java-code where the exception is thrown:
public static void main(String[] args) {
Properties contextConfig = new Properties();
contextConfig.setProperty("java.naming.factory.initial",
"org.apache.openejb.client.RemoteInitialContextFactory");
contextConfig.setProperty("java.naming.provider.url", "http://127.0.0.1:8080/tomee/ejb");
try {
InitialContext context = new InitialContext(contextConfig);
DataSource as400ds = (DataSource) context.lookup("as400-ds");
} catch (NamingException e) {
e.printStackTrace();
}
NoSuchMethodException StackTrace: (thrown at the lookup method):
java.lang.NoSuchMethodException: org.apache.openejb.resource.jdbc.managed.local.ManagedDataSource.getDriverClass()
at java.lang.Class.getMethod(Class.java:1773)
at org.apache.openejb.server.ejbd.JndiRequestHandler$DbcpDataSource.getDriverClassName(JndiRequestHandler.java:593)
at org.apache.openejb.server.ejbd.JndiRequestHandler.doLookup(JndiRequestHandler.java:276)
at org.apache.openejb.server.ejbd.JndiRequestHandler.processResponse(JndiRequestHandler.java:174)
at org.apache.openejb.server.ejbd.EjbDaemon.processJndiResponse(EjbDaemon.java:360)
at org.apache.openejb.server.ejbd.EjbDaemon.service(EjbDaemon.java:272)
at org.apache.openejb.server.ejbd.EjbServer.service(EjbServer.java:86)
at org.apache.openejb.server.httpd.ServerServlet.service(ServerServlet.java:58)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
However when I try to access it with dependency injection (#Resource) in a stateless container it works fine.
Thank you in advance.
P. S. The original exception was ThrowableArtifact cannot be cast to java.lang.Error but this seems to be a bug so I debugged it to get the NoSuchMethodException.
I am learning wicket framework and while working with ajax I tried one example in which I want to display a panel with selected radio button's company name. But while doing this I am getting some error. Here I mentioned all details from my coding:
Test.java
public class Test extends WebPage {
private static final List<String> companies = Arrays.asList(new String[] {"Google","Microsoft","Yahoo"});
private ArrayList<String> compSelected = new ArrayList<String>();
private Panel panel;
public Test(final PageParameters parameters) {
final RadioChoice<String> companyList =
new RadioChoice<String>("companyNames",new Model(compSelected),companies);
companyList.add(new AjaxFormChoiceComponentUpdatingBehavior() {
#Override
protected void onUpdate(AjaxRequestTarget target) {
if("Google".equals(companyList.getModelObject())){
panel = new Panel1("panel1","Google");
}
else if("Microsoft".equals(companyList.getModelObject())){
panel = new Panel1("panel1","Microsoft");
}
else{
panel = new Panel1("panel1","Yahoo");
}
panel.setOutputMarkupId(true);
target.addComponent(panel);
}});
Form<?> form = new Form<Void>("form");
add(form);
form.add(companyList);
form.add(panel);
this.add(form);
}
}
Test.html
<form wicket:id="form">
<label><b>Company List:</b></label><br>
<span wicket:id="companyNames">radio button list will goes here</span><br>
<span wicket:id = "panel1" class="panel">panel goes here</span>
</form>
Panel1.java
#SuppressWarnings("serial")
public class Panel1 extends Panel{
public Panel1(String id,String cName) {
super(id);
add(new Label("msg", "selected company is:"+ cName));
}
}
Panel1.html
<body>
<wicket:panel>
<span wicket:id="msg">message goes here</span>
</wicket:panel>
</body>
WicketMessage: Can't instantiate page using constructor public demo.wicket.ajax.Test(org.apache.wicket.PageParameters) and argument Root cause:java.lang.IllegalArgumentException: argument child may not be null at org.apache.wicket.MarkupContainer.add(MarkupContainer.java:131) at demo.wicket.ajax.Test.(Test.java:46) at java.lang.reflect.Constructor.newInstance(Unknown Source) at org.apache.wicket.session.DefaultPageFactory.createPage(DefaultPageFactory.java:188) at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:65) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.newPage(BookmarkablePageRequestTarget.java:299) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.getPage(BookmarkablePageRequestTarget.java:321) at org.apache.wicket.request.target.component.BookmarkablePageRequestTarget.processEvents(BookmarkablePageRequestTarget.java:234) at org.apache.wicket.request.AbstractRequestCycleProcessor.processEvents(AbstractRequestCycleProcessor.java:92) at org.apache.wicket.RequestCycle.processEventsAndRespond(RequestCycle.java:1250) at org.apache.wicket.RequestCycle.step(RequestCycle.java:1329) at org.apache.wicket.RequestCycle.steps(RequestCycle.java:1428) at org.apache.wicket.RequestCycle.request(RequestCycle.java:545) at org.apache.wicket.protocol.http.WicketFilter.doGet(WicketFilter.java:468) at org.apache.wicket.protocol.http.WicketFilter.doFilter(WicketFilter.java:301) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611) at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)
I am not sure what I did wrong here. can someone please help me to figure it out?
The problem is form.add(panel);. panel is null at that time. You initialize it in #onUpdate() but it is executed only after a click(?) on the radio buttons.
Solution:
Change panel type to WebMarkupContainer and initialize it in the page's constructor. Call panel.setOutputMarkupId(true) also in the constructor so the <span wicket:id="panel1"...> has an id in the rendered HTML and being able to be referenced later with JS to replace/update it. In #onUpdate() use something like panel = panel.replaceWith(new Panel1(panel.getId(), choice.getModelObject())); target.add(panel);
I am currently trying to export content to a csv/xls file using primefaces exporter classes. I am generating a datatable component from javacode and pass it to the exporter class. It works fine, but I get very often a the following exception:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
I understand the exception, but not why it is thrown. The following message is called as an actionlistener by a primefaces command button:
public void export(MyBeanBeanClass bean, MyTable myTable, String format) {
FacesContext context = FacesContext.getCurrentInstance();
Exporter exporter = ExporterFactory.getExporterForType(format);
DataTable table = new DataTable();
String beanName = this.lookupManagedBeanName(bean);
List<Object[]> exportList = new ArrayList<Object[]>();
String outputFileName = "export";
boolean isPageOnly = false;
boolean isSelectionOnly = false;
String encodingType = "iso-8859-1";
MethodExpression preProcessor = null;
MethodExpression postProcessor = null;
// creating <p:datatable> component from java code -> see balusc's blog
// http://balusc.blogspot.de/2006/06/using-datatables.html#PopulateDynamicDatatable
// prepare datasource for export
for (MyRow row : myTable) {
Object[] rowContent = new Object[row.columnCount()];
for (int i = 0; i < rowContent.length; i++) {
rowContent[i] = row.get(i);
}
exportList.add(rowContent);
}
bean.setExportList(exportList);
// create primefaces datatable <p:datatable>
table.setValueExpression("value", createValueExpression("#{" + beanName + ".exportList}", List.class));
table.setVar("row");
// create columns and rows
for (int i = 0; i < myTable.getColumnCount(); i++) {
// Create <p:column>.
Column column = new Column();
table.getChildren().add(column);
// Create <h:outputText value="dynamicHeaders[i]"> for <f:facet name="header"> of column.
HtmlOutputText header = new HtmlOutputText();
header.setValue(this.getColumnTitle(this.getRenderedColumnNames().get(i)));
column.setHeader(header);
// Create <h:outputText value="#{dynamicItem[" + i + "]}"> for the body of column.
HtmlOutputText output = new HtmlOutputText();
output.setValueExpression("value", createValueExpression("#{row[" + i + "]}", String.class));
column.getChildren().add(output);
}
// export
try {
exporter.export(context, table, outputFileName, isPageOnly, isSelectionOnly, encodingType, preProcessor, postProcessor);
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
here's the xhtml of the command button:
<h:form>
<p:commandButton value="#{cc.attrs.exportXLS}" style="margin-top: 5px; width: 100%"
actionListener="#{cc.attrs.view.export(cc.attrs.bean, cc.attrs.view.tableOfData, "xls")}"
ajax="false" />
</h:form>
some information: bean is a simple viewscoped bean which stores the generated list (in function) for exporting it.
myTable contains the data which should be exported (will be transfered into an list of object array in function)
format contains "csv" or "xls".
here is the stacktrace:
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:678)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:213)
at com.sun.faces.context.ExternalContextImpl.getResponseOutputWriter(ExternalContextImpl.java:837)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1197)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:408)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:612)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
anybody got an idea why I get this excpetion?
kind regards
Alex
I solved the problem by adding the following line after the export call:
context.responseComplete();
i just installed a OpenLDAP server and trying to connect, add, get users,groups on it.
Since i 'm very new on ldap it would be very nice if you share tutorials about spring-ldap :/
So here's my bind code:
User class:
public class User implements Serializable{
private String id;
private String userName;
private String firstName;
private String lastName;
private String email;
private String password;
private String department;
private String groups[];
}
save method:
public User save( final User user ){
init();
Name dn = buildDn( user );
Attributes attributes = buildAttributes( user );
logger.info( "trying to save DN " + dn + " and attributes " + attributes );
ldapTemplate.bind( dn, null, attributes );
// Update Groups
for( String group : user.getGroups() ){
try{
DistinguishedName groupDn = new DistinguishedName();
groupDn.add( "ou", "Groups" );
groupDn.add( "cn", group );
DirContextOperations context = ldapTemplate.lookupContext( groupDn );
context.addAttributeValue( "memberUid", user.getUserName() );
ldapTemplate.modifyAttributes( context );
}
catch( Exception e ){
e.printStackTrace();
}
}
logger.info( "successfuly saved " );
return user;
}
buildDN:
private Name buildDn( final User user ){
DistinguishedName dn = new DistinguishedName();
dn.add( "ou", "People" );
if( user.getDepartment() != null ){
dn.add( "ou", user.getDepartment() );
}
dn.add( "uid", user.getUserName() );
return dn;
}
buildAttributes:
private Attributes buildAttributes( final User user ){
Attributes attrs = new BasicAttributes();
BasicAttribute ocattr = new BasicAttribute( "objectClass" );
// ocattr.add( "person" );
ocattr.add( "inetOrgPerson" );
attrs.put( ocattr );
attrs.put( "cn", user.getFirstName() );
// attrs.put( "rdn", "uid" ); // TODO check how to assign rdn
attrs.put( "sn", user.getLastName() );
attrs.put( "userPassword", "{SHA}" + this.encrypt( user.getPassword() ) );
attrs.put( "mail", user.getEmail() );
return attrs;
}
and here's the exception:
org.springframework.ldap.NameNotFoundException: [LDAP: error code 32 - No Such Object]; nested exception is javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'uid=sercan,ou=People'
at org.springframework.ldap.support.LdapUtils.convertLdapException(LdapUtils.java:183)
at org.springframework.ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:820)
at org.springframework.ldap.core.LdapTemplate.executeReadWrite(LdapTemplate.java:812)
at org.springframework.ldap.core.LdapTemplate.bind(LdapTemplate.java:990)
at com.***.usr.mng.library.service.impl.UserServiceImpl.save(UserServiceImpl.java:101)
at com.***.usr.mng.library.handler.impl.UserHandlerImpl.saveUser(UserHandlerImpl.java:45)
at com.***.usr.mng.library.handler.impl.UserManagementHandlerImpl.handleRequest(UserManagementHandlerImpl.java:62)
at com.***.usr.mng.service.controller.UserManagementController.processRequest(UserManagementController.java:83)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:685)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:919)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:851)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:953)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:844)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:829)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:313)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.naming.NameNotFoundException: [LDAP: error code 32 - No Such Object]; remaining name 'uid=sercan,ou=People'
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3112)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3033)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2840)
at com.sun.jndi.ldap.LdapCtx.c_bind(LdapCtx.java:420)
at com.sun.jndi.toolkit.ctx.ComponentDirContext.p_bind(ComponentDirContext.java:295)
at com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.bind(PartialCompositeDirContext.java:215)
at javax.naming.directory.InitialDirContext.bind(InitialDirContext.java:182)
at org.springframework.ldap.core.LdapTemplate$21.executeWithContext(LdapTemplate.java:992)
at org.springframework.ldap.core.LdapTemplate.executeWithContext(LdapTemplate.java:817)
While the code you present will certainly work for doing what you want there are a couple of things included in the library that will make things easier for you.
The simplest approach is to use the Object-Directory-Mapping - ODM - feature, which pretty much removes all boiler plate and uses declarative mapping on the domain classes instead.
If you decide to continue using DirContextAdapter I would encourage you to take full advantage of what it can do (more specifically you can submit a DirContextOperation instance directly to the designated bind method):
Name dn = buildDn(user);
DirContextAdapter context = new DirContextAdapter(dn);
context.setAttributeValues("objectclass", new String[] {"top", "person"});
context.setAttributeValue("cn", user.getFullname());
// populate more attributes
ldapTemplate.bind(context);
The reference documentation has plenty of examples, and there are also a couple of sample applications included with the source to help you get started (there's one simple sample using ODM, another one using DirContextOperations, and finally a complete user admin application using ODM).
Finally, please note that the DistinguishedName class is deprecated in version 2.x; you should use the LdapNameBuilder or the utility methods in LdapUtils for working with Distinguished Names (which you will typically not have to do if you use ODM).
I found the solution,
dn.add( "ou", "People" );
i'm trying to add person to People organizational unit, but it does not exist !
Thanks.