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

Openxava: Hold Url Parameter into Session Object

我正在使用会话来保存 url 参数年份(例如 http://localhost:8080/CkSurvey/m/Sport?Year=2016)。我已经为会话编写了所有代码,但它仅适用于我上传图像之前的第一个条目。 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"/> 

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

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

有关详细信息,请参阅解决方案:https://sourceforge.net/p/openxava/discussion/419690/thread/9ff8f067/?limit=25&page=1#632c