my dog learned polymorphism*
The moose likes Struts and the fly likes struts 1.2.7: html:multibox and no checked checkboxes - how does Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 1.2.7: html:multibox and no checked checkboxes - how does "matches" work?" Watch "struts 1.2.7: html:multibox and no checked checkboxes - how does "matches" work?" New topic
Author

struts 1.2.7: html:multibox and no checked checkboxes - how does "matches" work?

Tobias Prinz
Greenhorn

Joined: Dec 18, 2008
Posts: 2
There I am, trying to update a legacy project using Tomcat, Castor and Struts. Now the struts part is giving me headaches.

What I am trying to do is giving a "contact" the ability do subscribe and unsubscribe newsletters.

So I have got two arrays, one containing all newsletters, one those already subscribed by the contact. I already managed to list all newsletters, works fine, shows their description and also assigns their id as value to the checkbox.
But I cannot get the checkbox to be "checked" if one of the newsletters has already been selected.

Now, this is the important part of the form used for the action:


This is me adding the data to the DynaActionForm by transforming my Collection to an array (reason: Castor JDO loves Collections, but since the forms for struts are already written in xml and I only knew how to model arrays there, I convert them):


And this is me extending the .jsp to display a list of newsletters


Now I cannot get my Eclipse to debug on the Tomcat (dunno, don' care, works with the same setup for the guy next to me...), so I stick to system.out.println()-debugging. From that I know:
  • Two newsletters are equal if their id, description and e-mail match (I implemented that myself because I thought matching did not work - and I remembered to implement the hashcode, too, don't worry)
  • If I simply iterate over the list in java and match using "equals", I find one match (for my example case)
  • If I iterate over the list of all newsletters in .jsp using logic:iterate, all are shown correctly
  • If I iterate over the list of subscribed newsletters in .jsp using logic:iterate, the one subscribed newsletter is shown correctly

  • So I figure it has to be either the "matching" done by Struts or me misreading the 10 top examples google gave me (which use arrays of String, so it has to be the equals() method, not a simple == comparison).
    Note that I do not insist on using multibox (so I would use checkbox, but I haven't found out how to get something checked there, either) and the solution does not have to be pretty. I already implemented a diff/delta for two arrays, so I do not insist on the ability to find out which box was unselected.

    So, anyone got an idea?

    --Tierlieb

    Edit: Added version to title

    Edit2: WTF? I just replaced my lovingly-crafted, beautiful Newsletter class with a String. And it worked! Why? Both are Objects, yet String is Comparable... hurrm?
    [ December 18, 2008: Message edited by: Tobias Prinz ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: struts 1.2.7: html:multibox and no checked checkboxes - how does "matches" work?