是否可以在不使用托管属性的情况下将输入值作为操作的参数传递?
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?
更多推荐
直接传递输入值作为操作方法参数
发布评论