• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 454
  • Last Modified:

struts multibox: null pointer exception

The following code generates null pointer exception. please help.

/** RegisterForm.java***/
public class RegisterForm extends ActionForm {
    protected String[] selectedItems = {};
   protected String[] item = {"UPS", "FedEX", "Airborne"};
   public String[] getSelectedItems() {
               return this.selectedItems;
   }
   public void setSelectedItems(String[] selectedItems) {
          this.selectedItems = selectedItems;
   }
}
/*** register.jsp ****/
<html:form action="/register" >
    <logic:iterate id="item" property="items" >
   <html:multibox property="selectedItems">
               <bean:write name="item"/>
         </html:multibox>
         </logic:iterate>
<html:submit value="Register"/>
</html:form>

0
jeff1919
Asked:
jeff1919
1 Solution
 
jpolin1Commented:
To start off I don't think your iterate tag is correct, you need to specify the form that you are using, in this case the RegisterForm, so it should be something like:

<logic:iterate id="item" name="registrationForm" property="items">

Could you also add the entire stack trace?
0
 
jeff1919Author Commented:
This helps. but got another error generated: no getter and setter methods for the bean
0
 
jeff1919Author Commented:
Venabili...thanks for moving my question..!
0
 
runa_paathakCommented:
That is because you don't have getters and setters for "items" property. Your property name is "selectedItems", so change it to

<logic:iterate id="item" name="registrationForm" property="selectedItems">
0
 
boonlengCommented:
If not mistaken, it should be adding the getter and setter method for 'items' in form bean, not 'selectedItems' as it does not contain value for display.
Example:
public class RegisterForm extends ActionForm {
   protected String[] selectedItems = {};
   protected String[] items = {"UPS", "FedEX", "Airborne"};
   public String[] getSelectedItems() {
             return this.selectedItems;
   }
   public void setSelectedItems(String[] selectedItems) {
         this.selectedItems = selectedItems;
   }
   public String[] getItems() {
             return this.items;
   }
   public void setItems(String[] items) {
         this.items = items;
   }

}
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now