0

I have my action, which has a variable HashMap<String, MyObject>

My Object:

 public class MyObject {

    private Boolean confermata;

    private String idObj;

    private String versione;

    /* (getters and setters) */

 }

When JSP snippet:

<s:hidden name="form.datiVersioneQuoteAssegnazione['%{#tmpIdObj}'].confermata"/>
<s:hidden name="form.datiVersioneQuoteAssegnazione['%{#tmpIdObj}'].idObj"/>
<s:hidden name="form.datiVersioneQuoteAssegnazione['%{#tmpIdObj}'].versione"/>

tmpIdObj is another variable...it's fine.

Problem: When I populate MyObject from the DB and I load the JSP the output is correct, but when I send the data to the server (clicking on a button in my <s:form>) the hashmap is built correctly. By debugging it, it is a <String,MyObject> but the values from the form are not taken, so the MyObjects objects are all empty... Furhtermore, I've seen that the setters of MyObjects are not called. Could somebody tell me why?

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
Emaborsa
  • 2,360
  • 4
  • 28
  • 50
  • Do you have setters/getters for your map in action? – Aleksandr M May 02 '13 at 08:06
  • Are you using the Default Interceptor Stack ? Do you have a no-args Constructor in myObject (implicit or explicit) ? – Andrea Ligios May 02 '13 at 08:20
  • check if MyObject is serializable – Code2Interface May 02 '13 at 10:36
  • Yes i have the getters and setters of my Map, and they get called. I have my own Stack, which works perfectly in the entire project (lots of Actions). Form is the bean which is used to fill the html form. MyObject implements Serializable. – Emaborsa May 02 '13 at 12:17
  • 3
    @panky1986 It doesn't matter if it's serializable or not. – Dave Newton May 02 '13 at 12:34
  • ...how are you setting the value to a hidden field..using a javascript???? – Code2Interface May 02 '13 at 12:42
  • If your `myObjects` are empty how did you display it in the JSP? – Roman C May 02 '13 at 14:37
  • Are you using default intercetor stack? – Aleksandr M May 02 '13 at 18:35
  • If you posted the action class AND configuration (if xml) then we would have what we need to solve the problem instead of guessing. – Quaternion May 02 '13 at 20:42
  • tag of struts takes the value and create name and id automatically. Javascript is not needed here. myObjects is empty when i try to save the data OF the page passing them to the framework; when i create the page (JSP) the beans are filled with data from the database. Give me some time and i'll post some code. – Emaborsa May 03 '13 at 08:07
  • I can't post it, except you really want that i post 1500lines of code. I know that the configuration is OK, since all the other stuff works... I only have problem with this HashMap and MyObject. Other mapped custom classes work fine. – Emaborsa May 03 '13 at 12:28
  • By debugging it deep, i see struts throws a NoSuchPropertyException on `java.lang.String.confermata` ... – Emaborsa May 03 '13 at 13:59

1 Answers1

0

I solved it. The problem was that i defined a Hashmap:

private HashMap<String, MyObject> datiVersioneQuoteAssegnazione;

When i define it as a Map as following, it works:

private Map<String, MyObject> datiVersioneQuoteAssegnazione;

It seems that Struts doesn't recognize HashMaps...strange.

Emaborsa
  • 2,360
  • 4
  • 28
  • 50
  • 1
    It cannot determine type of element inside map if you are using implementation (e.g. `HashMap`) not interface `Map`. If you need to use `HashMap` then you can use `@Element` annotation. See my answer to this question: http://stackoverflow.com/q/15006868/1700321. – Aleksandr M May 04 '13 at 10:24