Openxava:将URL参数保存到会话对象中

时间:2017-05-15 08:23:34

标签: session url-parameters openxava

我正在使用session来保存url参数year(例如http://localhost:8080/CkSurvey/m/Sport?Year=2016)。我已经为会话编写了所有代码,但它只适用于我上传图像之前的第一个条目。更改URL后,会话对象holded无法检索和加载。

以下是我的尝试:

Sport.java

<html>
<body>
<video controls="controls">
    <source src="shuttle.mp4" type="video/mp4">
    <source src="shuttle.ogv" type="video/ogg">
    Your browser does not support the HTML5 Video element.
</video>
</body>
</html>

SessionUrlParamsAction.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;
    }

}

controllers.xml(action)

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); 

    }

}

我应该做哪些更改才能成功保存和检索会话对象?

1 个答案:

答案 0 :(得分:0)

通过添加initAction和saveAction解决了问题。 initAction获取url参数值,而saveAction将值设置为相应的属性字段。

有关详细信息,请参阅解决方案:here