Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JSF datatable和Bootsfaces模式窗口的问题_Jsf_Jsf 2_Twitter Bootstrap 3_Bootsfaces - Fatal编程技术网

JSF datatable和Bootsfaces模式窗口的问题

JSF datatable和Bootsfaces模式窗口的问题,jsf,jsf-2,twitter-bootstrap-3,bootsfaces,Jsf,Jsf 2,Twitter Bootstrap 3,Bootsfaces,我将JSF用于我的webapp(与EJB结合使用)和Bootsfaces作为JavaScript添加来显示模式窗口。我有一个通过数据表显示的项目列表。通过点击列表中的一个命令按钮,我打开了一个模式窗口,询问用户“他是否确定要删除”。模式确认对话框有是和否。我可以在模式窗口内执行是执行按钮。但是我不能执行#{controller.delete(item)},因为在构建列表表时,该项仅在服务器端可用。不知何故,我必须将实际选择的项目发送到模式窗口,以便在控制器调用中以某种方式进行设置 有人有主意吗

我将JSF用于我的webapp(与EJB结合使用)和Bootsfaces作为JavaScript添加来显示模式窗口。我有一个通过数据表显示的项目列表。通过点击列表中的一个命令按钮,我打开了一个模式窗口,询问用户“他是否确定要删除”。模式确认对话框有是和否。我可以在模式窗口内执行是执行按钮。但是我不能执行#{controller.delete(item)},因为在构建列表表时,该项仅在服务器端可用。不知何故,我必须将实际选择的项目发送到模式窗口,以便在控制器调用中以某种方式进行设置

有人有主意吗

<!-- looping the jsf list //-->
<h:dataTable value="#{controller.itemlist}" var="item"...
...
<!-- showing modal window //-->
<h:commandButton value="delete" action="" onClick="return false;" p:toggle-data.... />
</h:dataTable>
</h:form>
...
<!-- modal window in panel, with item not set //-->
...
<h:commandButton action="#{controller.delete(item)}" />
</h:form>
</b:panel>
...

...
...

您可以使用ajax填充modal的内容:

$.ajax({
    url : "yourPage.jsf",
    type : "POST",
    data : {
        id: "your object's id"
    },
    dataType : "html"
}).done(function(html) {
    $("#yourModal").html(html);
});

当然,您需要为模式内容创建一个JSF视图。此视图将包含文本和两个按钮“是”和“否”。“否”应该忽略模态,而“是”应该调用bean操作:

不要忘记用
id
参数填充控制器
,以将数据绑定到视图

编辑:

我会给你举个例子

主视图(View.xhtml):


不幸的是,我只知道JSF和使用引导格式化我的xhtml页面。但到目前为止,我还不是JQuery方面的专家。我可以试一试,到处玩玩。但我对.done(函数…或$.ajax等@Arquillian$.ajax()和.done()一无所知:。这非常简单,您对第二个视图进行ajax调用以生成模态的html,并传递当前项id。然后从该视图创建一个按钮来关闭模态,另一个按钮用于提交一个调用bean操作的表单。我已经试了整整一周了,我从来没有在一个问题上花费过这么多时间而没有找到correct解决方案在我的一生中……我一直在使用自己编写的javascript、jsf actionlisteners、bootsfaces功能……我正在放弃它。我认为jsf和bootsfaces不能做到这一点:问题是你不能将foreach项从datatable传输到支持bean,以便以后在bootsfaces模式中再次使用。@Arquillian查看更新的答案。您还可以搜索
以获得更简单的版本。
<h:form>
  <h:dataTable value="#{controller.itemlist}" var="item">

    <h:column>
     ...
    </h:column>

    <h:column>
      <h:commandButton value="delete" onclick="return populateModal(#{item.id}); " />
    </h:column>

  </h:dataTable>

</h:form>
<script type="text/javascript">
  function populateModal(id) {
    $.ajax({
      url: "view2.jsf",
      type: "POST",
      data: { id: id },
      dataType: "html"
    }).done(function(html) {
      $("#modal").html(html);
      $("#modal").show();
    });

    return false;
  }
</script>
<h:form>

  Delete #{testBean2.item.name} ?
  <h:commandButton value="YES" action="#{testBean2.delete(testBean2.item)}" />
  <h:commandButton value="NO" onclick="return closeModal();" />

</h:form>
private Item item;

@PostConstruct
public void init() {
    // GET id parameter from HTTPRequest
    // Populate Local Item
}

public void delete(Item item) {
    // Delete your item
}