将DatePicker转换为java.util.Date
我在Vaadin 11中有一个日期选择器,我正试图绑定到日期字段。看起来像这样的东西会起作用:将DatePicker转换为java.util.Date,java,vaadin11,Java,Vaadin11,我在Vaadin 11中有一个日期选择器,我正试图绑定到日期字段。看起来像这样的东西会起作用: getBinder().forField(datePicker) .withConverter(new LocalDateTimeToDateConverter(ZoneId.systemDefault())) .bind(MatchEntry::getMatchDate, MatchEntry::setMatchDate); 但我得到了以下错误: n
getBinder().forField(datePicker)
.withConverter(new LocalDateTimeToDateConverter(ZoneId.systemDefault()))
.bind(MatchEntry::getMatchDate, MatchEntry::setMatchDate);
但我得到了以下错误:
no suitable method found for withConverter(com.vaadin.flow.data.converter.LocalDateTimeToDateConverter)
method com.vaadin.flow.data.binder.Binder.BindingBuilder.<NEWTARGET>withConverter(com.vaadin.flow.data.converter.Converter<java.time.LocalDate,NEWTARGET>) is not applicable
(cannot infer type-variable(s) NEWTARGET
(argument mismatch; com.vaadin.flow.data.converter.LocalDateTimeToDateConverter cannot be converted to com.vaadin.flow.data.converter.Converter<java.time.LocalDate,NEWTARGET>))
method com.vaadin.flow.data.binder.Binder.BindingBuilder.<NEWTARGET>withConverter(com.vaadin.flow.function.SerializableFunction<java.time.LocalDate,NEWTARGET>,com.vaadin.flow.function.SerializableFunction<NEWTARGET,java.time.LocalDate>) is not applicable
(cannot infer type-variable(s) NEWTARGET
(actual and formal argument lists differ in length))
method com.vaadin.flow.data.binder.Binder.BindingBuilder.<NEWTARGET>withConverter(com.vaadin.flow.function.SerializableFunction<java.time.LocalDate,NEWTARGET>,com.vaadin.flow.function.SerializableFunction<NEWTARGET,java.time.LocalDate>,java.lang.String) is not applicable
(cannot infer type-variable(s) NEWTARGET
(actual and formal argument lists differ in length))
com/github/javydreamercsw/tournament/manager/ui/views/matchlist/MatchEditorDialog.java:[115,19] invalid method reference
non-static method getMatchDate() cannot be referenced from a static context
找不到适用于withConverter的方法(com.vaadin.flow.data.converter.LocalDateTimeToDateConverter)
方法com.vaadin.flow.data.binder.BindingBuilder.withConverter(com.vaadin.flow.data.converter.converter)不适用
(无法推断类型变量NEWTARGET
(参数不匹配;com.vaadin.flow.data.converter.LocalDateTimeToDateConverter无法转换为com.vaadin.flow.data.converter.converter))
方法com.vaadin.flow.data.binder.BindingBuilder.withConverter(com.vaadin.flow.function.SerializableFunction,com.vaadin.flow.function.SerializableFunction)不适用
(无法推断类型变量NEWTARGET
(实际参数列表和正式参数列表长度不同))
方法com.vaadin.flow.data.binder.binder.BindingBuilder.withConverter(com.vaadin.flow.function.SerializableFunction,com.vaadin.flow.function.SerializableFunction,java.lang.String)不适用
(无法推断类型变量NEWTARGET
(实际参数列表和正式参数列表长度不同))
com/github/javydreamercsw/tournament/manager/ui/views/matchlist/MatchEditorDialog.java:[115,19]无效的方法引用
无法从静态上下文引用非静态方法getMatchDate()
如果需要,下面是MatchEntry类:
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
@Entity
@Table(name = "match_entry")
@XmlRootElement
@NamedQueries(
{
@NamedQuery(name = "MatchEntry.findAll", query = "SELECT m FROM MatchEntry m"),
@NamedQuery(name = "MatchEntry.findById",
query = "SELECT m FROM MatchEntry m WHERE m.matchEntryPK.id = :id"),
@NamedQuery(name = "MatchEntry.findByRoundId",
query = "SELECT m FROM MatchEntry m WHERE m.matchEntryPK.roundId = :roundId"),
@NamedQuery(name = "MatchEntry.findByFormatId",
query = "SELECT m FROM MatchEntry m WHERE m.matchEntryPK.formatId = :formatId")
})
public class MatchEntry implements Serializable
{
private static final long serialVersionUID = 1L;
@EmbeddedId
protected MatchEntryPK matchEntryPK;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumns(
{
@JoinColumn(name = "FORMAT_ID", referencedColumnName = "ID",
insertable = false, updatable = false),
@JoinColumn(name = "GAME_ID", referencedColumnName = "ID",
insertable = false, updatable = false)
})
private Format format;
@ManyToOne(optional = true, fetch = FetchType.LAZY)
@JoinColumns(
{
@JoinColumn(name = "ROUND_ID", referencedColumnName = "ID",
insertable = false, updatable = false),
@JoinColumn(name = "TOURNAMENT_ID", referencedColumnName = "ID",
insertable = false, updatable = false)
})
private Round round;
@OneToMany(mappedBy = "matchEntry", fetch = FetchType.LAZY,
cascade = CascadeType.ALL)
private List<MatchHasTeam> matchHasTeamList;
@Basic(optional = false)
@Column(name = "match_date")
@Temporal(TemporalType.TIMESTAMP)
private Date matchDate;
public MatchEntry()
{
setMatchHasTeamList(new ArrayList<>());
}
public MatchEntry(MatchEntryPK matchEntryPK)
{
this.matchEntryPK = matchEntryPK;
}
public MatchEntry(int roundId, int formatId)
{
this.matchEntryPK = new MatchEntryPK(roundId, formatId);
}
public MatchEntryPK getMatchEntryPK()
{
return matchEntryPK;
}
public void setMatchEntryPK(MatchEntryPK matchEntryPK)
{
this.matchEntryPK = matchEntryPK;
}
public Format getFormat()
{
return format;
}
public void setFormat(Format format)
{
this.format = format;
}
public Round getRound()
{
return round;
}
public void setRound(Round round)
{
this.round = round;
}
public List<MatchHasTeam> getMatchHasTeamList()
{
return matchHasTeamList;
}
public final void setMatchHasTeamList(List<MatchHasTeam> matchHasTeamList)
{
this.matchHasTeamList = matchHasTeamList;
}
@Override
public int hashCode()
{
int hash = 0;
hash += (matchEntryPK != null ? matchEntryPK.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object)
{
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof MatchEntry))
{
return false;
}
MatchEntry other = (MatchEntry) object;
return !((this.matchEntryPK == null && other.matchEntryPK != null)
|| (this.matchEntryPK != null
&& !this.matchEntryPK.equals(other.matchEntryPK)));
}
@Override
public String toString()
{
return "MatchEntry[ matchEntryPK="
+ matchEntryPK + " ]";
}
public Date getMatchDate()
{
return matchDate;
}
public void setMatchDate(Date matchDate)
{
this.matchDate = matchDate;
}
}
import java.io.Serializable;
导入java.util.ArrayList;
导入java.util.Date;
导入java.util.List;
导入javax.persistence.Basic;
导入javax.persistence.CascadeType;
导入javax.persistence.Column;
导入javax.persistence.EmbeddedId;
导入javax.persistence.Entity;
导入javax.persistence.FetchType;
导入javax.persistence.JoinColumn;
导入javax.persistence.JoinColumns;
导入javax.persistence.manytone;
导入javax.persistence.namedquerys;
导入javax.persistence.NamedQuery;
导入javax.persistence.OneToMany;
导入javax.persistence.Table;
导入javax.persistence.Temporal;
导入javax.persistence.TemporalType;
导入javax.xml.bind.annotation.XmlRootElement;
@实体
@表(name=“匹配项”)
@XmlRootElement
@命名查询(
{
@NamedQuery(name=“MatchEntry.findAll”,query=“从MatchEntry m中选择m”),
@NamedQuery(name=“MatchEntry.findById”,
query=“从匹配条目m中选择m,其中m.matchEntryPK.id=:id”),
@NamedQuery(name=“MatchEntry.findByRoundId”,
query=“从匹配条目m中选择m,其中m.matchEntryPK.roundId=:roundId”),
@NamedQuery(name=“MatchEntry.findByFormatId”,
query=“从匹配条目m中选择m,其中m.matchEntryPK.formatId=:formatId”)
})
公共类MatchEntry实现可序列化
{
私有静态最终长serialVersionUID=1L;
@嵌入ID
受保护的MatchEntryPK MatchEntryPK;
@manytone(fetch=FetchType.LAZY,可选=false)
@连接柱(
{
@JoinColumn(name=“FORMAT\u ID”,referencedColumnName=“ID”,
可插入=false,可更新=false),
@JoinColumn(name=“GAME\u ID”,referencedColumnName=“ID”,
可插入=false,可更新=false)
})
私有格式;
@manytone(可选=true,fetch=FetchType.LAZY)
@连接柱(
{
@JoinColumn(name=“ROUND\u ID”,referencedColumnName=“ID”,
可插入=false,可更新=false),
@JoinColumn(name=“TOURNAMENT\u ID”,referencedColumnName=“ID”,
可插入=false,可更新=false)
})
私人圆桌会议;
@OneToMany(mappedBy=“matchEntry”,fetch=FetchType.LAZY,
级联=级联类型(全部)
私人名单;
@基本(可选=假)
@列(name=“匹配日期”)
@时态(TemporalType.TIMESTAMP)
私人日期匹配日期;
公共匹配条目()
{
setMatchHasteaList(新ArrayList());
}
公共匹配条目(MatchEntryPK MatchEntryPK)
{
this.matchEntryPK=matchEntryPK;
}
公共匹配项(int-roundId、int-formatId)
{
this.matchEntryPK=新的matchEntryPK(roundId,formatId);
}
公共MatchEntryPK getMatchEntryPK()
{
返回matchEntryPK;
}
公共无效setMatchEntryPK(MatchEntryPK MatchEntryPK)
{
this.matchEntryPK=matchEntryPK;
}
公共格式getFormat()
{
返回格式;
}
公共void setFormat(格式)
{
this.format=格式;
}
公共回合
{
回程;
}
公共空间圆形(圆形)
{
这个圆=圆;
}
公共列表getMatchHasteaList()
{
返回匹配列表;
}
公共最终作废SetMatchHasteaList(列表MatchHasteaList)
{
this.matchHasTeamList=matchHasTeamList;
}
@凌驾
公共int hashCode()
{
int hash=0;
hash+=(matchEntryPK!=null?matchEntryPK.hashCode():0);
返回散列;
}
@凌驾
公共布尔等于(对象)
{
//TODO:警告-如果未设置id字段,此方法将不起作用
if(!(匹配项的对象实例))
{
返回false;
}
MatchEntry other=(MatchEntry)对象;
return!((this.matchEntryPK==null&&other.matchEntryPK!=null)
||(this.matchEntryPK!=null
&&!this.matchEntryPK.equals(other.matchEntryPK));
}
@凌驾
公共字符串toString()
{
return“MatchEntry[matchEntryPK=”
+matchEntryPK+“]”;
}
公共日期getMatchDate()
{
返回匹配日期;
}
公共无效设置匹配日期(日期匹配日期)
{
this.matchDate=匹配日期;
}
}
java.time
您可以使用(或)代替旧的日期
它更易于管理,并且有自动设置日期格式的方法 java.time
您可以使用(或)代替旧的日期