2012-09-07 4 views
0

일부 코드에 몇 가지 문제가 있습니다. 이제 개인 정보를 수정/삭제하려고 시도했지만 잘못된 값을 입력하여 수정/삭제를 시도합니다. 새 창을 계속 열어 둡니다. 나는 내가 그 값을 잘못 입력하면 그 코드를 수정하는 방법을 모른다. 창을 띄우지 않을 것이다. 다른 질문이 있습니다. 유효한 값을 입력하면 값을 팝업 창에 전달할 수 없습니다. 이름을 입력하면 이름이 바뀌고 값은 팝업 창에 전달되지 않습니다. 어떻게 다시 작성할 수 있습니까? 모두 감사합니다!JSF2는 새 팝업 창에 값을 전달하지 않습니다.

HTML

<h:panelGrid columns="3" cellspacing="20"> 
    <h:outputLabel for="name" value="Modify Name"/> <p:inputText value="#{modify.enName}"/> 
    <h:commandButton value="Modify System" style="height:35px" onclick="window.open('#{modify.domodify()}','modify', 
                 'width=500,height=400,status=yes,resizable=yes,scrollbars=yes') ; return false;"/> 
</h:panelGrid> 

자바 코드

public String domodify() { 
    try { 
     EntityManagerFactory emf = Persistence.createEntityManagerFactory("com.mycompany_SuneCoolingSystem_war_1.0-SNAPSHOTPU"); 
     EmployeeJpaController jpaController = new EmployeeJpaController(null, emf); 
     EntityManager e = jpaController.getEntityManager(); 
     Query q = e.createNamedQuery("Employee.findByEnName"); 
     q.setParameter("enName", getEnName()); 
     System.out.println(getEnName()); 
     List resultList = q.getResultList(); 
     Employee result = (Employee) resultList.get(0); 

     id = result.getId(); 
     name = result.getName(); 
     idNumber = result.getIdNumber(); 
     constellation = result.getConstellation(); 
     email = result.getEmail(); 
     enName = result.getEnName(); 

     rego="CRUD/Modify.xhtml"; 
    } catch (Exception ex) { 
     FacesContext context = FacesContext.getCurrentInstance(); 
     context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_WARN, "No Man", "")); 
     rego = "index.xhtml"; 
    } 
    return rego; 
} 

답변

0
onclick="window.open('#{modify.domodify()}','modify', 'width=500,height=400,status=yes,resizable=yes,scrollbars=yes') 

이 코드는 클릭 할 때 는, 새로운 창을 열고 반환 무엇 URL 확인하는 작업을 수행하는 것을 의미한다. 로직이 실행되기 전에 창이 열립니다.

수정하려면 f:ajax (또는 원할 경우 구성 요소 라이브러리와 동등 함)을 사용하여 ajax 호출을 수행하고 onevent을 사용하여 ajax 호출이 끝나고 예상 값을 반환 할 때 올바른 javascript를 시작해야합니다.

onevent을 처리하는 예는 JSF 2: How show different ajax status in same input?을 참조하십시오.

관련 문제