Jsp 为什么我的表单在提交时在Struts中抛出一个没有Bean指定的错误?

Jsp 为什么我的表单在提交时在Struts中抛出一个没有Bean指定的错误?,jsp,jakarta-ee,struts-1,Jsp,Jakarta Ee,Struts 1,我有一个dynaAction表单设置,提交给lookupDispatchAction。问题是页面加载正常,但提交时应用程序抛出一个[BeanUtils.populate],带有根本原因java.lang.IllegalArgumentException:没有指定bean,目前我似乎无法捕获堆栈转储,但它并没有指出这是在代码中的何处引起的。只有通过撤销修改后的代码,我才能将原因识别为下面打印的jsp中代码的一部分。目前,我正试图看看是否可以从调试器中获得更多信息,但到目前为止,研究已经暗示了可能的

我有一个dynaAction表单设置,提交给lookupDispatchAction。问题是页面加载正常,但提交时应用程序抛出一个[BeanUtils.populate],带有根本原因java.lang.IllegalArgumentException:没有指定bean,目前我似乎无法捕获堆栈转储,但它并没有指出这是在代码中的何处引起的。只有通过撤销修改后的代码,我才能将原因识别为下面打印的jsp中代码的一部分。目前,我正试图看看是否可以从调试器中获得更多信息,但到目前为止,研究已经暗示了可能的原因,这些都没有帮助。 下面是代码的相关部分(跳过堆栈跟踪以保持此帖子的合理性): struts-config.xml:

 <form-bean name="MonthlyInvoiceForm" type="com.myapp.form.accounting.MonthlyInvoiceForm">
                <form-property name="idMonthInvoice" type="java.lang.Long"/>
                <form-property name="creationDate" type="java.util.Date"/>
                <form-property name="adresse" type="com.myapp.model.component.CustomerAddress"/>
                <form-property name="extras" type="com.myapp.accounting.customer.ExtraInvoiceForm[]"/>
                <form-property name="creationLoc" initial="Home" type="java.lang.String"/>
                <form-property name="totalHT" type="java.math.BigDecimal"/>
                <form-property name="totalTTC" type="java.math.BigDecimal"/>
                <form-property name="prefix" type="java.lang.Integer"/>
                <form-property name="number" type="java.lang.String"/>
                <form-property name="person" type="java.lang.String"/>
                <form-property name="strTotalHT" type="java.lang.String"/>
                <form-property name="strTotalTTC" type="java.lang.String"/>
                <form-property name="customerName" type="java.lang.String"/>
                <form-property name="strIdCustomer" type="java.lang.String"/>
                <form-property name="strCreationDate" type="java.lang.String"/>
        </form-bean> 

表单本身具有以下设置:

public class MonthlyInvoiceForm extends BaseDynaForm implements ModelForm<MonthlyInvoice>{

@Override
public void reset(ActionMapping mapping, HttpServletRequest request) {
    ExtraInvoiceForm[] extraForms = new ExtraInvoiceForm[1];
    this.set("extras", extraForms);

    CustomerAddress caddress = new CustomerAddress();
    this.set("adresse", caddress);

    BigDecimal tmpTRD = new BigDecimal(BigInteger.ZERO);
    this.set("totalHT", tmpTRD);


    BigDecimal tmpTRM = new BigDecimal(BigInteger.ZERO);
    this.set("totalTTC", tmpTRM);
}

@Override
public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();

    ExtraInvoiceForm[] extraInvoiceForms = (ExtraInvoiceForm[]) this.get("extras");
    LinkedList<String> credits = new LinkedList<String>(); 
    LinkedList<String> reductions = new LinkedList<String>(); 

    for(ExtraInvoiceForm eif: extraInvoiceForms) {
        eif.validate(errors);

        if(!eif.isBlank()) {
            if(eif.getOperation().equals(ExtraCostInvoice.CREDITOPERATION)) {
                if(credits.contains(eif.getDescription()))
                    errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("invoice.duplicate.credit", eif.getDescription()));
                else
                    credits.add(eif.getDescription());
            } else {
                if(reductions.contains(eif.getDescription()))
                    errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("invoice.duplicate.reduction", eif.getDescription()));
                else
                    reductions.add(eif.getDescription());
            }
        }
    }


    if (StringUtils.isEmpty(this.get("strCreationDate").toString()))
        errors.add("strCreationDate",new ActionError("field.required"));

    if (StringUtils.isEmpty(this.get("creationLoc").toString()))
        errors.add("creationLoc",new ActionError("field.required"));



    return errors;
}

@Override
public void populateModel(MonthlyInvoice model) throws Exception {
    DateTimeFormatter fmt = DateTimeFormat.forPattern("dd MMMM yyyy");
    DateTime crDate;


    crDate = new DateTime(fmt.withLocale(Locale.FRENCH).parseDateTime(this.get("strCreationDate").toString()));
    this.set("creationDate",BaseForm.jodaToSqlDate(crDate));

    PropertyUtils.copyProperties(model, this);
}
公共类MonthlyInvoiceForm扩展BaseDynaForm实现ModelForm{
@凌驾
公共无效重置(ActionMapping映射,HttpServletRequest请求){
ExtraInvoiceForm[]extraForms=新的ExtraInvoiceForm[1];
本.集(“附加”,附加形式);
CustomerAddress CadAddress=新CustomerAddress();
本套(“ADRESE”,caddress);
BigDecimal tmpTRD=新的BigDecimal(BigInteger.ZERO);
此.set(“totalHT”,tmpTRD);
BigDecimal tmpTRM=新的BigDecimal(BigInteger.ZERO);
此.set(“totalTTC”,tmpTRM);
}
@凌驾
公共ActionErrors验证(ActionMapping ActionMapping、HttpServletRequest请求){
ActionErrors=新的ActionErrors();
ExtraInvoiceForm[]extraInvoiceForms=(ExtraInvoiceForm[])this.get(“extras”);
LinkedList credits=新建LinkedList();
LinkedList reduces=新建LinkedList();
对于(ExtraInvoiceForm eif:extraInvoiceForms){
验证(错误);
如果(!eif.isBlank()){
if(eif.getOperation().equals(ExtraCostInvoice.CREDITOPERATION)){
if(credits.contains(eif.getDescription()))
添加(ActionErrors.GLOBAL_ERROR,new ActionError(“invoice.duplicate.credit”,eif.getDescription());
其他的
credits.add(eif.getDescription());
}否则{
if(reduces.contains(eif.getDescription()))
errors.add(ActionErrors.GLOBAL_ERROR,newactionError(“invoice.duplicate.reduce”,eif.getDescription());
其他的
add(eif.getDescription());
}
}
}
if(StringUtils.isEmpty(this.get(“strCreationDate”).toString())
错误。添加(“strCreationDate”,新操作错误(“field.required”);
if(StringUtils.isEmpty(this.get(“creationLoc”).toString())
错误。添加(“creationLoc”,新操作错误(“field.required”);
返回错误;
}
@凌驾
public void populateModel(MonthlyInvoice模型)引发异常{
DateTimeFormatter fmt=DateTimeFormat.forPattern(“dd-MMMM-yyyy”);
日期时间;
crDate=newdatetime(fmt.withLocale(Locale.FRENCH).parseDateTime(this.get(“strCreationDate”).toString());
这个.set(“creationDate”,BaseForm.jodaToSqlDate(crDate));
PropertyUtils.copyProperties(模型,this);
}
jsp:

<html:form action="/toInvoiceCustomerMissions"> 
/*This is the part of code in the jsp which causes the error*/
<c:forEach var="extras" items="${MonthlyInvoiceForm.map.extras}" varStatus="vs">
                    <tr>
                        <td align="center">
                                                    <html:text indexed="true" name="extras" property="description" size="40" maxlength="100" /></td>
                        <td align="center">
                                                    <html-el:radio indexed="true" name="extras" property="operation"
                            value="<%= ExtraCostInvoice.CREDITOPERATION %>"
                            onclick="setPercentSymbol(${vs.index}, false); calcCustomerAmount();" />Déduction
                                                    <html-el:radio indexed="true" name="extras" property="operation"
                            value="<%= ExtraCostInvoice.REDUCTIONOPERATION %>"
                            onclick="setPercentSymbol(${vs.index}, true); calcCustomerAmount();" />Réduction
                                                    <html-el:radio indexed="true" name="extras" property="operation"
                            value="<%= ExtraCostInvoice.SUPPLEMENTOPERATION %>"
                            onclick="setPercentSymbol(${vs.index}, false); calcCustomerAmount();" />Supplément
                        </td>
                        <td align="center">
                                                    <html:text indexed="true" name="extras"
                            property="strAmount" size="7" maxlength="6" onchange="calcCustomerAmount();" />
                                                    <input type="text" id="extraSymbol<c:out value='${vs.index}'/>" value="&euro;"
                            readonly="readonly" size="1" style="border: none">
                                                </td>
                    </tr>
                </c:forEach>
</html:form>

/*这是jsp中导致错误的代码部分*/
归纳法
还原
补给

提前感谢

解决了这个问题。事实证明,您还需要迭代分配数组的每个元素,并使用重置方法对其进行初始化;在这种情况下,ExtraInvoiceForm[]extraInvoiceForms必须对每个元素进行初始化