1

次の JSF ページで、ページの読み込み時に commandButton アクション リスナーを実行する必要がある状況があります。

        <?xml version='1.0' encoding='UTF-8'?>
        <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
         xmlns:f="http://java.sun.com/jsf/core"
         xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
         xmlns:trh="http://myfaces.apache.org/trinidad/html">
        <jsp:directive.page contentType="text/html;charset=UTF-8"/>

        <f:view>

       <af:document id="d1" partialTriggers="pt1">
       <af:resource type="javascript">  
       function callCustomButton(){
       var button =AdfPage.PAGE.findComponentByAbsoluteId("cbCustomFields");
       ActionEvent.queue(button,true);
       }
       </af:resource>



     <af:clientListener method="callCustomButton" type="load"/>

      <af:form id="f1">
     <af:pageTemplate viewId="/ESOPM_Base_Template.jspx" id="pt1">



    <f:facet name="main_content">

    <af:decorativeBox id="db1" theme="medium">
        <f:facet name="top"/>
        <f:facet name="center">
        <af:panelGroupLayout layout="scroll" id="pgl2"> 
        <trh:tableLayout id="tblUpload" cellPadding="3" cellSpacing="3"  halign="center" inlineStyle="font-size:1.2em; font-weight:bold; font-family:helvetica,sans-serif;">
                <trh:rowLayout id="rl1">

                    <trh:cellFormat id="cf1">            
                        <af:panelGroupLayout layout="horizontal" id="pgl3">

                   <af:commandButton text="Custom Fields"                       

                  actionListener="#{EditProperties.generateCustomAttributeFields}" 
                  id="cbCustomFields"  partialSubmit="true"  visible="true"/>
                        </af:panelGroupLayout>
                    </trh:cellFormat>
                </trh:rowLayout>

                  </trh:cellFormat>
              </trh:rowLayout>

        </trh:tableLayout>
        </af:panelGroupLayout>
        </f:facet>
        </af:decorativeBox>
        </f:facet>
</af:pageTemplate>
</af:form>
</af:document>
</f:view>

</jsp:root>

コマンドボタンは「カスタムフィールド」であり、クライアントリスナーを介してページで使用したjavascriptで呼び出そうとしています。ただし、ユーザーがこのページをロードすると、ボタンはクリックされず、そのアクション リスナー操作は実行されません。助けてください。

4

2 に答える 2

1

これはadf-stuffJSF2ですか?その場合、preRenderViewlistenerを使用して、ページの読み込み時にサーバー側で何かを実行できます。

<f:view>
    <f:metadata>
      <f:event type="preRenderView" listener="#{bean.doSomething}"/>
    </f:metadata>
</f:view>

アップデート

もう1つのアプローチは、バッキングBeanリクエストのスコープを設定し、@PostConstructアノテーションを使用してデータを初期化することです。

@ManagedBean
@RequestScoped
public class Bean {
    @PostConstruct
    public void init (){

    }  
}

また、別のJSFコンポーネントライブラリに切り替える機会がある場合は、Primefacesをお勧めします。これらは、クライアント側のスクリプトによってバッキングBeanメソッドを実行するための非常に単純なソリューションを提供します。https://www.primefaces.org/showcase/ui/ajax/remoteCommand.xhtmlを参照<p:remoteCommand>してください。

于 2012-09-05T21:11:25.173 に答える
1

f:view (マネージド Bean) で afterMethod を作成し、RENDER_RESPONSE フェーズをリッスンします。次に、への呼び出しによって JS を呼び出します。

String script = "callCustomButton();";
FacesContext fctx = FacesContext.getCurrentInstance();  
//Trinidad class
ExtendedRenderKitService erks = null;  
//Service also is a Trinidad class
erks = Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
erks.addScript(fctx, script);

ビュースコープでメモリフラグを設定して、二重呼び出しを避けるようにしてください

Frank Ps 管理対象 Bean (リスナー) でアクション イベントをキューに入れているサーバーでその関数を呼び出してみましたか?

于 2012-09-06T05:25:56.193 に答える