即使Managed bean包含方法,服务器抛出消息也没有属性'getCustomerDetails'

时间:2013-04-26 04:05:47

标签: java jsf

我正在研究JSF应用程序,甚至认为托管bean有方法,但服务器抛出消息为 enter image description here

以下是托管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>

建议我如何解决这个问题。

2 个答案:

答案 0 :(得分:0)

我以前从未与面孔合作过。 我认为问题是你如何尝试访问你的方法...... 尝试更改

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

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

或许(如果面孔有些魔力)

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

答案 1 :(得分: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根本不适合你(因此你被迫采用旧的JSF 1.x路径在XML中注册它,这意味着<f:ajax>也不会被解释为JSF标记,因为JSF 1.x中不存在