0

我的网站上有一个表单,它询问用户信息(如姓名、地址等),主要是字符串、一个 int 和一个 ArrayList。我使用 Spring webflow 主要是为了允许查看视图状态,以便用户可以返回并编辑字段,并且因为我也使用了一些其他表单,所以我试图保持我的代码一致。

我遇到的问题是我的 Arraylist。我希望用户最多可以添加 10 位医生(姓名、保单编号、专业),但我不断收到 BeanException 和错误消息,表明我的列表为空。当我单击评论按钮转到下一个视图时,页面将重新加载并抛出我在底部发布的错误。

这是我的 spring webflow 的一部分: 在视图 PracticeReviewRequest 我用一个新的 Arraylist 实例化我的 arrayList

    <set name="flowScope.pageDescription" value="'Please complete the form below to submit your request for a practice review.'"/>
</on-start>

<view-state id="practiceReviewRequest" view="/components/risk/practiceReview" model="practiceReviewForm">
    <on-entry>
        <set name="flowScope.practiceReviewForm.physicians" value="new java.util.ArrayList()"/>
    </on-entry>
    <transition on="review" to="practiceReviewRequestReview"/>
    <transition on-exception="org.tmlt.data.dao.DataAccessException" to="practiceReviewRequest">
        <set name="flowScope.exception" value="rootCauseException"/>
    </transition>
</view-state>

<view-state id="practiceReviewRequestReview" view="/components/risk/email">
    <transition on="submit" to="practiceReviewRequestSubmit"/>
    <transition on-exception="org.tmlt.data.dao.DataAccessException" to="practiceReviewRequest">
        <set name="flowScope.exception" value="rootCauseException"/>
    </transition>
</view-state>

这是我的 Object practiceReviewRequest 的艺术

@XmlAccessorType(XmlAccessType.FIELD) 公共类 PracticeReviewRequestImpl 实现 IPracticeReviewRequest, Serializable {

private static final long serialVersionUID = 1L;

private String submitName;
private String policyType;
private String groupName;
private String policyNumber;
private int physNum;
private List<IPracticeReviewRequest> physicians = new ArrayList<>(15);

@Override
public List<IPracticeReviewRequest> getPhysicians() {
    return physicians;
}

@Override
public void setPhysicians(List<IPracticeReviewRequest> physicians) {
    this.physicians = physicians;
}

@Override
public int getPhysNum() {
    return physNum;
}

...

这是我的医师对象: public class PracticeReviewRequestPhysicianImpl implements IPracticeReviewRequestPhysician, Serializable {

private static final long serialVersionUID = 1L;

private String name;
private String policyNumber;
private String specialty;

@Override
public String getName() {
    return name;
}

@Override
public String getPolicyNumber() {
    return policyNumber;
}

@Override
public String getSpecialty() {
    return specialty;
}

@Override
public void setName(String name) {
    this.name = name;
}

@Override
public void setPolicyNumber(String policyNumber) {
    this.policyNumber = policyNumber;
}

@Override
public void setSpecialty(String specialty) {
    this.specialty = specialty;
}

...

这是我的 .ftl 的一部分(为了解决这个问题,我只硬编码一个外业医师 [0].name,而不是使用我的 JS 函数循环医师 [i].name 等......)(这就是全部在包含隐藏输入类型 flowExecutionKey 的表单标签内)

这是我在我的 tomcat 中看到的错误消息。

2018-04-12 11:00:15,916 调试 springframework.binding.mapping.impl.DefaultMapper:源 [org.springframework.webflow.core.collection.LocalParameterMap] 和目标 [org.tmlt.data.model.impl 之间的开始映射.PracticeReviewRequestImpl] 2018-04-12 11:00:15,923 调试pringframework.binding.mapping.impl.DefaultMapping:添加映射结果[TargetAccessError@c60ad7映射=参数:'执行'->执行,代码='propertyNotFound',错误= true,errorCause = org.springframework.binding.expression.PropertyNotFoundException:找不到属性, originalValue = 'e7s1',mappedValue = [null]] 2018-04-12 11:00:15,924 调试 pringframework.binding.mapping.impl.DefaultMapping : 添加映射结果 [Success@122d6f5 mapping = parameter:'submitName' -> submitName, code = 'success', error = false,originalValue = 'Test', mappedValue = 'Test'] 2018-04-12 11:00:15,924 调试pringframework.binding.mapping.impl.DefaultMapping:添加映射结果[Success@6ced27 mapping = parameter:'policyType' -> policyType , code = 'success', error = false, originalValue = 'Yes', mappedValue = 'Yes'] 2018-04-12 11:00:15,925 DEBUG pringframework.binding.mapping.impl.DefaultMapping: 添加映射结果[Success@ 769c4 映射 = 参数:'groupName' -> groupName,code = 'success',error = false,originalValue = 'Tset', mappedValue = 'Tset'] 2018-04-12 11:00:15,925 DEBUG pringframework.binding.mapping .impl.DefaultMapping: 添加映射结果 [Success@ae3690 mapping = parameter:'policyNumber' -> policyNumber, code = 'success', error = false,originalValue = 'SEt1', mappedValue = 'SEt1'] 2018-04-12 11:00:15,925 DEBUG pringframework.binding.mapping.impl.DefaultMapping:添加映射结果 [Success@1ded18e mapping = parameter:'physNum' -> physNum , code = 'success', error = false, originalValue = '1', mappedValue = '1'] 2018-04-12 11:00:15,925 DEBUG pringframework.binding.mapping.impl.DefaultMapping: 添加映射结果 [TargetAccessError@ 1c1147映射=参数:'physicians[0].name'->医师[0].name,code ='evaluationException',error = true,errorCause = org.springframework.binding.expression.EvaluationException:设置值时发生BeansException上下文 [class org.tmlt.data.model.impl.PracticeReviewRequestImpl] 到 [Ttest] 上的表达式 'physicians[0].name',originalValue = 'Ttest', mappedValue = [null]] 2018-04-12 11:00:15,926 DEBUG pringframework.binding.mapping.impl.DefaultMapping: 添加映射结果 [TargetAccessError@1461909 mapping = null -> eventId_review, code = 'propertyNotFound', error = true,errorCause = org.springframework.binding.expression.PropertyNotFoundException:找不到属性,originalValue = [null],mappedValue =enter code here[null]] 2018-04-12 11:00:15,927 调试 springframework.binding.mapping.impl.DefaultMapper:完成源 [org.springframework.webflow.core.collection.LocalParameterMap] 和目标 [org.tmlt.data 之间的映射.model.impl.PracticeReviewRequestImpl]; 总映射 = 8;错误总数 = 3 2018-04-12 11:00:15,927 DEBUG g.springframework.webflow.mvc.view.AbstractMvcView:模型绑定导致错误;将错误消息添加到上下文 2018-04-12 11:00:15,931 DEBUG ingframework.binding.message.DefaultMessageContext:使用 [DefaultMessageResolver@dc00ab 源 = 'physicians[0].name',严重性 = 错误,代码 = 数组 [ 'practiceReviewForm.physicians[0].name.evaluationException'、'practiceReviewForm.physicians.name.evaluationException'、'physicians[0].name.evaluationException'、'physicians.name. URL [/MyTMLT/templates/components/mytmlt/myTMLTComponent.ftl]] 2018-04-12 11:00:15,934 调试 org.springframework.webflow.engine.ViewState:Flash 范围 = map[[empty]] 2018-04- 12 11:00:15,934 调试 org.springframework.webflow.engine.ViewState:Messages = [DefaultMessageContext@19f94a4 sourceMessages = map[[null] -> list[[empty]],'physicians[0].name' -> list [[Message@17402e3 source = 'physicians[0].name',severity = ERROR,text = 'evaluationException on doctors[0].name']]]] 2018-04-12 11:00:15,935 调试 g.springframework .webflow.mvc.view.AbstractMvcView: 渲染 MVC [info.magnolia.module.blossom.view.TemplateView: name '/components/risk/practiceReview'; URL [/MyTMLT/templates/components/mytmlt/myTMLTComponent.ftl]] 与模型图 [{currentUser=null, viewScope=map[[empty]], riskpracticereviewrequest-flow', flowSessions = list[[FlowSessionImpl@ec7f63 flow = 'riskpracticereviewrequest-flow', state = 'practiceReviewRequest', scope = map['viewScope' -> map[[empty]], 'componentTemplatePath' -> '/ MyTMLT/templates/components/risk/practiceReview.ftl', 'pageDescription' -> '请填写下面的表格以提交您的实践审查请求。', 'practiceReviewForm' -> org.tmlt.data.model.impl。 PracticeReviewRequestImpl@174ec05]]]]], org.springframework.validation.BindingResult.practiceReviewForm=org.springframework.webflow.mvc.view.BindingModel: 1 错误字段 'physicians[0].name' 上的对象'practiceReviewForm' 中的字段错误: 拒绝值 [null]; 代码 []; 论据 []; 默认消息 [evaluationException on doctors[0]。

请让我知道,如果你有任何问题。我整个星期都被困在这上面。感谢您的时间。

4

1 回答 1

0

我通过在我的对象 impl 类 PracticeReviewRequestPhysicianImpl 中实例化我的 ArrayList 来解决我的问题,如果我的 ArrayList 为空

 public List<IPracticeReviewRequestPhysician> getPhysicians() {
        if(physicians.isEmpty()){
            for(int i = 0;i < MAX_PHYSICIANS;i++) {


  physicians.add(TMLTObjectFactory.getNewPracticeReviewPhysician());
            }
        }
        return physicians;
    }

我的错误的原因是我正在为一个不存在的索引分配一个值,从而导致 indexoutofbounds 异常。我的日志中有一些线索抱怨我的清单是空的。

于 2018-04-20T14:52:49.980 回答