1

当我单击触发 editUser(User) 方法的命令按钮或触发支持 bean 中的 editClient(User) 方法的命令按钮时,不再调用这些方法。它以前工作过,但现在什么都没有被调用。页面被重新加载。

这里有什么问题???

这是我的看法:

<p:accordionPanel activeIndex="#{userManagement.activeOverviewTab}" id="overview" rendered="#{loginControl.isAllowedForClientUserCreation()}">
<p:tab title="#{text.tabClients}" rendered="#{loginControl.isAllowedForUserManagement()}">
    <h:form id="clientForm">
    <p:dataTable value="#{userManagement.clientUsers}" var="clientUser" paginator="true" rows="5" id="clientTable">
        <p:column><f:facet name="header"><h:outputText value="#{text.colClientName}"/></f:facet><h:outputText value="#{clientUser.client.clientName}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colClientEmail}"/></f:facet><h:outputText value="#{clientUser.client.email}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colClientJobLayout}"/></f:facet><h:outputText value="#{clientUser.client.reportLayout}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersLogin}"/></f:facet><h:outputText value="#{clientUser.login}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersPassword}"/></f:facet><h:outputText value="#{clientUser.password}"/></p:column>            
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersAction}"/></f:facet>
            <p:commandLink onclick="clientDlg.show()">
                <h:graphicImage name="icons/pencil.png" title="#{text.editClientUser}" />
            </p:commandLink>
                <p:dialog header="#{text.editClientUser}" widgetVar="clientDlg" modal="true" resizable="false" width="350" height="190" showEffect="slide" hideEffect="explode">
                <h:form id="customerEditForm">
                <p:growl id="clientUserMessages"/>
                <br/>
                <p:panelGrid columns="2" columnsClasses="odd, even">
                    <h:outputLabel value="#{text.colClientName}"/><h:inputText value="#{clientUser.client.clientName}" />
                    <h:outputLabel value="#{text.colClientEmail}"/><h:inputText value="#{clientUser.client.email}" />
                    <h:outputLabel value="#{text.colClientJobLayout}"/><h:inputText value="#{clientUser.client.reportLayout}" />
                    <h:outputLabel value="#{text.colUsersLogin}"/><h:inputText value="#{clientUser.login}" />
                    <h:outputLabel value="#{text.colUsersPassword}"/><h:inputText value="#{clientUser.password}" />
                </p:panelGrid>
                <br/>
                    <p:commandButton value="#{text.applyButton}" type="button" action="#{userManagement.editClient(clientUser)}" onclick="clientDlg.hide()"/>
                    <p:commandButton value="#{text.abortButton}" type="button" onclick="clientDlg.hide()" />                    
                </h:form>
            </p:dialog>

        </p:column>             
    </p:dataTable>
    </h:form>
</p:tab>

<p:tab title="#{text.tabPrinter}" rendered="#{loginControl.isAllowedForClientUserCreation()}">
    <h:form id="userForm">
    <p:dataTable value="#{userManagement.printUsers}" var="printUser" paginator="true" rows="5" id="userTable">
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersUsername}"/></f:facet><h:outputText value="#{printUser.name}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersLogin}"/></f:facet><h:outputText value="#{printUser.login}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersPassword}"/></f:facet><h:outputText value="#{printUser.password}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colsUsersAssignedClient}"/></f:facet><h:outputText value="#{printUser.client.clientName}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersLocked}"/></f:facet><h:graphicImage name="icons/lock.png" rendered="#{printUser.locked == 1}"/></p:column>
        <p:column><f:facet name="header"><h:outputText value="#{text.colUsersAction}"/></f:facet>
            <p:commandLink onclick="dlg.show()">
                <h:graphicImage name="icons/pencil.png" title="Drucker bearbeiten" />
            </p:commandLink>
                <p:dialog header="#{text.editPrintUser}" widgetVar="dlg" modal="true" resizable="false" width="350" height="190" showEffect="slide" hideEffect="explode">
                <h:form id="printerEditForm">
                <p:growl showDetail="true" id="printerMessages" />  
                <br />
                    <p:panelGrid columns="2" columnClasses="odd, even">
                        <h:outputLabel value="#{text.colUsersLogin}"/><h:inputText value="#{printUser.login}" />    
                        <h:outputLabel value="#{text.colUsersPassword}"/><h:inputText value="#{printUser.password}" />  
                        <h:outputLabel value="#{text.colsUsersAssignedClient}"/>
                        <h:selectOneMenu value="#{printUser.client}" converter="de.flexicon.webtools.entity.Client">
                            <f:selectItems value="#{userManagement.clients}" />
                        </h:selectOneMenu>                          
                        <h:outputLabel value="#{text.colUsersLocked}"/><h:inputText value="#{printUser.locked}" />  
                        <h:outputLabel value="#{text.colClientEmail}"/><h:inputText value="#{printUser.email}" />   
                    </p:panelGrid>  
                    <br />
                        <p:commandButton value="#{text.applyButton}" type="button" action="#{userManagement.editUser(printUser)}" onclick="dlg.hide()"/>
                        <p:commandButton value="#{text.abortButton}" type="button" onclick="dlg.hide()" />
                    </h:form>
                </p:dialog>

        </p:column>
    </p:dataTable>
    </h:form>
</p:tab>
</p:accordionPanel>

这是我的支持bean:

package de.flexicon.webtools.util;

import java.io.Serializable;
import java.util.List;
import java.util.ResourceBundle;    
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import org.apache.log4j.Logger;
import de.flexicon.webtools.entity.Client;
import de.flexicon.webtools.entity.User;
import de.flexicon.webtools.entity.dao.ClientDAO;
import de.flexicon.webtools.entity.dao.RoleDAO;
import de.flexicon.webtools.entity.dao.UserDAO;
import de.flexicon.webtools.entity.report.constants.UserRole;

@SuppressWarnings("serial")
@ManagedBean(name="userManagement")
@ViewScoped
public class UserManagement implements Serializable
{

private User newUser;
private Client selectedClient;

private List<User> clientUsers;
private List<User> printUsers;

private List<Client> clients;

private int activeOverviewTab = -1;

public UserManagement(){

}

public User getNewUser() {
    if(newUser==null){
        newUser = new User();
    }
    return newUser;
}

public void setNewUser(User newUser) {
    this.newUser = newUser;
}



/**
 * Legt einen neuen Drucker mit Kundenzuordnung an!
 */
    public void createNewTechUser(ActionEvent e){

    FacesContext ctx = FacesContext.getCurrentInstance();
    ResourceBundle bundle = ctx.getApplication().getResourceBundle(ctx, "text");

    try
    {
        UserDAO userDAO = new UserDAO();
        User user = new User();
        user.setEmail(newUser.getEmail());
        user.setLocked(0);
        user.setLogin(newUser.getLogin());
        user.setName(newUser.getName());
        user.setPassword(newUser.getPassword());
        userDAO.persist(user);

        RoleDAO roleDAO = new RoleDAO();
        user.getRoles().add(roleDAO.findById(UserRole.DRUCKER));

        user.setClient(selectedClient);
        userDAO.update(user);


        ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, bundle.getString("msgNewTechUserCreated"), bundle.getString("msgNewTechUserCreated")));
    }
    catch(Exception ex){
        Logger.getRootLogger().error(bundle.getString("logErrorCreatingUser") + ex);
        ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, bundle.getString("logErrorCreatingUser") + ": " + ex.getMessage(), bundle.getString("logErrorCreatingUser") + ": " + ex.getMessage()));
    }
    finally{
        setActiveOverviewTab(1);
    }
}

public void createNewClient(ActionEvent e)
{
    FacesContext ctx = FacesContext.getCurrentInstance();
    ResourceBundle bundle = ctx.getApplication().getResourceBundle(ctx, "text");
    try
    {
        UserDAO userDAO = new UserDAO();
        User user = new User();
        user.setEmail(newUser.getEmail());
        user.setLocked(0);
        user.setLogin(newUser.getLogin());
        user.setName(newUser.getName());
        user.setPassword(newUser.getPassword());
        userDAO.persist(user);

        RoleDAO roleDAO = new RoleDAO();
        user.getRoles().add(roleDAO.findById(UserRole.KUNDE));

        ClientDAO clientDAO = new ClientDAO();
        Client client = new Client();
         client.setClientName(user.getName());
         client.setEmail(user.getEmail());
        clientDAO.persist(client);

        user.setClient(client);
        userDAO.update(user);


        ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, bundle.getString("msgNewTechUserCreated"), bundle.getString("msgNewTechUserCreated")));
    }
    catch(Exception ex){
        Logger.getRootLogger().error(bundle.getString("logErrorCreatingUser") + ex);
        ctx.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, bundle.getString("logErrorCreatingUser") + ": " + ex.getMessage(), bundle.getString("logErrorCreatingUser") + ": " + ex.getMessage()));
    }
    finally{
        setActiveOverviewTab(0);
    }
}


public Client getSelectedClient() {
    return selectedClient;
}

public void setSelectedClient(Client selectedClient) {
    this.selectedClient = selectedClient;
}


public List<User> getClientUsers() {
    if(clientUsers==null){

        UserDAO userDAO = new UserDAO();
        clientUsers= userDAO.getUsersByRole(UserRole.KUNDE);
    }
    return clientUsers;
}

public void setClientUsers(List<User> clientsUsers) {
    this.clientUsers = clientsUsers;
}

public void setPrintUsers(List<User> printUsers) {
    this.printUsers = printUsers;
}

public List<User> getPrintUsers() {
    if(printUsers==null){
        UserDAO userDAO = new UserDAO();
        printUsers = userDAO.getUsersByRole(UserRole.DRUCKER);
    }
    return printUsers;
}

public List<Client> getClients() {
    if(clients==null){
        ClientDAO clientDAO = new ClientDAO();
        setClients(clientDAO.getClientsOrderedByName());
    }
    return clients;
}

public void setClients(List<Client> clients) {
    this.clients = clients;
}

public void editUser(User user){
    UserDAO userDAO = new UserDAO();
    userDAO.update(user);
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "text");
    context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, bundle.getString("printerUpdated"), bundle.getString("descUpdatedPrintUser")));
    setActiveOverviewTab(1);
}

public void editClient(User user){
    UserDAO userDAO = new UserDAO();
    userDAO.update(user);
    FacesContext context = FacesContext.getCurrentInstance();
    ResourceBundle bundle = context.getApplication().getResourceBundle(context, "text");
    context.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, bundle.getString("printerUpdated"), bundle.getString("descUpdatedPrintUser")));
    setActiveOverviewTab(0);
}

public void setActiveOverviewTab(int tabIdx){
    this.activeOverviewTab = tabIdx;
}

public int getActiveOverviewTab(){
    return this.activeOverviewTab;
}

}

4

1 回答 1

5

您正在嵌套表单。有关更多详细信息,请参阅h:commandLink / h:commandButton 没有被调用

于 2012-08-07T03:14:59.613 回答