[英]unknown property error struts2
I am developing a struts2 application. 我正在开发一个struts2应用程序。 I have a property in my jsp file, which need to refer to a property of an object that is in a list, but I run into unknown property error,
我的jsp文件中有一个属性,该属性需要引用列表中对象的属性,但遇到未知属性错误,
just to clarify: lets say my jsp property is called x my class is called a, it has a private String x and a set of getter and setters a is in ArrayList called b, and b is in the action class that jsp file is referring to (it is referring to the correct class as it can find the properties that are action's member but not the x which is in class a). 只是为了澄清一下:假设我的jsp属性称为x我的类称为a,它有一个私有String x以及一组getter和setters,它们在ArrayList中称为b,而b在jsp文件所引用的action类中到(它指的是正确的类,因为它可以找到操作成员的属性,但不能找到a类中的x)。
If I get your problem correctly (other people are right, it does read a bit like a Math problem) the problem is that Struts doesn't know to which element of the list to map the property in your JSP. 如果我正确地解决了您的问题(其他人是对的,它的确读得有点像数学问题),那么问题是Struts不知道将列表中的哪个元素映射到JSP中的属性。 Let me explain, suppose you have class A defined like this:
让我解释一下,假设您具有如下定义的A类:
public class A {
private String x;
//Getter and setter for x
}
and in your action class you have something like 在你的动作课上
public class MyAction extends ActionSupport {
private A aProperty;
//execute method and getter/setter for aProperty.
}
In this case you use aProperty.x to reference the x member of aProperty from your JSP. 在这种情况下,您可以使用aProperty.x从您的JSP引用aProperty的x成员。 However, the moment your action class changes to
但是,当您的动作类别更改为
public class MyAction extends ActionSupport {
private List<A> aList;
//Execute method and getter/setter for aList.
}
you can no longer use aList.x since you need to tell Struts which item of the list to get in order to get/set x on this item. 您不再可以使用aList.x,因为您需要告诉Struts要获取/设置x的项目要获取列表中的哪个项目。 You can specify the item of the list you want to reference like this: aList[0].x
您可以像这样指定要引用的列表项:aList [0] .x
Let me know if this is not exactly what you were trying to ask in your question. 让我知道这是否不是您要问的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.