5 Replies Latest reply on Oct 26, 2005 11:19 AM by Gavin King

    Injecting <f:param> howto ?

    Louis Coetzee Apprentice

      Hi all,

      I am trying to inject the value of a <f:param> into my Stateless Seam action handler. Unfortunately the value remains null. I am using the cvs build of Seam.

      I am trying to build up a list of links with url parameters so that I can see which link was selected (I know I can do something similar with a Stateful bean in combination with a @DataModel annotation, but I would like to make use of a Stateless bean).

      Below is the relevant snippets of code:

      My stateless bean

      public class ServiceViewerAction implements Serializable, ServiceViewer {
       private List<Service> allServices;
       private Service currentService;
       // How to get this to work ?
       @In(required=false, value="#{selectedServiceId}")
       private Long selectedServiceId;
      public String viewSelected() {
      logger.info("we have entered down the selection road");
      //selectedServiceId remains null
      logger.info("View selected server with id: " + selectedServiceId);
      return "success";

      and my xhtml:
      <t:dataList value="#{allServices}" var="currService" layout="simple"
       rowCountVar="rowCount" rowIndexVar="rowIndex">
       <h:commandLink action="#{serviceViewerAction.viewSelected}"
       <h:outputText value="#{currService.name}" />
       < f:param id="selectedServiceId" name="selectedServiceId"
       value="#{currService.id}" />

      Any suggestions ?



        • 1. Re: Injecting <f:param> howto ?
          drapierwimATgmailDOTcom Newbie


          @In(required=false, value="#{selectedServiceId}")
           private Long selectedServiceId;

          Non primitieve datatypes won't work here simple because there is no instance created, when you change it to long you will see that an injection is done when the seam component is created, resulting in another error because seam doesn't know the selected value.

          please correct me if I'm wrong.

          • 2. Re: Injecting <f:param> howto ?
            Louis Coetzee Apprentice

            I have made some progress with regard to using non-primitives. Using an int brings Seam to attempt to inject a value, but throws an exception (as suggested by the previous poster).

            The exception:

            Caused by: javax.ejb.EJBTransactionRolledbackException: null; CausedByException is:
             could not inject: #{selectedServiceId} to: serviceViewerAction

            I have changed (simplified) my code as follows (to get the above exception):
            @In(value="#{selectedServiceId}", required=false)
             @Out (required=false)
             private int selectedServiceId;

            with xhtml
            <h:commandLink action="#{serviceViewerAction.viewSelected}"
             <h:outputText value="test" />
             <f:param id="selectedServiceId" name="selectedServiceId" value="171" />

            Still learning (slowly unfortunately ;-).


            • 3. Re: Injecting <f:param> howto ?
              Gavin King Master

              The CVS build of Seam supports use of JSF expressions in @In. However, the only way to get the value of an <f:param> is to go direct to the FacesContext.

              • 4. Re: Injecting <f:param> howto ?
                Louis Coetzee Apprentice

                Thanks for the confirmation.

                In the end I did the following:

                FacesContext context = FacesContext.getCurrentInstance();
                Map map = context.getExternalContext().getRequestParameterMap();
                String serviceNr = (String) map.get("selectedServiceId");
                if (serviceNr.length() > 0) {
                 logger.info("Retrieved: " + serviceNr + "from <f:param ... ");
                 selectedServiceNr = new Integer(serviceNr);



                • 5. Re: Injecting <f:param> howto ?
                  Gavin King Master

                  Right, this is one way.

                  You can even inject the FacesContext, if you like.