java – 在jsf中找不到类型的属性

前端之家收集整理的这篇文章主要介绍了java – 在jsf中找不到类型的属性前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图在jsf中调用一个使用primefaces的属性.但我有类型managedbean.PersonelBean上找不到的错误500.
我正在使用hibernate jsf和 spring.

PersonelBean.java

@ManagedBean(name="personelMB")
@SessionScoped
public class PersonelBean implements Serializable{
    private static final long serialVersionUID = 1L;

    @ManagedProperty(value="#{PersonelService}")
    IPersonelService personelservice;
    List<Personel> personelList;

    private int personel_id;
    private String pname;
    private String pfamily;
    private String paddress;
    private String pphone;
    public IPersonelService getPersonelservice() {
        return personelservice;
    }
    public void setPersonelservice(IPersonelService personelservice) {
        this.personelservice = personelservice;
    }
    public List<Personel> getPersonelList() {
        personelList=new ArrayList<Personel>();
        personelList.addAll(getPersonelservice().getPersonels());
        return personelList;
    }
    public void setPersonelList(List<Personel> personelList) {
        this.personelList = personelList;
    }
    //getter and setter method

    public void addPersonel(){
        Personel personel=new Personel();
        personel.setPaddress(getPaddress());
        personel.setPersonel_id(getPersonel_id());
        personel.setPfamily(getPfamily());
        personel.setPname(getPname());
        personel.setPphone(getPphone());
        getPersonelservice().addPersonel(personel);
    }

}

personel.xhtml

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="rtl" 
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:fn="http://java.sun.com/jsp/jstl/functions"
>
<h:head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>اطلاعات پرسنلی</title>
</h:head>
<h:body>
<h1>اضافه کردن پرسنل جدید</h1>
        <h:form>

            <h:panelGrid columns="4" >
              شماره پرسنلی : 
                <h:inputText id="id" value="#{personelMB.personel_id}" 
                    size="20" required="true"
                    label="id" >
                </h:inputText>
                <br></br>
                نام : 
                <h:inputText id="name" value="#{personelMB.pname}" 
                    size="20" required="true"
                    label="Name" >
                </h:inputText>

                 نام خانوادگی: 
                <h:inputText id="family" value="#{personelMB.pfamily}" 
                    size="20" required="true"
                    label="family" >
                </h:inputText> 

                آدرس : 
                <h:inputTextarea id="address" value="#{personelMB.paddress}" 
                    cols="30" rows="10" required="true"
                    label="Address" >
                </h:inputTextarea>


          تلفن:  
                <h:inputText id="tel" value="#{personelMB.pphone}" 
                    size="20" required="true"
                    label="tel" >
                </h:inputText> 
            </h:panelGrid>

            <h:commandButton value="درج اطلاعات" action="#{personelMB.addPersonel()}" />

        </h:form>
 <h2>مشاهده اطلاعات پرسنل</h2>  
 <h:form prependId="false">  

    <p:dataTable id="dataTable" var="personel" value="#{personelMB.getPersonelList()}">  

        <f:facet name="header">  
            اطلاعات پرسنل 
        </f:facet>  

        <p:column>  
            <f:facet name="header">  
               شماره پرسنلی  
            </f:facet>  

            <h:outputText value="#{personel.personel_id}" />  

            <f:facet name="footer">  
                کدملی 
            </f:facet>  
        </p:column>  

        <p:column headerText="نام">  
            <h:outputText value="#{personel.pname}" />  
        </p:column>  

        <p:column headerText="نام خانوادگی">  
            <h:outputText value="#{personel.pfamily}" />  
        </p:column>  

        <p:column headerText="آدرس">  
            <h:outputText value="#{personel.paddress}" />  
        </p:column>  
   <p:column headerText="تلفن">  
            <h:outputText value="#{personel.pphone}" />  
        </p:column>
        <f:facet name="footer">  
            In total there are #{fn:length(personelMB.getPersonelList())} personels.  
        </f:facet>  

    </p:dataTable>  

</h:form>  

</h:body>
</html>

但我有这个错误

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: /personel.xhtml @58,88 value="#{personelMB.getPersonelList()}": Property 'getPersonelList' not found on type managedbean.PersonelBean
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:321)


root cause 

javax.el.PropertyNotFoundException: /personel.xhtml @58,88 value="#{personelMB.getPersonelList()}": Property 'getPersonelList' not found on type managedbean.PersonelBean
    com.sun.faces.facelets.el.TagValueExpression.getType(TagValueExpression.java:97)
    org.primefaces.component.api.UIData.isLazyLoading(UIData.java:170)
    org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:187)
    org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:107)
    javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:879)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1650)
    javax.faces.render.Renderer.encodeChildren(Renderer.java:164)
    javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:849)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1643)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1646)
    javax.faces.component.UIComponent.encodeAll(UIComponent.java:1646)
    com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:389)
    com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:127)
    com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:117)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:97)
    com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:135)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:309)

我不知道出了什么问题,但我的addPersonel()效果很好.

解决方法

属性值表达式需要使用以下语法指定,不带get(或is)前缀且不带括号:
value="#{personelMB.personelList}"
原文链接:https://www.f2er.com/java/120721.html

猜你在找的Java相关文章