English 中文(简体)
How can i pass a form field as a action parameter by using Seam framework?
原标题:

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,

最佳回答

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,

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签