2016-12-03 5 views
1

私はデータベース(JBDC)の "面"を追加または削除できるJSFページを持っています。私は2つの豆(@RequestScopedの両方)、1つの "コントローラ"と1つの "バッキングBean"を持っています。@RequestScoped Beanは期待どおりに機能していませんか? (JSF)

enter image description here

そして、いくつかの入力を持つ:ここで

は、JSFページで情報を入力し、写真を追加した後

enter image description here

、 "飛行機" は、私のページに追加されます、私はページをリロードします。ここで

が提出した後、ページがどのように見えるかです:

enter image description here

私の問題は、ここで入力されたテキストフィールドが情報を持つBeanから「人口」を取得し、また、削除プレーンフィールドは人口なる、ということです飛行機のID。私はこれらのフィールドを爽やかにしてから空にしておき、@RequestScopedの使用が便利だと思っていたことを考えています。また、Webブラウザからページを更新しようとすると、フォームを再送信しようとします。

どのようにフィールドにBeanのデータが入力されるのを避けることができますか?

また、ここではBeanコードです:

@Named 
@RequestScoped 
public class AddAirplaneCtrl implements Serializable{ 

    @Inject 
    private FlightModel flightModel; 

    private ListAirplaneBB listAirplaneBB; 

    protected AddAirplaneCtrl(){ 
     ; 
    } 

    @Inject 
    public void addListAirplaneBB(ListAirplaneBB listAirplaneBB){ 
     this.listAirplaneBB = listAirplaneBB; 
    } 

    public String addPlane(){ 

     listAirplaneBB.setError(null); 
     listAirplaneBB.setMessage(null); 

     if(failed any of the validation parts){ 
      return /some/site?faces-redirect=false"; 
     } 

     //add plane 
     return /some/site?faces-redirect=true"; 
    } 
} 

とバッキング・ビーン:

@Named 
@RequestScoped 
public class ListAirplaneBB implements Serializable{ 

    @Inject 
    private FlightModel flightModel; 

    //private variable fields 

    public List<Airplane> getAllPlanes(){ 
     return flightModel.getAirplaneList().findAll(); 
    } 

    public int getTotalPlanes(){ 
     return getAllPlanes().size(); 
    } 

    //GETTERS and SETTERS 

} 

そして最後に、私のJSFページ:

<div class="contbox"> 
        <h3> 
         <h:outputLabel value="Edit Planes" /> 
        </h3> 
        <c:if test="#{not empty listAirplaneBB.error}"> 
         <div class="alert alert-danger" 
          id="success-alert"> 
          <span class="glyphicon glyphicon-remove" /> 
          <h:outputText value="#{listAirplaneBB.error}" /> 
          <button type="button" 
            class="close" 
            data-dismiss="alert"> 
           <h:outputLabel value="x" /> 
          </button> 
         </div> 
        </c:if> 
        <c:if test="#{not empty listAirplaneBB.message}"> 
         <div class="alert alert-success"> 
          <span class="glyphicon glyphicon-remove" /> 
          <h:outputText value="#{listAirplaneBB.message}" /> 
          <button type="button" 
            class="close" 
            data-dismiss="alert"> 
           <h:outputLabel value="x" /> 
          </button> 
         </div> 
        </c:if> 

        <h4>Add A Plane</h4>      
        <h:form enctype="multipart/form-data"> 
        <table id="addtable" 
          class="table"> 
         <thead> 
          <tr> 
           <th> 
            <h:outputLabel value="Plane Make" /> 
           </th> 
           <th colspan="1"> 
            <h:outputLabel value="Plane Model" /> 
           </th> 
           <th colspan="1"> 
            <h:outputLabel value="Plane Seats" /> 
           </th> 
           <th colspan="1"> 
            <h:outputLabel value="Plane Photo" /> 
           </th> 
          </tr> 
         </thead> 
         <tr>  
          <td> 
           <h:inputText value="#{listAirplaneBB.make}"> 
           </h:inputText> 
          </td> 
          <td> 
           <h:inputText value="#{listAirplaneBB.model}"> 
           </h:inputText> 
          </td> 
          <td> 
           <h:inputText value="#{listAirplaneBB.seats}"> 
           </h:inputText> 
          </td> 
          <td> 
           <h:inputFile value="#{listAirplaneBB.file}" > 
           </h:inputFile> 
          </td>  
          <td> 
           <h:commandButton value="Add Plane" 
               class="btn btn-primary" 
               action="#{addAirplaneCtrl.addPlane()}" > 
           </h:commandButton> 
          </td> 
         </tr> 
        </table> 
        </h:form>     
        <h4>Delete Plane</h4> 

        <h:form> 
         <h:panelGrid columns="3" class="table"> 
          <h:outputLabel value="Plane ID" /> 
          <h:inputText value="#{listAirplaneBB.airPlaneId}"/> 
          <h:commandButton value="Delete" 
              class="btn btn-primary" 
              action="#{addAirplaneCtrl.deleteAirplane}" > 
          </h:commandButton> 
         </h:panelGrid> 
        </h:form> 
       </div> 
+0

@BalusCあなたに役立つ情報はありますか? – Carlton

答えて

0

お使いのブラウザのキャッシュ入力。

JSF 2.2ソリューション

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:ui="http://java.sun.com/jsf/facelets" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"> 
... 
    <f:passThroughAttribute name="autocomplete" value="off"/> 
... 

jQueryのソリューション:

<h:form styleClass="form">...</h:form> 

<script> 
    $(function(){ 
     $(".form").attr("autocomplete", "off"); 
    }); 
</script> 

あなたはより多くの情報hereを見つけることができます。

+0

このエラーは、「コンポーネントのフォームに属性のオートコンプリートが定義されていません」というエラーが表示されます。このエラーは何を意味しますか? – Carlton

+0

更新された解決策 – jklee

+0

私のケースでは機能しませんでした。私はそれがBeanの問題だと確信しています。Beanは、同じページにリダイレクトした後にBeanの値を保持します。そしてそれはリクエストスコープのBeanです。リダイレクト後にこれらのフィールドを空にする方法に関するアイデアはありますか? – Carlton

関連する問題