2016-04-30 14 views
0
<h:form> 
      <table> 
       <tr> 
        <td><label>First Name:</label></td> 
        <td><h:outputText value="#{profile.firstName}" 
          rendered="#{not profile.canEdit}" /></td> 
        <td><h:inputText value="#{profile.firstName}" 
          rendered="#{profile.canEdit}" required="true" /></td> 
        <td><h:commandButton value="Edit" 
          action="#{profile.editDetail}" /></td> 
        <td><h:commandButton value="Cancel" type="button" 
          action="#{profile.cancelBtn}" /></td> 
       </tr> 
       <tr> 
        <td><label>Last Name:</label></td> 
        <td><h:outputText value="#{profile.lastName}" 
          rendered="#{not profile.canEdit}" /></td> 
        <td><h:inputText value="#{profile.lastName}" 
          rendered="#{profile.canEdit}" required="true" /></td> 
        <td><h:commandButton value="Edit" 
          action="#{profile.editDetail}" /></td> 
        <td><h:commandButton value="Cancel" type="button" 
          action="#{profile.cancelBtn}" /></td> 
       </tr> 
       <tr> 
        <td><label>Email:</label></td> 
        <td><h:outputText value="#{profile.email}" 
          rendered="#{not profile.canEdit}" /></td> 
        <td><h:inputText value="#{profile.email}" id="email" 
          rendered="#{profile.canEdit}" required="true" /></td> 
        <td><h:commandButton value="Edit" 
          action="#{profile.editDetail}" /></td> 
        <td><h:commandButton value="Cancel" type="button" 
          action="#{profile.cancelBtn}" /></td> 
        <td><h:message for="email" value="#{profile.errorMessage}" 
          rendered="#{profile.errorMessage ne null}" /></td> 
       </tr> 
       <tr> 
        <td><label>Password:</label></td> 
        <td><h:outputText value="#{profile.password}" 
          rendered="#{not profile.canEdit}" /></td> 
        <td><h:commandButton value="Edit" 
          action="#{profile.editDetail}" /></td> 
        <td><h:commandButton value="Cancel" type="button" 
          action="#{profile.cancelBtn}" /></td> 
       </tr> 
       <h:panelGroup rendered="#{profile.canEdit}"> 

        <tr> 
         <td><label>Old Password: </label></td> 
         <td><h:inputText value="#{profile.password}" required="true" /></td> 
         <td><h:outputText rendered="#{profile.errorMessage != null}" 
           value="#{profile.errorMessage}"></h:outputText></td> 
        </tr> 
        <tr> 
         <td><label>New Password: </label></td> 
         <td><h:inputSecret value="#{profile.newPassword}" 
           required="true" /></td> 
        </tr> 
        <tr> 
         <td><label>Confirm Password: </label></td> 
         <td><h:inputSecret value="#{profile.confirmPassword}" 
           required="true" /></td> 
         <td><h:outputText 
           rendered="#{profile.confirmPassword != profile.newPassword}" 
           value="Passwords donot match!!"></h:outputText></td> 
        </tr> 
        <tr> 
         <td><h:commandButton action="#{profile.savePassword}" 
           value="Save Password" 
           disabled="#{profile.confirmPassword != profile.newPassword}" /></td> 
         <td><h:commandButton action="#{profile.cancelBtn}" value="Cancel" type="button"/></td> 
        </tr> 

       </h:panelGroup> 
       <tr> 
        <td><label>Gender</label></td> 
        <td>#{profile.gender}</td> 
       </tr> 
       <tr> 
        <td><label>City</label></td> 
        <td>#{profile.city}</td> 
       </tr> 
       <tr> 
        <td><label>State</label></td> 
        <td>#{profile.state}</td> 
       </tr> 
       <tr> 
        <td><label>Country</label></td> 
        <td>#{profile.country}</td> 
       </tr> 
       <tr> 
        <td><label>Zip-Code</label></td> 
        <td>#{profile.zipCode}</td> 
       </tr> 
       <tr> 
        <td><label>Phone Number</label></td> 
        <td>#{profile.phoneNumber}</td> 
       </tr> 
       <tr> 
        <td><h:commandButton action="#{profile.saveDetails}" 
          disabled="#{profile.canEdit eq 'false'}" value="Save" /></td> 
        <td><h:commandButton action="#{profile.cancelBtn}" type="button" 
          value="Cancel" /></td> 
       </tr> 
      </table> 
     </h:form> 

マイコードスニペット私はUIコンポーネントは、Beanの値をバックアップした後、アップデートをいけない、私のバッキングBeanの

  1. が必要

    public String InitializeValues(){ 
    
    
        customer = (CustomerVO) sessionManager.getSession("CustomerBean"); 
        System.out.println("inside profilepagecontroller"+"\n"+ customer); 
        setFirstName(customer.getFirstName()); 
        this.setLastName(customer.getLastName()); 
        this.setEmail(customer.getEmail()); 
        this.setPassword(customer.getPassword()); 
        this.setCity(customer.getCity()); 
        this.setState(customer.getState()); 
        this.setCountry(customer.getCountry()); 
        this.setPhoneNumber(customer.getPhoneNumber()); 
        this.setGender(customer.getGender()); 
        this.setZipCode(customer.getZipCode()); 
        this.setCustomerId(customer.getCustomerId()); 
    
        return "ProfilePage"; 
    
    } 
    
    
    
    public String editDetail(){ 
        setCanEdit(true); 
        setCanSave(true); 
        return null; 
    } 
    
    public String cancelBtn(){ 
        setCanEdit(false); 
        return "ProfilePage"; 
    } 
    

    問題点と解決策、私はcancelbuttonをクリックすると、canEditがに設定を変更しましたfalseですが、 のinputTextは画面に表示されません。 outputTextを表示しません。私は編集をクリックした後

  2. は、どのように私は編集モードでのみ特定のフィールドを得るのですか?(各フィールドOBVない 可能に別々のブール値を作成する)
  3. setterメソッドは、バッキングBeanのフィールドの値を設定します。私はコードを実行した後、同じが画面に表示されません。 'this'はすべて の値を表示する必要がありますが、画面には表示されません。

答えて

0

私はcancelbuttonをクリックすると、canEditはfalseに設定しますが、のinputText 「は、画面上un'renderedません。それはoutputTextをレンダリングしません

あなたのcommandButtonは、そのようにはならないtype = "button"を持っています。

私は編集をクリックした後、私は編集モードでのみ特定のフィールドを得るのですか?( が実行可能ではない各フィールドOBVに別々のブール値を作成する)

えっ確かにそれが可能です。私が使用している唯一のシナリオは、検証がいくつかのコンポーネントに合格しなかった場合です。あなたは#{component.valid}をレンダリングしようと思うと思います。問題は、すべてのコンポーネントが開始時に曖昧になり、無効がレンダリングされないことです。要求がポストバックである場合はそのチェックを解決するために:

public boolean isPostback(){ 
    return FacesContext.getCurrentInstance().isPostback(); 
} 
rendered="#{component.valid and not mybean.postback}" 

setterメソッドは、バッキングBeanのフィールドの値を設定します。私は のコードを実行した後、画面に同じものは表示されません。 'this'は表示する必要があるすべての 値を取得しますが、画面には表示されません。

は、私はそれあなたの資産計上方法は、あなたが話していることを初期化されたその質問を理解していませんか?あなたは全体の豆を投稿する必要がありますそれはここでは決して呼ばれていないcuz。

関連する問題