【问题标题】:How can I pass value from jQuery to jsf h:inputText and Backing Bean如何将值从 jQuery 传递到 jsf h:inputText 和 Backing Bean
【发布时间】:2013-04-03 09:46:16
【问题描述】:

我尝试将值从 jquery 传递给 jsf 和 Backing Bean。在此过程中,我不想使用来自 jsf-Tag 的 f:ajax。

javaScript 或 jQuery

<script>
   var myvalue = null;
   $('.classname').live('click',function(){
      myvalue = "thisvalue"+xyz;  
      // update myvalue in jsf inputtext and in bean
   });
</script>

JSF - 内容

<h:form id="myid" prependId="false">

  <h:inputText id="fragment" value="#{myBean.changevalue}">
  <!-- please do not use here f:ajax or p:ajax so on. -->

</h:form>

豆内容

private String changevalue;

public String getChangevalue() {
  return changevalue;
}

public void setChangevalue(String changevalue) {
  this.changevalue = changevalue;
}

【问题讨论】:

  • 您要更新 值还是添加新参数并发送到您的 bean

标签: javascript jsf jquery


【解决方案1】:

只需在 jquery 中将 val 设置为浏览器文本框 id

例如

 <script>
   var myvalue = null;
   $('.classname').live('click',function(){
      myvalue = "thisvalue"+xyz;  

     $("#myid\\:fragment").val(myvalue);

   });
</script>

它会自动将值绑定到你的 bean

希望对你有帮助。

【讨论】:

  • @murat :是的,Ravi 是对的,请试试这个代码。它可能会帮助你。
猜你喜欢
  • 2011-02-02
  • 1970-01-01
  • 1970-01-01
  • 2014-08-11
  • 1970-01-01
  • 1970-01-01
  • 2011-10-13
  • 2011-06-09
  • 1970-01-01
相关资源
最近更新 更多