0
我使用會話來保存url參數year(例如。http://localhost:8080/CkSurvey/m/Sport?Year=2016)。我已經爲會話編寫了所有代碼,但它僅適用於上載圖像之前的第一個條目。更改url後,會話對象holded無法檢索和加載。Openxava:將Url參數保存到會話對象
這裏是我的嘗試:
Sport.java
package org.survey.model;
import java.math.*;
import java.util.*;
import javax.persistence.*;
import org.openxava.annotations.*;
import org.openxava.calculators.*;
import org.survey.actions.*;
import org.survey.calculators.*;
@Table(name="T_SPORT")
@View(members= "title; date; estimatedCost; attendance; remark; image; year")
@Entity
public class Youth {
//******************************FORM ID******************************//
@Id
@Hidden
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="YOUTH_ID", length=10, unique = true, nullable = false, updatable = false)
private int youthId;
//******************************TYPE/CATEGORY***
//******************************TITLE******************************//
@Column(name="YOUTH_TITLE", precision=2000)
@Required
private String title;
//******************************DATE******************************//
// @Stereotype("DATE")
@Column(name="YOUTH_DATE")
@Required
private Date date;
//******************************ESTIMATED COST******************************//
@Hidden
@Stereotype("MONEY")
@Column(name="YOUTH_EST_COST")
@Required
private BigDecimal estimatedCost; // Include the import java.math.* BigDecimal is typically used for money
//******************************ESTIMATED ATTENDEES******************************//
@Hidden
@Column(name="YOUTH_ATTENDANCE", length=10)
@Required
private int attendance;
//******************************REMARK******************************//
@Hidden
@Editor("TextAreaNoFrame")
@Stereotype("MEMO")
@Column(name="YOUTH_REMARK", precision=2000)
private String remark;
@Stereotype("PHOTO")
@Column(name="YOUTH_IMAGE")
private byte [] image;
//******************************URL PARAMETER (Year)******************************//
//@Hidden
@ReadOnly
//@DefaultValueCalculator(YearCalculator.class)
//@OnChange(GetParameterValueAction.class)
@Column(name="YOUTH_YEAR", length=4)
private String year;
//******************************GETTERS AND SETTERS FOR ALL PROPERTIES******************************//
public int getYouthId() {
return youthId;
}
public void setYouthId(int youthId) {
this.youthId = youthId;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public BigDecimal getEstimatedCost() {
return estimatedCost;
}
public void setEstimatedCost(BigDecimal estimatedCost) {
this.estimatedCost = estimatedCost;
}
public int getAttendance() {
return attendance;
}
public void setAttendance(int attendance) {
this.attendance = attendance;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public String getYear() {
return year;
}
public void setYear(String year) {
this.year = year;
}
public byte[] getImage() {
return image;
}
public void setImage(byte[] image) {
this.image = image;
}
}
SessionUrlParamsAction.java
package org.survey.actions;
import javax.inject.*;
import org.openxava.actions.*;
public class SessionUrlParamsAction extends SaveAction {
@Inject @Named("CkSurveysessionYear")
private String sessionYear;
private String uid;
@Override
public void execute() throws Exception {
sessionYear = getRequest().getParameter("Year");
getView().setValue("year", sessionYear);
super.execute();
System.out.println("year============" + sessionYear);
}
}
controllers.xml(動作)
<action name="save" mode="detail"
by-default="if-possible"
class="org.survey.actions.SessionUrlParamsAction"
image="save.gif"
icon="content-save"
on-init="true"
keystroke="Control S"/>
什麼樣的變化,我應該對蘇有效握住並檢索會話對象?