0

IamはJSFアプリケーションに取り組んでいますが、マネージドBeanにはメソッドがあると思っていましたが、サーバーは次のようにメッセージをスローしています ここに画像の説明を入力

以下は、マネージド Bean のコードです。

package retail.web.mbean;

import java.io.Serializable;
import java.util.List;
import java.util.Properties;

import javax.faces.bean.ManagedBean;
import javax.faces.event.AjaxBehaviorEvent;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


import retail.ejb.service.CustomerSessionBeanRemote;
import retail.model.vo.Customer;


@ManagedBean
public class CustomerMB implements Serializable{
    /**
     * 
     */
    private static final long serialVersionUID = -4402277663508618618L;
    private Customer customer = new Customer();
    public void CustomerMB(){
        System.out.println("customer method +++++++++++++++++++++++"+getCustomer());
    }

private List<Customer> customerList;


public Customer getCustomer() {
    return customer;
}



public void setCustomer(Customer customer) {
    this.customer = customer;
}



public List<Customer> getCustomerList() {
    return customerList;
}



public void setCustomerList(List<Customer> customerList) {
    this.customerList = customerList;
}



public String createCustomer() throws NamingException{
    try{
    System.out.println("in Create customer method +++++++++++++++++++++++");
    Properties p = new Properties();
    //p.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
    p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
    p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
    p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
    p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
    p.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); //any configured port different from 3700 - 34513
    InitialContext c = new InitialContext(p);
    System.out.println("in Create customer method remote+++++++++++++++++++++++");
    CustomerSessionBeanRemote remote = (CustomerSessionBeanRemote) c.lookup("java:global/RetailProducts/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote");
                                                                            //java:global/RetailService/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote
     //java:global/RetailProducts/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote
    System.out.println("in Create customer method remote222+++++++++++++++++++++++");
    remote.insterCustomerDetails(getCustomer());
    remote.showCustDetails();
    }catch(Exception e){
        e.printStackTrace();
    }
    //System.exit(1);
    return "viewCustomerDetails";
}

public void getCustomerDetails(AjaxBehaviorEvent event){
    //List<Customer> customer = null;
    try{
        System.out.println("in Create customer method +++++++++++++++++++++++");
        Properties p = new Properties();
        //p.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
        p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
        p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
        p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
        p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
        p.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); //any configured port different from 3700 - 34513
        InitialContext c = new InitialContext(p);
        System.out.println("in Create customer method remote+++++++++++++++++++++++");
        CustomerSessionBeanRemote remote = (CustomerSessionBeanRemote) c.lookup("java:global/RetailProducts/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote");
                                                                                //java:global/RetailService/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote
         //java:global/RetailProducts/CustomerSessionBeanImpl!retail.ejb.service.CustomerSessionBeanRemote
        System.out.println("in Create customer method remote222+++++++++++++++++++++++");
        //remote.insterCustomerDetails(getCustomer());
        //customer = remote.showCustDetails();
        setCustomerList(remote.showCustDetails());
        }catch(Exception e){
            e.printStackTrace();
        }
        //System.exit(1);
    //  return customer;

}
}

xhtml ページ

<h:form id="hidden" style="display:none">
        <h:commandLink id="link">
        <f:ajax event="click" listener="#{customer.getCustomerDetails}"/>

        </h:commandLink>
    </h:form>


顔-config.xml

   <managed-bean>
   <managed-bean-name>customer</managed-bean-name>
   <managed-bean-class>retail.web.mbean.CustomerMB</managed-bean-class>
   <managed-bean-scope>session</managed-bean-scope>
</managed-bean>


この問題を解決する方法を教えてください。

4

2 に答える 2

0

私はこれまで顔を扱ったことはありません。問題は、メソッドにアクセスしようとしている方法だと思います...変更してみてください

    <f:ajax event="click" listener="#{customer.getCustomerDetails}"/>

    <f:ajax event="click" listener="#{customer.getCustomerDetails(...)}"/>

または多分(顔が魔法をかけるなら)

    <f:ajax event="click" listener="#{customer.customerDetails}"/>
于 2013-04-26T04:38:17.503 に答える
0

あなたのコードは有効です。例外は、EL 式がテンプレート テキストの一部として解釈されたことを示しているだけです<p>#{customer.getCustomerDetails}</p>。式は、メソッド式ではなく、ページのレンダリング中に値式として評価されました。値式には getter メソッドが必要ですが、特定のケースでは存在しません。

<f:xxx>これは、名前空間がどこにも登録されていないことを示唆しているため、<f:ajax>はタグとして解釈されず、「プレーンな HTML」として解釈されます。

これを修正するには、XML ルート要素に JSF コア XML 名前空間宣言があることを確認してください。

xmlns:f="http://java.sun.com/jsf/core"

具体@ManagedBean的な問題とは関係なく、クラスと<managed-bean>インで混在していますfaces-config.xml。なぜそうしているのかはわかりませんが、別の考えられる理由として、JSF 1.x と 2.x を混在さ@ManagedBeanせているため、まったく機能しなかったことが考えられます (したがって、強制的にこれ<f:ajax>は、JSF 1.x には存在しなかったため、JSF タグとしても解釈されないことを意味します。

于 2013-04-26T11:59:22.317 に答える