2

OminiFaces の 'o:methodParam' は、以下のように機能するようになりました。どうすれば他の方法を使用できますか? 何が欠けているのかわかりません。<h:commandButton>を使用しても使用し<a4j:jsFunction>なくても動作しますがSeamSeamを使用すると では動作しません<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());
    }

}

datatable.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>
4

2 に答える 2

2

値については完全にはわかりませんnull。ポストバック後にデータが存在しない場合 (頻繁に繰り返される間違い)、メソッドはまったく呼び出されるべきではありません。

ただし、コードにバグがあります。それa4j:jsFunctionは関数を作成し、それを という名前の js 変数に割り当てますsubmit。これはすべての行で同じになります。

つまりsubmit=function(){RichFaces.ajax("j_idt15:departmentTable:0:j_idt18" ...、最初の行、submit=function(){RichFaces.ajax("j_idt15:departmentTable:1:j_idt18" ...2 番目の行、というように続きます。

ダイアログは常に最後の行からのものを呼び出します。nullでは、テーブルにフィードするリストの最後の値としてa はありますか?

次の少し単純化されたコードを使用して、アクション メソッドで渡されたパラメーターを取得します。

@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);
    }

}

datatable.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);
    }

}

Department.java:

public class Department {

}

(他のすべてのコードは以前と同じです)

これはすべきであり、(私の側では)実際には何の違いもありません。String配列を1 つに変更したときDepartment、私と同じようにしましたか? 完全なバッキング Bean を表示できますか?

于 2012-09-19T22:45:33.497 に答える
0

でこの問題を解決しようとしていますjavascript。それは不適切な解決策になる可能性があります。データテーブルの各行のIDを取得したいため、パラメーターとしてdatatable渡します。ユーザーが ConfirmationBox のボタンをクリックすると、JavaScript がクリックします。row Index<h:commandButton><h:commandButton>OK

確認.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="#{value}" onclick="#{rich:component('confirmation')}.show();return false"/>

    <h:commandButton id="commandButton" value="direct" action="#{methodParam}" style="display:none;"/>

    <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="document.getElementById('#{index}:commandButton').click();#{rich:component('confirmation')}.hide();return false;" />
                <input type="button" value="Cancel" onclick="#{rich:component('confirmation')}.hide(); return false" />
            </h:panelGroup>
        </h:panelGrid>
    </rich:popupPanel>

    </ui:composition>

データテーブル内。

    <rich:dataTable id="departmentTable" value="#{DataTableBacking.items}" var="dep" style="width:100%" rowKeyVar="index">
        <rich:column style="width:100px;text-align:center;">
            <f:facet name="header">
                <h:outputText value="Name"/>
            </f:facet>
            #{dep.name}
            <richm:confirmLink value ="Delete" index="tableForm:departmentTable:#{index}" actionBeanMethod="#{DataTableBacking.action(dep)}" render="departmentTable"/>
        </rich:column>
    </rich:dataTable>
于 2012-09-20T09:40:39.200 に答える