0

I'm using Spring 3.1.0.RELEASE with Hibernate 4.0.1.Final. I want to invoke a search method in a controller that takes as input a search bean (the Event bean below) ...

@RequestMapping(value = "/search_results.jsp")
public ModelAndView processSearch(final HttpServletRequest request, final Event searchBean, final BindingResult result) {
    ...
}

The event bean contains the following field ...

@Entity
@Table(name = "EVENTS")
public class Event implements Comparable {

    ...
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="EVENT_FEED_ID")
    private EventFeed eventFeed;
    ...
}

in which the EventFeed object contains the following fields ...

@Entity
@Table(name = "EVENT_FEEDS")
public class EventFeed {

    @Id
    @Column(name = "ID")
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Integer id;

    @NotEmpty
    @Column(name = "TITLE")
    private String title;

    ... 
}

How do I construct a URL such that the search bean's Event.getEventFeed().getId() field is populated?

I realize I could submit a GET request with a parameter like "eventFeedId=2" and populate everything manually, but since other pages are submitting requests that populate the command object, I'd like to continue to use the same logic.

Dave
  • 15,639
  • 133
  • 442
  • 830
  • "... populate everything manually, but since other pages are submitting requests that populate the command object" is your question: "how do I load that EventFeed from the database?" ? -- if you have an other question, can you please formulatethe question more precise: Because the answer to your formal question is `?event.eventFeed.id=1&event.eventFeed.title=hallo` - but I do not think that that is what you want to know. – Ralph Apr 11 '12 at 17:21
  • Yes, "?event.eventFeed.id=1&event.eventFeed.title=hallo" is what I want to know, except as I indicated below, I tried that, and the Event.getEventFeed() bean is not getting populated. – Dave Apr 12 '12 at 13:42

1 Answers1

0

It would be

/search_results.jsp?event.eventFeed.id=...&event.eventFeed.title=...

event is a default model attribute name as defined in @ModelAttribute, other binding rules are described in 5.4.1 Setting and getting basic and nested properties.

Note, however, that this approach can cause problems if you'll associate these bean with Hibernate session later. For example, if you want to attach new Event to the existing EventFeed by calling merge() it would also override the title property. Thus, in such a case it would be better to avoid overuse of data binding and pass primitives as parameters instead.

axtavt
  • 239,438
  • 41
  • 511
  • 482
  • I tried the query string you suggested but the Event bean's EventFeed field is still null. – Dave Apr 11 '12 at 22:15