0

I got some troubles with some codes. Now I try to modify/delete personal information , but I enter an invalid value try modify/delete , it's still pop a new window . I dont know how to modify those code for i enter an invalid value , it will not pop a window . I have other question . When I enter a valid value , the value cant pass to pop window , like I enter a name to go grab id value , the value cant pass to pop window , how can I reslove it . Thank all !

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 Code

 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;
}

1 Answers1

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

This code means when clicked, open a new window and perform the action to check what URL is returned. The windows is opened before any logic is executed.

You should perform an ajax call to the modify with f:ajax (or your component library equivalent, if you want) and use onevent to launch the correct javascript when the ajax calls ends in success and returning the expected value.

See JSF 2: How show different ajax status in same input? to see an example of dealing with onevent.

Community
  • 1
  • 1
SJuan76
  • 24,532
  • 6
  • 47
  • 87