动作表单中变量的默认初始化
我做了一个类似的:
MyForm extend ActionForm{
list<Menu> MenuList=null;
MyForm(){
super();
setMenuList(); //initialize menu list
}
}
菜单对象有字符串描述和布尔变量用于选择或不选择。
在网页中,我正在迭代列表以显示这些布尔变量上的所有菜单和复选框。但每次我想访问所选项目时,列表都会设置为默认值。是因为构造函数,我已经定义了吗??? 请帮助我伙计们?
有没有其他方法来初始化变量,我也尝试过在其 getter 函数上初始化列表,但它给了我一个空指针异常。我什至无法理解为什么会这样。
i have made a from like :
MyForm extend ActionForm{
list<Menu> MenuList=null;
MyForm(){
super();
setMenuList(); //initialize menu list
}
}
Menu object has string desciption and boolean variable for selected or not.
In web page, i am iterating the list to display all the menus and checkbox over those boolean variables. But the list is set to default every time i want to access the selected items. Is that because of constructor, i have defined ?????
Please help me Guys??
Is there any other way to initialize the variables, i had also tried to initialize the list on its getter function, but its giving me a null pointer exception. I was not even able to understand why is this so.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看准备拦截器。它允许您在调用操作时在任何其他操作逻辑发生之前自动调用
prepare
方法:在上面的示例中,当您调用 MyForm 的 view() 方法时,将首先调用prepareView() ,设置菜单并准备好在输入上使用。
您可能还需要考虑在操作期间将
yourMenu
添加到会话中,以便在遇到验证错误时仍然可以使用它。Check out the Prepare interceptor. It allows you to automatically invoke a
prepare
method when you call an action, before any other Action logic occurs:In the above example, when you call MyForm's view() method, prepareView() will be invoked first, setting up your menu and ready for you to use on your INPUT.
You might also want to consider adding
yourMenu
to the session for the duration of your Action so that it's still available to you if you encounter validation errors.