java - Ominifaces EL 字符串传递

标签 java jsf facelets omnifaces

OminiFaces 的“o:methodParam”现在对我有用,如下所示。我怎样才能使用另一种方式?我不知道我在其中缺少什么。它可以与 <h:commandButton> 一起使用和<a4j:jsFunction>不使用Seam , 当 Seam使用它不适用于 <a4j:jsFunction>

开发环境是 RichFaces 4. Seam 2.3 OminiFaces 1.2 JBoss 7.1.1

@Name("DataTableBacking")
public class DataTableBacking {

    Department[] items = {new Department("AAA", "AAA"), new Department("BBB", "BBB"), new Department("CCC", "CCC")};

    public Department[] getItems() {
        return items;
    }

    public void action(Department action) {
        System.out.println("Action called with:" + action.getName());
    }

}

数据表.xhtml

<h:html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:richm="http://developmentTutorials.com/java">
        <h:body>
            <h:form>
            <h1>Data Table</h1>
                <rich:dataTable id="departmentTable" value="#{DataTableBacking.items}" var="dep" style="width:100%">
                    <rich:column style="width:100px;text-align:center;">
                        #{dep.name}
                        <richm:confirmLink actionBeanMethod="#{DataTableBacking.action(dep)}" render="departmentTable"/>
                    </rich:column>
                </rich:dataTable>
            </h:form>
        </h:body>
</h:html>

在标签库中,confirmation.xml

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:o="http://omnifaces.org/ui"
    xmlns:of="http://omnifaces.org/functions"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <o:methodParam name="methodParam" value="#{actionBeanMethod}" />

    <a4j:commandLink value="delete" onclick="#{rich:component('confirmation')}.show();return false" />

    <h:commandButton value="direct" action="#{methodParam}" />

    <a4j:jsFunction name="submit" action="#{methodParam}" render="#{render}" />

    <rich:popupPanel id="confirmation" width="250" height="150">
        <f:facet name="header">Confirmation</f:facet>
        <h:panelGrid>

            <h:panelGrid columns="1">
                <h:outputText value="Are you sure?" style="FONT-SIZE: large;" />
            </h:panelGrid>

            <h:panelGroup>
                <input type="button" value="OK" onclick="#{rich:component('confirmation')}.hide(); submit(); return false" />
                <input type="button" value="Cancel" onclick="#{rich:component('confirmation')}.hide(); return false" />
            </h:panelGroup>
        </h:panelGrid>
    </rich:popupPanel>

</ui:composition>

最佳答案

我不完全确定 null 值。如果回发后数据不存在(经常出现的错误),则根本不应该调用该方法。

不过,您的代码中确实有一个错误,那就是 a4j:jsFunction 将创建一个函数并将其分配给名为 submit 的 js 变量,这将每行都相同。

因此,第一行的 submit=function(){RichFaces.ajax("j_idt15:departmentTable:0:j_idt18"...submit=function(){RichFaces.ajax (“j_idt15:departmentTable:1:j_idt18”... 第二行,依此类推。

然后,您的对话框将始终调用最后一行中的对话框。那么,是否可能存在 null 作为您向表提供的列表中的最后一个值?

使用以下稍微简化的代码,我在操作方法中获取传递的参数:

@ManagedBean
public class DataTableBacking {

    String[] items = {"A", "B"};

    public String[] getItems() {
        return items;
    }

    public void action(String action) {
        System.out.println("Action called with:" + action);
    }

}

数据表.xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:richm="http://developmentTutorials.com/java"
>
    <h:head/>
    <h:body>

        <h:form>
            <rich:dataTable id="departmentTable" value="#{dataTableBacking.items}" var="dep" style="width:100%">
                <rich:column style="width:100px;text-align:center;">
                    #{dep}
                    <richm:confirmLink actionBeanMethod="#{dataTableBacking.action(dep)}" render="departmentTable"/>
                </rich:column>
            </rich:dataTable>
        </h:form>

    </h:body>
</html>

确认.xhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:o="http://omnifaces.org/ui"
    xmlns:of="http://omnifaces.org/functions"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <o:methodParam name="methodParam" value="#{actionBeanMethod}" />

    <a4j:commandLink value="delete" onclick="#{rich:component('confirmation')}.show();return false" />

    <h:commandButton value="direct" action="#{methodParam}" />

    <a4j:jsFunction name="submit" action="#{methodParam}" render="#{render}" />

    <rich:popupPanel id="confirmation" width="250" height="150">
        <f:facet name="header">Confirmation</f:facet>
        <h:panelGrid>

            <h:panelGrid columns="1">
                <h:outputText value="Are you sure?" style="FONT-SIZE: large;" />
            </h:panelGrid>

            <h:panelGroup>
                <input type="button" value="OK" onclick="#{rich:component('confirmation')}.hide(); submit(); return false" />
                <input type="button" value="Cancel" onclick="#{rich:component('confirmation')}.hide(); return false" />
            </h:panelGroup>
        </h:panelGrid>
    </rich:popupPanel>

</ui:composition>

我通过 h:commandButton 添加了直接调用,以验证表达式是否正确地连接到 Facelet 标记。在此示例中,当我单击 delete 链接并确认时,我得到了两行 action() 方法中预期的最后一个元素 (B)。

我使用了 JBoss AS 7.1.1、OmniFaces 1.2 Snapshot 和 RichFaces 4.0.0。 OmniFaces 版本应该不会太重要,因为我没有对这些版本之间的 methodParam 进行任何更改(我是该特定部分的作者)。

您使用的是哪个服务器以及哪个版本的 OmniFaces 和 RichFaces?

编辑

根据注释,将String更改为Department:

DataTableBacking.java:

@ManagedBean
public class DataTableBacking {

    Department[] items = {new Department(), new Department()};

    public Department[] getItems() {
        return items;
    }

    public void action(Department action) {
        System.out.println("Action called with:" + action);
    }

}

部门.java:

public class Department {

}

(所有其他代码与之前相同)

这应该并且(在我这边)确实没有任何区别。当你将String数组改为Department数组时,你是按照我的方式做的吗?你能展示一下你的完整支持 bean 吗?

关于java - Ominifaces EL 字符串传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12499627/

相关文章:

java - 需要简单的正则表达式

jsf - jsf中没有 session 生成

Google-app-engine 服务器 : Error 500 on working code - deployment problems. Java 代码

java - 在 JSF-2.0 中使用 JSP 技术(而不是 XHTML)有什么缺点吗?

java - 选中项目时,selectManyCheckbox 元素不会复制到数组

java - 不可见的 JMenuBar,加速器不工作

java - 二维条码检测和图像分割

java - JSF selectOneRadio 函数返回值作为 itemValue。 For 循环创建 selectItems

java - 我遇到空指针异常,但不确定它在代码中的位置

jsf - JavaBean 和 ManagedBean 有什么区别