tags:

views:

347

answers:

1

Hi,

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,

+2  A: 

It is possible,

In order to get my goal, i need to use the following

<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>
        <h:commandButton action="#{accountService.deposit(param.accountId, param.amount)}" value="Deposit amount"/>
    </div>
</h:form>
</f:view>

The param.accountId and param.amount is evaluated when the action method is invoked. Although Seam allows use built-in Event context component in EL expression as follows

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

It does not work as expected. Maybe because of it just work when using a component, not when using a request parameter. If you want to pass a request parameter, use param

regards,

Arthur Ronald F D Garcia