2012-09-07 25 views
0

我有一些代碼的麻煩。現在我嘗試修改/刪除個人信息,但我輸入了一個無效的值嘗試修改/刪除,它仍然彈出一個新窗口。我不知道如何修改這些代碼,因爲我輸入了一個無效的值,它不會彈出一個窗口。 我還有其他問題。當我輸入一個有效值時,值不能傳遞到彈出窗口,就像我輸入一個名稱以獲取id值,該值不能傳遞到彈出窗口,我該如何重新使用它。謝謝大家!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> 

Java代碼的

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推出正確的JavaScript的Ajax調用在成功返回預期值結束。

請參閱JSF 2: How show different ajax status in same input?以查看處理onevent的示例。

相關問題