0
@AllArgsConstructor
@NoArgsConstructor
@Data
public class JobDto {
    private Long JobId;
    private String jobName;
    private String jobDesc;
    private String status;
    private boolean isScheduled;
    private String cronExpression;
    private InputSourceDto inputSource;
    private OutputSourceDto outputSource;
}
        jobBinder.bind(jobName, JobDto::getJobName, JobDto::setJobName);
        jobBinder.bind(jobDesc, JobDto::getJobDesc, JobDto::setJobDesc);
        jobBinder.forField(jobType).bind(job -> job.getOutputSource().getType(),(job,jobType) -> job.getOutputSource().setType(jobType));
        jobBinder.forField(dbUrl).bind(job -> job.getOutputSource().getConnection().getDbUrl(),(job,dbUrl) -> job.getOutputSource().getConnection().setDbUrl(dbUrl));
        jobBinder.forField(dbUserName).bind(job -> job.getOutputSource().getConnection().getDbUserName(),(job,dbUserName) -> job.getOutputSource().getConnection().setDbUserName(dbUserName));
        jobBinder.forField(dbUserPassword).bind(job -> job.getOutputSource().getConnection().getDbUserPassword(),(job,dbUserPassword) -> job.getOutputSource().getConnection().setDbUserPassword(dbUserPassword));
        jobBinder.forField(dbDriverClass).bind(job -> job.getOutputSource().getConnection().getDbDriverClass(),(job,dbDriverClass) -> job.getOutputSource().getConnection().setDbDriverClass(dbDriverClass));
        etCronExpression, JobDto ::setCronExpression);
     

my binder worked perfectly when I connected directly with the entity classes directly. Now after using the dtos it gives me a null pointer error when I try to get a nested attribute

I want to know solutions when using vaadin binder with nested dtos

  • Where does the null pointer exception come from? Looking at the code, you must ensure that dto getters for intermediate objects always returns a valid instance – Marco C Mar 18 '23 at 09:24
  • getters are defined by Lombok – Buddhima Chamaranga Mar 18 '23 at 15:29
  • Vaadin will not populate the intermediate objects. So you should set them by your self, for example in the bind callbacks, or you can explicitly defined getters instead of autogenerating them or you can populate the dto before passing it to the binder – Marco C Mar 18 '23 at 16:32
  • even after setting up getters setters without lombok it gives me same error, could please show me a example of a bind callback? – Buddhima Chamaranga Mar 19 '23 at 03:01
  • Please update the question with your new insights. Ideally provide a [MRE](https://stackoverflow.com/help/minimal-reproducible-example) – cfrick Mar 19 '23 at 14:58
  • For example if `job.getOutputSource()` can return null, then you will have NPE. So you need to improve your getter and setter lambda code to handle the possible null values accordingly. This cannot be handled by Vaadin framework automatically, as the decisions upon those are highly application specific. E.g. in some applications you do not want to add anything there if NPE indeed should be thrown to indicate data corruption being happened. – Tatu Lund Mar 20 '23 at 12:47
  • I made those UIdto's simple, by excluding nested dto's – Buddhima Chamaranga Mar 20 '23 at 17:05

0 Answers0