简体   繁体   English

Struts索引属性—未找到用于属性的吸气方法

[英]Struts Indexed Property — no getter method found for property

So in struts I have an action form which has 5 properties. 因此,在struts中,我有一个具有5个属性的动作表单。 Each property is a String Array. 每个属性都是一个字符串数组。

in my form class i getter/setter methods for the properties like the ones below: 在我的表单类中,我使用getter / setter方法来获取以下属性:

public String getPropertyX(int index) {
  return x[index];
}

public void setPropertyX(int index, String value) {
  x[index] = value; 
}

When my form is first processed I populate the form object and when it displays the respective JSP i can tinker with it so it outputs the correct values using the struts tags and get the propper values for each array. 当我的表单第一次被处理时,我会填充表单对象,当它显示相应的JSP时,我可以对其进行修补,以便它使用struts标记输出正确的值并获取每个数组的适当值。 However, I want those to be inputs so when i submit the form the object/arrays will be populated for me. 但是,我希望将这些作为输入,因此当我提交表单时,将为我填充对象/数组。 However on submitting the form I get a "Error 500: No getter method for property." 但是,在提交表单时,我收到“错误500:属性没有getter方法”。 When I add the following to my form object I no longer get that error: 当我将以下内容添加到表单对象时,我不再收到该错误:

public String getPropertyX() {
   return x;
}

I no longer get that error, but now then it comes to a population error on the backend when i process the form. 我不再遇到该错误,但是现在在处理表单时,后端出现了填充错误。 I could do it another way but I'd much rather use the struts framework (i'm learning here). 我可以用另一种方式来做,但是我宁愿使用struts框架(我在这里学习)。

Figured it out on my own. 我自己弄清楚了。 Decided to go a whole different way. 决定走完全不同的方式。 Created two ActionForms (not really sure if the second one needed to be an ActionForm but it works). 创建了两个ActionForm(不确定第二个ActionForm是否需要一个ActionForm,但它可以工作)。 One contains the actual elements in the form I want to populate on each row of the form. 一个包含要在表单的每一行上填充的表单中的实际元素。 The other contains an Array of the other. 另一个包含另一个的数组。 I iterate through the array on the jsp and using indexed="true" on the inputs I achieve what i want. 我遍历jsp上的数组,并在输入上使用indexed =“ true”以实现所需的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM