直接传递输入值作为操作方法参数

编程入门 行业动态 更新时间:2024-10-15 20:18:31
本文介绍了直接传递输入值作为操作方法参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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.

  • 如何发送形成输入值并在JSF bean中调用方法
  • 绑定"属性在JSF中如何工作?何时以及如何使用?
  • 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?

更多推荐

直接传递输入值作为操作方法参数

本文发布于:2023-10-27 10:26:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1533096.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:操作方法   参数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!