dcsimg
Map of ImageButtonBeans?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   jason_burrows
Posted On:   Friday, April 22, 2005 07:58 PM

Hi - I'm trying to create a form with an arbitrary number of image buttons. To do this I am using a map backed action form composed of ImageButtonBeans. Unfortunately I get "java.lang.IllegalArgumentException: No bean specified" when I click on one of the buttons. The page loads fine though. For the property attribute I am doing this (just a test): property="delete(one)" If I don't use a map, it works fine, and if I use a map but dont use images, it works fine. I am instantiating my map like this: private final Map deletes = new HashMap (); and I have these for accesors: public void setDelete(String key, ImageButtonBea   More>>

Hi -

I'm trying to create a form with an arbitrary number of image buttons. To do this I am using a map backed action form composed of ImageButtonBeans. Unfortunately I get "java.lang.IllegalArgumentException: No bean specified" when I click on one of the buttons. The page loads fine though. For the property attribute I am doing this (just a test):


property="delete(one)"


If I don't use a map, it works fine, and if I use a map but dont use images, it works fine. I am instantiating my map like this:


private final Map deletes = new HashMap ();


and I have these for accesors:


public void setDelete(String key, ImageButtonBean delete) {
deletes.put(key, delete);
}


public ImageButtonBean getDelete(String key) {
return deletes.get(key);
}


Is it even possible to create an ActionForm with a map of ImageButtonBeans? If not, how would you suggest creating a list of arbitrary length of items that can be deleted by clicking on an image (I would really prefer to not use links if that is possible)?


Thanks

Jason

   <<Less

Re: Map of ImageButtonBeans?

Posted By:   jason_burrows  
Posted On:   Friday, April 22, 2005 09:20 PM

OK, I figured it out!


If I change my getter so that it will definitely return a valid object, all is well. This makes sense now that I see what is going on. So my getter is now:


public ImageButtonBean getDelete(String key) {

if (deletes.get(key) == null){

deletes.put(key, new ImageButtonBean());

}

return deletes.get(key);

}


I didn't understand that when you are using nested properties Struts (apparently) will not attempt to create an instance of an object if it is null in order to set the nested property.


Now I'm happily clicking on my red "X"s and deleting database rows from various tables! =-)

About | Sitemap | Contact