-1

i want select a user and edit it in pop-up page.

   <h:form>
        <h:selectOneMenu id="friendselected" value="#{userBean.selecteduser}">
            <f:selectItems value="#{userBean.users}" />
        </h:selectOneMenu>
        <h:commandButton value="Edit User" action="#{userBean.edituser()}" onclick="#{userBean.JSPopup()}" />
    </h:form>

pop-up code

public String JSPopup() {
    return "javascript:void window.open(' UserEdit.xhtml ',' name ','width=700,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=1,left=0,top=0');return false;";
}

First i will select user and set it's id to selecteduser. After in pop-up page i see it's informatin in and edit.

public void edituser()
{
    initializeJdbc();

    String aSQL="select * from users where UserID="+selecteduser;
    Statement st = null;
    ResultSet rs = null;

    try {
        st = (Statement) connect.createStatement();
        rs = st.executeQuery(aSQL);

        if(rs.next()) {
            fullname=rs.getString("FullName");
            username=rs.getString("UserName");
            password=rs.getString("Password");
            gender=rs.getString("Gender").charAt(0);
            BirthDate=rs.getString("BirthDate");
            Tel=rs.getString("Tel");
            Email=rs.getString("Email");
            Address=rs.getString("Address");
        }

    } catch (Exception ex) {

    }
}

1 Answers1

0

The return false; in your userBean.JSPopup() means that you the default event should not be started, so your action is never called. Remove it and it should be fine.

Another hint, not causing problems for you at the moment, but worth noting. The onclick is a value attribute, so when you place a method expression within, it will not call the method bean onclick, rather it will call it immediately when page is rendered (simply set a debug in your JSPopup method, to see this). If I were you, I would replace the method expression with the js code e.g.

onclick="javascript:void window.open(' UserEdit.xhtml ',' name ','width=700,height=500,toolbar=0,menubar=0,location=0,status=0,scrollbars=0,resizable=1,left=0,top=0');"

or create a function and call it from onclick. At present your not getting any issue, as the method is returning js code only, but in future, if you add additional logic to the method, you might get unexpected results.

Master Slave
  • 24,735
  • 4
  • 53
  • 54