2017-03-24 12 views
0

管理対象Beanは、jsfページの単純なフォームからNULL値を取得します。実際には、私はかなり開発されたインターフェイスを持っていますが、問題は簡単なフォームでも起こっています。jsfページから値を取得できません

(JSF 2.1.0、Javaコンパイラ1.6は、6.0とtomcat7をprimefaces)

重複した質問のようです。しかし、5日前、私はこの奇妙な問題の解決策を探しています。私は多くのソリューションを見つけましたが、それは私のためには機能しません。たぶん私はBalusC(commandButton/commandLink/ajax action/listener method not invoked or input value not updated)からの答えとしてそれらをあまり理解していませんでした。

JSFページ:

<?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 xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:p="http://primefaces.org/ui" 
    xmlns:c="http://java.sun.com/jsp/jstl/core"> 
<h:head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
</h:head>  
<h:body> 
    <h:form> 
      <h:inputText value="#{notification.typeSelected}"></h:inputText> 
      <p:commandButton value="Enregistrer" 
       actionListener="#{notificationBean.filtrer}" process="@this" 
       style="float:right"> 
      </p:commandButton> 
     </h:form> 
</h:body> 
</html> 

管理Bean:

package presentation; 
import java.util.ArrayList; 
import java.util.List;  
import javax.annotation.PostConstruct; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.faces.event.ActionEvent; 
//import javax.faces.event.ValueChangeEvent; 
import javax.faces.model.SelectItem;  
import org.apache.log4j.Logger;  
import entities.Contrainte; 
import metier.ContrainteMetier; 
import metier.ContrainteMetierImp;  
@ManagedBean 
@SessionScoped 
public class NotificationBean implements java.io.Serializable{ 
    private static final long serialVersionUID = 1L; 

    public static Logger log = Logger.getLogger(ProjetMODBean.class); 

    private ContrainteMetier contrainteM = new ContrainteMetierImp(); 
    private List<Contrainte> contrainteL; 
    private List<Contrainte> filtreL; 
    private List<SelectItem> classificationL; 
    private String typeSelected; 
    //Constructeurs 
    public NotificationBean() { 
    } 
    public NotificationBean(ContrainteMetier contrainteM, List<Contrainte> contrainteL) { 
     super(); 
     this.contrainteM = contrainteM; 
     this.contrainteL = contrainteL; 
    } 

    @PostConstruct 
    public void init() { 

     contrainteL = contrainteM.findAll(); 
     classificationL = new ArrayList<SelectItem>(); 

     for(Contrainte c:contrainteL) 
     {//Attention, il ne faut pas dupliquer les types dans la liste déroulante   
      classificationL.add(new SelectItem(c.getClassification())); 
     } 
     log.info(" dans init je filtre selon: " + getTypeSelected()); 


    } 


    //Méthodes 
    public void filtrer(ActionEvent e) 
    { 
     setTypeSelected(typeSelected); 
     log.info("je filtre selon: " + getTypeSelected());  
    } 

コンソール出力:

2017-03-24 18:06:43 INFO ProjetMODBean:57 - dans init je filtre selon: null 
2017-03-24 18:06:43 INFO ProjetMODBean:76 - je filtre selon: null 

私は自分のエラーを修正しようとしましたが、詳細は私をエスケープします。

+0

に変更しました。注入されていないpostConstructのフィールドにアクセスするのは変です。私はNPEのそれを期待するか、あなたは間違った方法で豆を使用する – Kukeltje

答えて

2

あなたの問題はprocess="@this"です(正当な理由がある場合にのみデフォルト値ですので変更してください)。または、idを入力してprocess="@this idOfInputField"を使用してください。

questionを参照してください。

英語で質問を投稿してください。 私は、//メドノードはフィールドのゲッタ/セッタを意味します(JSFは入力用のゲッタ/セッタを必要とします)。

また、サービスのための注入を使用します。 メソッドヘッダをpublic void filtrer(ActionEvent e)からpublic void filtrer()

関連する問題