【问题标题】:how to call jsf managed bean inside jquery file如何在jquery文件中调用jsf托管bean
【发布时间】:2013-05-23 05:37:21
【问题描述】:

如果用户选择是,我有一个带有确认对话框的 jquery 文件,我需要从 jsf 调用方法

这就是我需要在 jquery 中调用 jsf 托管 bean 的地方:

 jConfirm('item '+ui.item.context.id+'you want continu ?', 'alerte', function(r) {     
                  if(r)          
                  {
              // i want to call the addmember methode here
             addmember(ui.sender.attr('id'));// i need the right way to call it this is wrong way
                   }
                    else
                    {
                    $(ui.sender).sortable('cancel'); // refuse element to be dropped
                    }

在 jsf 托管 bean“Managedbeanmembers”中我有:

void addmember(String name)
{
  listmembers.add(name);
}

编辑 1:

这次我会尝试更清楚地向您解释我需要什么:

我在 jsf 托管 bean 中有一个获取值并插入数据库的方法:

    public void exec() {
    FacesContext context = FacesContext.getCurrentInstance();
    Map map = context.getExternalContext().getRequestParameterMap();
    String name1 = (String) map.get("name1");
    String name2 = (String) map.get("name2");

    manageTesttable.persist(name1);   
}

在 Jsf 中,我将其包含在 :

 <p:remoteCommand name="remoteCommandFunctionName"   
                  actionListener="#{gestionduplanning.exec()}"/>

在我的 Javascript 文件中:

jConfirm('item '+ui.item.context.id+' capacite Cuisson epuise vous voulez continue comme meme ?', 'alerte', function(r) {     
                  if(r)          
                  { 

                  remoteCommandFunctionName({name1:'value1', name2:'value2'});

                   }
                    else
                    {
                    $(ui.sender).sortable('cancel'); // refuse element to be dropped
                    }

但是当我插入时我有空值,为什么 name1 和 name2 是空的??

【问题讨论】:

  • 创建一个 commandButton 并使用 CSS 使其不可见(我认为它是 visibility:none 并只需“单击”它。
  • 你能举个例子吗?
  • @BalusC 我编辑了我的帖子以解释更多
  • 我也尝试了 var input = document.getElementById('formid:inputid'); 的解决方案input.value = '新值';并且在 jsf 文件中 但不工作我有这个方法的空值

标签: jquery jsf


【解决方案1】:

一种可能性 - 创建一个隐藏按钮并像 @SJuan76 建议的那样单击它 - here's 示例。

另一种可能性 - 如果您使用的是 Richfaces,请尝试 jsFunction - 请参阅 here

编辑:在 Primefaces 的情况下,p:remoteCommand 提供了类似的功能。

【讨论】:

  • 我需要在 jquery 中的函数中添加参数,然后再将其发送到服务器我该怎么做??
  • 你有没有使用richfaces?
  • 在这种情况下,您可以使用p:remoteCommand 来简化操作。类似的question 展示了如何传递参数。
  • 我按照示例进行操作,我可以在托管 bean 中调用该函数,但问题是我可以获取传递的参数值:remoteCommandFunctionName({name1:'value1', name2:'value2'}) ;当我尝试使用 FacesContext context = FacesContext.getCurrentInstance(); 获取它们时Map map = context.getExternalContext().getRequestParameterMap(); String name1 = (String) map.get("name1"); String name2 = (String) map.get("name2");我什么都没有
  • 试试remoteCommandFunctionName([{name1:'value1', name2:'value2'}]);
猜你喜欢
  • 2013-03-18
  • 2012-11-09
  • 1970-01-01
  • 2014-01-27
  • 2011-12-01
  • 2013-01-24
  • 2023-03-05
  • 2013-07-26
  • 2016-07-09
相关资源
最近更新 更多