You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jonathan Gerrish <jo...@indiekid.org> on 2007/06/18 23:43:23 UTC

Radio tag with nested elements

Hi all.

Question regarding struts 2 UI tags.

I have one action which gets a list of objects and forwards to a jsp view.
I'd like that view to display a list of those objects, with a radio button
besides each one, so the user can select a single item from this list. For
each item, I'd also like to display other properties too. When the user
submits the form to a different action, the selected item from the list is
then set as a (single) property on the new action.

Its actually a flight booking website... user searches for flights, system
presents user with available flights, user selects one of the returned
flights, system prices the selected flight and so on. So the code looks more
or less as follows, I think that the radio tag doesn't do what I want (just
allows a simple select from list), but maybe it can be bent somehow to get
the result I want.... or perhaps there is another tag, or I need to write
one myself.... if anyone has any guidance, I'd be very very grateful :-)

Thanks in advance! All the best, Jonathan.

public class FlightSearchAction implements Action {
  public String execute() {
      outboundFlights = service.doFlightSearch(....);
  }

  public List<Flight> getOutboundFlights() {
    return outboundFlights;
  }
}

<!-- Flight search results page. User must select one of the options -->
<s:iterator value="outboundFlights" status="status">
  <s:radio name="selectedOutboundFlight"
value="outboundFlights(#status.index)"/>
  <s:property value="departureCity"/>
  <s:property value="destinationCity"/>
  <s:property value="departureDate"/>
  <s:property value="flightNumber"/>
</s:iterator>

public class FlightPriceAction implements Action {
  public String execute() {
    service.priceFlight(selectedOutboundFlight);
  }

  public void setOutboundFlight(Flight flight) {
    selectedOutboundFlight = flight;
  }
}