我在使用一个托管 bean 的页面中有两个命令。第一种方法创建一个游览,第二种方法将照片网址添加到该游览。但问题是,当我调用第二种方法时,我创建的游览丢失并返回 null。我该如何解决这个问题?
@ManagedBean(name="addtour")
@SessionScoped
public class CreateTourAction {
private Tour tour;
public String execute() {
tour = new Tour(this.date,this.province,this.country, this.category,transportation,this.gregarious,this.days, this.space,BigDecimal.valueOf(price));
tour.save();
return"success";
}
public void handleFileUpload(FileUploadEvent event) {
tour.setImg_urls(urls);
tour.save();
}
xml相关部分:
<h:commandButton value="Create" action="#{addTour.execute}"/>
<p:fileUpload fileUploadListener="#{addTour.handleFileUpload}" mode="advanced" dragDropSupport="true"
update="messages" sizeLimit="1000000" fileLimit="3" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />