0

我正在开发 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

Your code is valid. The exception just indicates that the EL expression is been interpreted as part of template text like as would happen in <p>#{customer.getCustomerDetails}</p>. The expression is just been evaluated as a value expression during rendering of the page instead of a method expression. A value expression requires a getter method which however doesn't exist in your particular case.

This in turn suggests that the <f:xxx> namespace is nowhere registered and thus the <f:ajax> is not interpreted as a tag, but as "plain HTML".

To fix it, make sure that you've the JSF core XML namespace declaration in the XML root element:

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

Unrelated to the concrete problem, you're mixing @ManagedBean on class and <managed-bean> in faces-config.xml. I'm not sure why you're doing that, but another possible reason reason would be that you're mixing JSF 1.x with 2.x and thus @ManagedBean didn't work for you at all (and thus you're forced to take the old JSF 1.x path of registering it in XML), which implies that the <f:ajax> also won't be interpreted as a JSF tag as that didn't exist in JSF 1.x.

于 2013-04-26T11:59:22.317 回答
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 回答