2015-11-30 1 views
1

Я создал класс Java в Eclipse, Java EE IDE (Luna Release 2 (4.4.2) и Java jre1.8.0_66Неразрешенные проблемы с компиляцией: тип java.lang.String не может быть разрешен. . Неявный конструктор Object() не определен

package com.luv2code.jsf.hello; 
import javax.faces.bean.ManagedBean; 



@ManagedBean 
public class Student { 


    private String sfirstName; 
    private String slastName; 

    // create a no-arg constructor 
    public Student() { 

    } 

    public String getFirstName() { 
     return sfirstName; 
    } 

    public void setFirstName(String sfirstName) { 
     this.sfirstName = sfirstName; 
    } 

    public String getLastName() { 
     return slastName; 
    } 

    public void setLastName(String slastName) { 
     this.slastName = slastName; 
    } 

    // define public getter and setter methods to expose properties of the managed Bean 

} 

Ошибка я получаю:

HTTP Status 500- Unresolved compilation problems 
type Exception report 
message unresolved compilation problem 
description The server encountered an internal error that prevented it from fulfilling this request. 
exception 
javax.servlet.ServletException: Unresolved compilation problems: 
The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files 
String cannot be resolved to a type 
String cannot be resolved to a type 
Implicit super constructor Object() is undefined. Must explicitly invoke another constructor 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 

javax.faces.webapp.FacesServlet.service(FacesServlet.java:659) 
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 
root cause 
java.lang.Error: Unresolved compilation problems: 
The type java.lang.String cannot be resolved. It is indirectly referenced from required .class files 
String cannot be resolved to a type 
String cannot be resolved to a type 
Implicit super constructor Object() is undefined. Must explicitly invoke another constructor 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 
String cannot be resolved to a type 

com.luv2code.jsf.hello.Student.<init>(Student.java:1)r 





com.luv2code.jsf.hello.Student.<init>(Student.java:1) 
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) 
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) 
java.lang.reflect.Constructor.newInstance(Unknown Source) 
java.lang.Class.newInstance(Unknown Source) 
com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186) 
com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:100) 
com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) 
com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) 
com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244) 
com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116) 
com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) 
com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) 
org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:80) 
org.apache.el.parser.AstValue.getValue(AstValue.java:137) 
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184) 
com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) 
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) 
javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) 
javax.faces.component.UIOutput.getValue(UIOutput.java:174) 
javax.faces.component.UIInput.getValue(UIInput.java:291) 
com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205) 
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:355) 
com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164) 
javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:924) 
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1863) 
javax.faces.render.Renderer.encodeChildren(Renderer.java:176) 
javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:894) 
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1856) 
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) 
javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859) 
com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443) 
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131) 
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) 
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) 
javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) 
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 

и если я парить над String, я вижу

String cannot be resolved to a type

и если я парить над Student (в конструктор без аргументов) Я вижу:

Implicit constructor Object() is undefined. Must explicitly invoke another constructor.

Я не уверен, почему это не позволит мне использовать приватную String in m Student class. Может ли кто-нибудь объяснить это или предложить мне какое-нибудь предложение?

ответ

1

Я бы рекомендовал прочитать учебное пособие по JSF. потому что у вас, похоже, проблема в основах JSF!

теперь вернемся к вашим проблемам:

  1. класс Студент должен быть класс DataModel и не managedBean класса
  2. в зависимости от конфигурации шаблона FacesServlet в web.xml, вы должны запустить приложение и не один файл. после запуска контейнер (Tomcat), вызовите URL для вашего проекта: т.е. локальный: 8080/Тестирование/лица/test.xhtml
  3. в вашем XHTML у вас есть ошибка синтаксиса: <:inputText value="#{student.slastName}" />, его следует начинать с <h:...
  4. в (applicationScoped, SessionScoped, ViewScoped, ... и т. д.), вы не объявляете это в своем бине
  5. личные поля управляемого Beean должны иметь getter/setter, доступ к ним может быть открыт только для общественности извне (в пределах view/xhtml)

вот пример, как это должно быть:

DataModel класс:

package a.b.model; 

import java.io.Serializable; 

public class Student implements Serializable{ 
    private static final long serialVersionUID = -7013884476678061379L; 
    private String firstName; 
    private String lastName; 

    public Student() { 

    } 

    public String getFirstName() { 
     return firstName; 
    } 
    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 
    public String getLastName() { 
     return lastName; 
    } 
    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    }  
} 

ManagedBean:

package a.b.controler; 

import java.io.Serializable; 
import javax.annotation.PostConstruct; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.faces.event.AjaxBehaviorEvent; 
import a.b.model.Student; 

@ManagedBean 
@SessionScoped 
public class StudentManager implements Serializable { 
    private static final long serialVersionUID = -6254452297683880945L; 
    private Student student;  
    public StudentManager(){ 

    } 
    @PostConstruct 
    public void init(){ 
     System.out.println("Called once on Object init!"); 
     this.student = new Student(); 
    } 
    public final void save (AjaxBehaviorEvent event){ 
     System.out.println("Ajax command ...."); 
     System.out.println("Firstname: "+this.getStudent().getFirstName()); 
     System.out.println("Lasttname: "+this.getStudent().getLastName()); 
    } 

    public Student getStudent() { 
     return student; 
    } 
    public void setStudent(Student student) { 
     this.student = student; 
    } 
} 

web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 
    <display-name>Testing</display-name> 
    <servlet> 
    <servlet-name>Faces Servlet</servlet-name> 
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 
    <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
    <servlet-name>Faces Servlet</servlet-name> 
    <url-pattern>/faces/*</url-pattern> 
    </servlet-mapping> 
    <context-param> 
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> 
    <param-value>resources.application</param-value> 
    </context-param> 
</web-app> 

The View test.xhtml :

<!DOCTYPE html> 
<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html"> 
<h:head> 
    <meta charset="UTF-8" /> 
    <title>Student Registration</title> 
</h:head> 
<body> 
    <h:form> 
      First Name: <h:inputText value="#{studentManager.student.firstName}" /> 
     <br /> 
     <br /> 
      Last Name: <h:inputText value="#{studentManager.student.lastName}" /> 
     <br /> 
     <br /> 
     <h:commandButton value="Submit"> 
     <f:ajax execute="@form" listener="#{studentManager.save}"/> 
     </h:commandButton> 
    </h:form> 
</body> 
</html> 

после запуска контейнер (Tomcat), откройте его в браузере так:

http://localhost:8080/Testing/faces/test.xhtml 
+0

Читали ли вы ошибки OP получили? Ничто из этого не связано с JSF. OP просто полностью испортил конфигурацию IDE. Я отредактировал вопрос, чтобы уменьшить нерелевантный шум, чтобы он лучше сфокусировался. – BalusC

Смежные вопросы