Pass an input value directly as action method argument

﹥>﹥吖頭↗ 提交于 2019-12-18 09:09:17

问题


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

i.e.

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

回答1:


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.

See also:

  • 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?



回答2:


This is what worked for me: In Java: String dna=this.dna;



来源:https://stackoverflow.com/questions/18340851/pass-an-input-value-directly-as-action-method-argument

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!