将输入文本值传递给bean方法,而无需将输入值绑定到bean属性 [英] Pass input text value to bean method without binding input value to bean property

查看:116
本文介绍了将输入文本值传递给bean方法,而无需将输入值绑定到bean属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将输入文本字段值传递给bean方法,而无需将该值绑定到bean属性?

Can I pass a input text field value to a bean method without binding the value to a bean property?

<h:inputText value="#{myBean.myProperty}" />
<h:commandButton value="Test" action="#{myBean.execute()} />

是否可以在不做#{myBean.myProperty}临时保存的情况下执行此操作?

Can I do this without doing temporary save in #{myBean.myProperty}?

推荐答案

将该组件绑定为

Bind the component as UIInput to the view and use UIInput#getValue() to pass its value as method argument.

<h:inputText binding="#{input1}" />
<h:commandButton value="Test" action="#{myBean.execute(input1.value)}" />

使用

public void execute(String value) {
    // ...
}

请注意,该值已经通过这种方式转换并验证了通常的JSF方式.

Note that the value is this way already converted and validated the usual JSF way.

  • How does the 'binding' attribute work in JSF? When and how should it be used?
  • JSF component binding without bean property

这篇关于将输入文本值传递给bean方法,而无需将输入值绑定到bean属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆