【事象】
画面から番号と氏名を入力し、その入力内容をコンソールに表示する、というプログラムを書いているのですが、実行すると、RuntimeExceptionになり、画面が開けません。
【試したこと】
バッキングビーン(MeiboBean.java)の@RequestScopedを削除して実行してみたら、画面を表示するところまではできました。なので、おそらく@RequestScopedアノテーションを書いたことが原因だと思うのですが、書き方が間違っているとは思えないです。
このサイトに書いてある、importを使わない方法は、試しましたが、それでもだめでした。
JSF2.2入門 第16回CDIとManagedBeanのRequestScoped(リクエストスコープ)
【環境】
ブラウザ:IE
統合開発環境:NetBeans
サーバランタイム:glassfish
java
1 2package bean; 3 4import javax.enterprise.context.RequestScoped; 5import javax.inject.Named; 6 7 8@Named 9@RequestScoped 10public class MeiboBean{ 11 private Integer number; 12 private String name; 13 public void toConsole(){ 14 System.out.println("number = "+this.number+ "/ name=" +this.name); 15 } 16 public Integer getNumber() { 17 return number; 18 } 19 public void setNumber(Integer number) { 20 this.number = number; 21 } 22 public String getName() { 23 return name; 24 } 25 public void setName(String name) { 26 this.name = name; 27 } 28} 29
jsf
1<?xml version='1.0' encoding='UTF-8' ?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" 4 xmlns:h="http://xmlns.jcp.org/jsf/html"> 5 <h:head> 6 <title>Sample01</title> 7 </h:head> 8 <h:body> 9 <h2>名簿データの作成</h2> 10 <h:form> 11 番号:<h:inputText value="#{meiboBean.number}" /><br/> 12 氏名:<h:inputText value="#{meiboBean.name}" /><br/> 13 <h:commandButton value="送信" actionListener = "#{meiboBean.toConsole()}"/> 14 </h:form> 15 16 </h:body> 17</html>
stacktrace
1java.lang.RuntimeException: 2 at bean.MeiboBean.<init>(MeiboBean.java:1) 3 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 4 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) 5 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 6 at java.lang.reflect.Constructor.newInstance(Constructor.java:423) 7 at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:119) 8 at org.jboss.weld.injection.ConstructorInjectionPoint.invokeAroundConstructCallbacks(ConstructorInjectionPoint.java:92) 9 at org.jboss.weld.injection.ConstructorInjectionPoint.newInstance(ConstructorInjectionPoint.java:78) 10 at org.jboss.weld.injection.producer.AbstractInstantiator.newInstance(AbstractInstantiator.java:28) 11 at org.jboss.weld.injection.producer.BasicInjectionTarget.produce(BasicInjectionTarget.java:112) 12 at org.jboss.weld.injection.producer.BeanInjectionTarget.produce(BeanInjectionTarget.java:180) 13 at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:158) 14 at org.jboss.weld.contexts.AbstractContext.get(AbstractContext.java:96) 15 at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:100) 16 at org.jboss.weld.bean.ContextualInstanceStrategy$CachingContextualInstanceStrategy.get(ContextualInstanceStrategy.java:177) 17 at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50) 18 at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:676) 19 at org.jboss.weld.module.web.el.AbstractWeldELResolver.lookup(AbstractWeldELResolver.java:107) 20 at org.jboss.weld.module.web.el.AbstractWeldELResolver.getValue(AbstractWeldELResolver.java:90) 21 at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:147) 22 at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:156) 23 at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:184) 24 at com.sun.el.parser.AstIdentifier.getValue(AstIdentifier.java:92) 25 at com.sun.el.parser.AstValue.getBase(AstValue.java:126) 26 at com.sun.el.parser.AstValue.getValue(AstValue.java:175)

あなたの回答
tips
プレビュー