0

I am trying to display value from two table Activites and Favorites using struts2 and hibernate one-to-many relationship

     //Activities
        @Entity
        @Table(name="ACTIVITIES")
        @OneToMany(fetch = FetchType.EAGER, mappedBy = "activities" , targetEntity=Favorites.class, cascade=CascadeType.ALL )
            public Set<Favorites> getFavorites() {
                return favorites;
            }
            public void setFavorites(Set<Favorites> favorites) {
                this.favorites = favorites;
            }

        @Id
            @GeneratedValue
            @Column(name="ACTIVITYID")
            public Long getId() {
                return id;
            }
            public void setId(Long id) {
                this.id = id;
            }


        //Favorites
        @Entity
        @Table(name="Favorites")
        @ManyToOne(optional=false)
            public Activities getActivities() {
                return this.activities;
    }

and other fields

In jsp:

<s:iterator value="activityList" id="activityList" status="activityStatus" <s:hidden id="activityList" name="activityList[%{#activityStatus.index}].id" />                          
<s:iterator value="favorites" var="fav" status="myStat">                                                          
<s:checkbox id="accFavorities"  name="accFavorities"/></td>     
<s:iterator>

but when submit i am getting id from activity table but not values favorites table which is the checkbox.

In my action class

for (Activities al : activityList) {
    for (Favorites ss : al.getFavorites()) {
         System.out.println(ss.getCompany());
         System.out.println(ss.getAccFavorities());
          }
   }

In jsp I tried something like this below in that case the value from database itself is not comming

<s:iterator value="%{favorites}" id="fav" status="myStat"> 
<s:checkbox id="accFavorities" value="activityList[%{#activityStatus.index}].fav[%{#myStat.index}].accFavorities"/></td>

Any help is really appreciated.

thanks

Vallaru
  • 3
  • 2
  • 8

1 Answers1

0

You have to define your checkbox so that when browser submits the form, the parameter names match the expected bean structure.

Maybe you could try the "key" attribute of as shown in http://struts.apache.org/2.2.1/docs/struts-2-form-tags.html#Struts2FormTags-Struts2CheckboxTag

Michael Zilbermann
  • 1,398
  • 9
  • 19
  • Thanks but i am kind of having a problem with onetomany( nested iterators) and i have referred the example from http://stackoverflow.com/questions/2327466/struts-2-nesting-iterators – Vallaru Mar 21 '11 at 23:36