【问题标题】:How can i pass a form field as a action parameter by using Seam framework?如何使用 Seam 框架将表单字段作为操作参数传递?
【发布时间】:2009-11-10 03:01:52
【问题描述】:

我不知道这是否可能,但我想要类似的东西

<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>

还有我的服务

@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);
    }

}

碰巧我想用这个而不是上面显示的

@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);
    }

}

有可能吗?如果是这样,我应该使用什么 - 事件或其他东西 - 来实现我的目标?

问候,

【问题讨论】:

  • 嘿亚瑟,你为什么不把其他论坛的答案作为你自己问题的答案。

标签: java binding seam


【解决方案1】:

有可能,

为了实现我的目标,我需要使用以下内容

<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>

param.accountId 和 param.amount 在调用操作方法时进行评估。虽然 Seam 允许在 EL 表达式中使用内置的 Event 上下文组件,如下所示

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

它没有按预期工作。也许是因为它只在使用组件时起作用,而不是在使用请求参数时。如果要传递请求参数,请使用 param

问候,

【讨论】:

    猜你喜欢
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 2014-04-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多