2017-11-16 5 views
0

"문서"엔티티 (JSF2 및 최대 절전 모드를 사용)에 대한 기본 편집 양식이 있는데 "작성"양식은 정상적으로 작동하지만 "편집"은 작동하지 않습니다. 따라서 편집 양식은 현재 문서 값을 표시하지만 새로운 값을 보낼 때 백bean은 이전 값을 가져 오지 않고 이전 엔티티와 같이 작동합니다. 내 edit.xhtml의JSF 업데이트 뷰가 bean을 변경하지 않습니다.

부품 : 내 문서 콩의

<ui:param name="doc" value="#{document.getDocument()}" /> 

<h:form id="editForm"> 
    <h:inputHidden name="ID" id="ID" value="#{doc.ID}" /> 

    <div class="input-group"> 
     <span class="input-group-label">Title *</span> 
     <h:inputText type="text" class="input-group-field" size="30" name="title" id="title" a:required="required" a:placeholder="title" value="#{doc.title}"/> 
    </div> 
    <h:message for="title"></h:message> 

    <div class="input-group"> 
     <span class="input-group-label">Subtitle</span> 
     <h:inputText type="text" class="input-group-field" size="30" name="subtitle" id="subtitle" a:placeholder="subtitle" value="#{doc.subtitle}" /> 
    </div> 
    <h:message for="subtitle"></h:message> 

    <div class="button-group"> 
     <h:button outcome="/main?faces-redirect=true" type="button" value="Cancel"></h:button> 
     <h:commandButton action="${doc.save}" value="Save"> 
      <f:ajax render="@form" execute=":editForm" event="keyup"/> 
     </h:commandButton> 
    </div> 

</h:form> 

부품 : 나는 문서 제목을 편집하는 경우

@ManagedBean 
@Entity 
@ViewScoped 
public class document implements Serializable { 
    private static final long serialVersionUID = 1L; 

    @Id 
    @GeneratedValue(strategy=GenerationType.IDENTITY) 
    @Column(name = "ID") 
    private int ID; 
    @NotNull 
    private String title; 
    private String subtitle; 

    //Getters Setters.... 

    @Transient 
    public document getDocument() { 
     documentDAO = new DocumentDAO(); 
     Optional<document> doc = documentDAO.read(this.ID); 
     if(doc.isPresent()) {   
      return doc.get(); 
     }else { 
      return null; 
     } 
    } 

    public String save() { 
     documentDAO = new DocumentDAO(); 
     System.out.println("Saving Document (" + this.getTitle() + ")..."); 
     documentDAO.update(this); 
     if(this.error == null || this.error.isEmpty()) 
       return "/list?faces-redirect=true"; 
     else 
      return "edit";    
    } 

는 "testok"에 의해, 예를 들어 "테스트"를했다, "testok"이 post html 요청으로 전송되었음을 알 수 있음에도 불구하고 "문서 저장 중 ..."이 아닌 "문서 저장 중 ..." 네비게이터의 웹 개발 패널 사용). 양식 안에 양식이 없습니다.

답변

0

편집을 위해 bean 사본을 사용하여 해결책을 찾은 다음 뷰 매개 변수에로드하여 이전 목록 페이지에서 ID를 검색합니다. 내 edit.xhtml의 헤더에서 :

<f:metadata> 
    <f:viewParam name="id" value="#{document.ID}"/> 
    <f:viewAction action="#{document.getDocument()}" /> 
</f:metadata> 

내 문서 콩에서 :

@Transient 
public void getDocument() { 
    documentDAO = new DocumentDAO(); 
    Optional<document> doc = documentDAO.read(this.ID); 
    if(doc.isPresent()) {   
     document d = doc.get();   
     this.title = d.title; 
     this.subtitle = d.subtitle; 
    } 
} 

그리고 지금은 잘 작동, 그것은 빈을 업데이트합니다. 모든 멤버 변수를 복사하는 것은 다소 엉터리입니다. 아마도 더 좋은 방법 일 것입니다.

관련 문제