直接传递输入值作为操作方法参数 [英] Pass an input value directly as action method argument

查看:123
本文介绍了直接传递输入值作为操作方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在不使用托管属性的情况下将输入值作为操作的参数传递?

Is there a way to do pass an input value as a action's parameter without using managed properties?

<h:form>        
    <h:inputText id="input" />  
    <h:commandButton action="#{someBean.doSome(input)}" />  
</h:form> 

推荐答案

是的,它是在表单提交期间处于JSF组件状态.只需通过binding属性将输入组件绑定到视图,该属性将引用 UIInput 实例,该实例又具有getValue()方法,用于检索输入值(以便您可以将其作为操作方法参数传递):

Yes, it's during the form submit already there in the JSF component state. Just bind the input component to the view by binding attribute, which will reference an UIInput instance, which in turn has a getValue() method for the very purpose of retrieving the input value (so that you can pass it as action method argument):

<h:form>        
    <h:inputText ... binding="#{input}" />  
    <h:commandButton ... action="#{someBean.doSome(input.value)}" />  
</h:form> 

然而,这种方法的正确性值得高度质疑,并取决于具体的功能要求.这种方法基本上就是将视图与模型紧密耦合,因此被认为是一种不好的做法.

The properness of this approach is however highly questionable and depends on concrete functional requirements. This approach is namely basically tight-coupling the view with the model and therefore considered a bad practice.

  • How to send form input values and invoke a method in JSF bean
  • How does the 'binding' attribute work in JSF? When and how should it be used?

这篇关于直接传递输入值作为操作方法参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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