I am using session to hold the url parameters year (eg. http://localhost:8080/CkSurvey/m/Sport?Year=2016). I have wrote all the codes for session but it only works for the first entry before I upload an image. After the url changed, the session object holded fail to retrieve and load.
Here are my attempts:
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)
<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"/>
What changes should I do to successfully hold and retrieve the session object?
Problem solved by adding initAction and saveAction. initAction gets the url parameter value whereas saveAction sets the value to respective property field.
For more detail, refer to the solution at: https://sourceforge.net/p/openxava/discussion/419690/thread/9ff8f067/?limit=25&page=1#632c