1 Reply Latest reply on Aug 23, 2012 7:03 AM by i92jurir

    problem selecting row with f:param

    i92jurir

      Hi,

       

      I´m having a problem selecting a row from a datatable. I know it´s a very common task in web applications but I have tried a lot of ways and I can´t make it work anyway.

      The page with the datatable is:

       

      <rich:dataTable value="#{hoteles}" var="hot">
      
        <h:column id="column1">
               <f:facet id="NameFacet" name="header">Nombre</f:facet>
                  #{hot.nombre}
            </h:column>
      
        <h:column id="column2">     
               <f:facet id="NameFacet" name="header">Seleccionar</f:facet>
                  <s:link value="Reservar" view="/reservarPaso1.xhtml" propagation="begin">       <!-- Link to booking page. We start a LRC -->
                      <f:param name="hotelSeleccionado" value="#{hot}"/>                                   <!-- We pass the selected row -->
                  </s:link>            
        </h:column>
      
      </rich:dataTable>
      

       

      My idea is pass the selected row (the hotel) with a page paramameter to a booking page.    #{hoteles} is populated with this method triggered with a page action:

       

      public void buscarHoteles() {
             
            // Hacemos la busqueda
            hoteles = entityManager.createQuery("select h from Hotel h").getResultList();
              
      }
      

       

      The target page (booking page) is:

       

      ... 
      <h:form id="reservarPaso1Form">   
      
              <rich:panel>
                  <f:facet name="header">Paso 1</f:facet>
      
                  <s:decorate id="fechaEntradaField" template="layout/edit.xhtml">
                      <ui:define name="label">Fecha entrada</ui:define>
                      <rich:calendar id="fechaEntrada"
                             required="true"
                                value="#{nuevaReserva.fechaEntrada}" datePattern="MM/dd/yyyy" />     <!-- nuevaReserva is created and stored in Conversation Context when page is show -->
                  </s:decorate>
      
      
                  <s:decorate id="fechaSalidaField" template="layout/edit.xhtml">
                      <ui:define name="label">Fecha salida</ui:define>
                      <rich:calendar id="fechaSalida"
                                value="#{nuevaReserva.fechaSalida}" datePattern="MM/dd/yyyy" />
                  </s:decorate>
      
               </rich:panel>
      
      </h:form>
      ...
      

       

      Booking.page.xml is:

       

      <page view-id="/reservarPaso1.xhtml">
           <param name="hotelSeleccionado" value="#{nuevaReserva.hotel}"/>         <!-- Parameter goes to hotel attribute inside nuevaReserva instance -->
      </page>
      

       

      When I run the application this exception is thrown.

       

      WARN  [SeamPhaseListener] uncaught exception, passing to exception handler

      javax.el.ELException: java.lang.IllegalArgumentException: argument type mismatch

       

      I have tried using DataModel and DataModelSelection but hotelSeleccionado is not storing in conversation context when booking page is shown. I have tried too Contexts.getConversationContext.set("hotelSeleccionado",hotel) in an action method to store the object in context but the object doesn´t appear in seam debug page. Anybody can give me some help?

       

      Sorry for long post. Thanks in advance.

        • 1. Re: problem selecting row with f:param
          i92jurir

          It´s solved.

           

          Link in the page to select the row.

           

          <h:column id="column5">
                   <f:facet id="NameFacet" name="header">Seleccionar</f:facet>            
                   <s:link value="Reservar" action="#{findHotels.startBooking}" propagation="begin"/>  
          </h:column>
          

           

          In findHotels bean:

          @DataModel
          private List<Hotel> hoteles;             //hotels list
              
          @DataModelSelection @Out(required=false, scope=ScopeType.CONVERSATION)  // selected hotel
          private Hotel hotelSeleccionado;       
          
          public String startBooking() {
               return "/reservarPaso1.xhtml";
          }
          

           

          The trick was put @Out(required=false, scope=ScopeType.CONVERSATION) in the selected hotel.

          When startBooking is called hotelSeleccionado is inyected with @DataModelSelection. When the method ends hotelSeleccionado is outyected to conversation context.