4 Replies Latest reply on Nov 12, 2009 12:47 AM by alpha88

    request parameter and method binding

    alpha88

      I do not know whether it is possible but i want something like




      <f:view>
      <h:form>      
          <div>
              <label for="accountId">Type your account id</label>
              <input type="text" name="accountId"/>
          </div>
          <div>
              <label for="amount">Type amount</label>
              <input type="text" name="amount"/>
          </div>
          <div>
              <!--NOTICE IT IS #{accountService.deposit} -->
              <!--BUT I WANT TO USE #{accountService.deposit(accountId, amount)} -->
              <h:commandButton action="#{accountService.deposit}" value="Deposit amount"/>
          </div>
      </h:form>
      </f:view>
      



      And my service


      @Stateless
      @Name("accountService")
      public class AccountServiceImpl implements AccountService {
      
          @RequestParemeter
          protected Integer accountId;
      
          @RequestParemeter
          protected double amount;
      
          @PersistenceContext
          private EntityManager manager;
      
          public void deposit() {
              Account account = manager.find(Account.class, accountId);
      
              account.deposit(amount);
          }
      
      }
      



      It happens i want to use this one instead of shown above


      @Stateless
      @Name("accountService")
      public class AccountServiceImpl implements AccountService {
      
          @PersistenceContext
          private EntityManager manager;
      
          public void deposit(Integer accountId, double amount) {
              Account account = manager.find(Account.class, accountId);
      
              account.deposit(amount);
          }
      
      }
      



      Is it possible ? If so, what should i use - event or something else - to get my goal ?


      regards,




        • 1. Re: request parameter and method binding
          kragoth

          I'm not quite sure why you are having a hard time doing what you want to do.


          This is what you have at the moment


          <h:commandButton action="#{accountService.deposit}" value="Deposit amount"/>
          



          And all you want to do is pass the request params in so you can do something like this (I havn't tested this, I have just done some googling so it is probably not 100% correct but if you do a bit of reading about requestParameters in EL expressions I'm sure you'll be able to get it to work.)


          So.... maybe something like...


          <h:commandButton action="#{accountService.deposit(param.accountId, param.amount)}" value="Deposit amount"/>
          



          Here I am accessing the request params by using the expression param.paramId


          I found this info HERE


          If that way doesn't work then maybe accessing the param like this might.


          #{param['accountId']}
          



          This idea is from HERE


          I hope this helps.

          • 2. Re: request parameter and method binding
            asookazian

            30.1. Parameterized Method Bindings


            Standard EL assumes that any parameters to a method expression will be provided by Java code. This means that a method with parameters cannot be used as a JSF method binding. Seam provides an enhancement to the EL that allows parameters to be included in a method expression itself. This applies to any Seam method expression, including any JSF method binding, for example:


            <h:commandButton action="#{hotelBooking.bookHotel(hotel)}" value="Book Hotel"/>



            30.1.1. Usage


            Parameters are surrounded by parentheses, and separated by commas:


            <h:commandButton action="#{hotelBooking.bookHotel(hotel, user)}" value="Book Hotel"/>



            http://docs.jboss.org/seam/2.0.0.GA/reference/en/html/elenhancements.html

            • 3. Re: request parameter and method binding
              alpha88

              You are right,


              When i use param as follows


              <h:commandButton action="#{accountService.deposit(param.accountId, param.amount)}" value="Deposit amount"/>
              



              It works fine.


              You save me a lot of time.


              Congratulations!


              • 4. Re: request parameter and method binding
                alpha88

                You are right,


                When i use param, i can pass request parameter. It works fine!


                Congratulations!