2012-05-17 42 views
0

我希望能够从我的数据库中删除用户。界面有如下代码,但action方法永远不会被调用。我错过了什么?删除richFaces数据上的链接表

 <h:form id="formAdministracionUsuarios"> 
      <br/> 
      <rich:panel style="width: 800px"> 
       <f:facet name="header"> 
        <h:outputText value="Administración de usuarios"/> 
       </f:facet> 

       <rich:dataScroller for="usersTable" fastControls="hide" 
            boundaryControls="hide" /> 
       <h:panelGroup/> 
       <rich:dataTable id="usersTable" rows="10" var="user" 
           value="#{administrationBean.tablaUsuarios}"> 
        <f:facet name="header"> 
         <rich:columnGroup> 
          <rich:column> 
           <h:outputText value="Nombre"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Usuario"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Dependencia"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Email"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Tipo usuario"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Tipo dependencia"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Fecha límite"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Eliminar"/> 
          </rich:column> 
         </rich:columnGroup> 
        </f:facet> 
        <rich:column> 
         <h:outputText value="#{user.nombre}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.usuario}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.dependencia}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.correo}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.tipoUsuario}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.tipoDependencia}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.fechaLimiteCarga}"/> 
        </rich:column> 
        <rich:column> 
         <a4j:commandLink value="Eliminar" execute="@form" 
             action="#{administrationBean.doEliminarUsuario(user.usuario)}"/> 
        </rich:column> 
       </rich:dataTable> 
       <a4j:outputPanel> 
        <br/><br/> 
        <fieldset>         
         <legend>Datos del usuario</legend> 
         <h:panelGrid id="camposUsuario" columns="2"> 
          <h:outputLabel value="Nombre" for="queryNombre"/> 
          <h:outputLabel value="Usuario" for="queryUsuario"/> 
          <h:inputText id="queryNombre" required="true" 
             requiredMessage="Introduzca el nombre." immediate="true" 
             value="#{administrationBean.queryNombre}"> 
           <f:ajax event="keypress" 
             listener="#{administrationBean.doClearMessages}" 
             render="datosUsuario"/> 
          </h:inputText> 
          <h:inputText id="queryUsuario" required="true" 
             requiredMessage="Introduzca el nombre de usuario." 
             value="#{administrationBean.queryUsuario}"> 
          </h:inputText>         
          <rich:message ajaxRendered="true" for="queryNombre"/> 
          <rich:message ajaxRendered="true" for="queryUsuario"/> 

          <h:outputLabel value="Contraseña:" for="queryContrasena"/> 
          <h:outputLabel value="Dependencia:" for="queryDependencia"/> 
          <h:inputSecret id="queryContrasena" required="true" 
              requiredMessage="Introduzca la contraseña." 
              value="#{administrationBean.queryContrasena}"/> 
          <rich:select id="queryDependencia" required="true" 
             requiredMessage="Seleccione la dependencia." 
             defaultLabel="Dependencia..." 
             value="#{administrationBean.queryDependencia}"> 
           <f:selectItems value="#{administrationBean.selectDependencia}"/> 
          </rich:select> 
          <rich:message ajaxRendered="true" for="queryContrasena"/> 
          <rich:message ajaxRendered="true" for="queryDependencia"/>         

          <h:outputLabel value="Correo" for="queryCorreo"/> 
          <h:outputLabel value="Fecha límite:" for="queryFechaLimite"/> 
          <h:inputText id="queryCorreo" required="true" 
             requiredMessage="Introduzca el correo." 
             value="#{administrationBean.queryCorreo}"/> 
          <rich:calendar id="queryFechaLimite" datePattern="dd/MM/yyyy" 
              value="#{administrationBean.queryFechaLimite}"/> 
          <rich:message ajaxRendered="true" for="queryCorreo"/> 

         </h:panelGrid> 
         <h:panelGrid columns="3"> 
          <a4j:commandButton value="Agregar" execute="@form" 
               render="datosUsuario usersTable camposUsuario" 
               action="#{administrationBean.doRegistrarUsuario}"/> 
         </h:panelGrid> 
         <a4j:outputPanel id="datosUsuario" style="font-size: 14px; color: #D17100"> 
          <h:outputText rendered="#{administrationBean.alreadyRegistered}" 
              value="Usuario ya existe !"/> 
          <h:outputText rendered="#{administrationBean.registrationComplete}" 
              value="Usuario registrado !"/> 
         </a4j:outputPanel> 
        </fieldset> 
       </a4j:outputPanel> 
      </rich:panel> 

      <br/> 
     </h:form> 

UPDATE 后的完整形式的代码。

+0

您是否收到任何错误?你的表格是表格的一部分,我认为你需要提交页面以执行任何bean动作 –

+0

nope,我根本没有得到任何错误。我实际上尝试过使用'actionListener'和'action',但没有一个会触发删除方法。表格是表格的一部分。 – BRabbit27

+1

尝试更改链接提交表单,检查出http://stackoverflow.com/questions/3701908/html-making-a-link-submit-in-form和http://stackoverflow.com/questions/313478/如何最好地使链接提交表格 –

回答

1

我找到了。 整个表格包括dataTable材料和新用户材料的注册,即inputFields

发生了什么事情是,当调用h:commandLink中的方法时,由于inputFields中的required属性设置为true,因此未触发操作。

我所做的是两种形式我的东西,第一种形式dataTable相关的东西,第二种形式InputFields东西

随着该分开我避免inputFields所需的属性等等action方法在commandLink现在被称为。

下面是它看起来像现在:

  <h:form id="formUsuariosRegistrados"> 
       <rich:dataScroller for="usersTable" fastControls="hide" 
            boundaryControls="hide" /> 
       <rich:dataTable id="usersTable" rows="10" var="user" 
           value="#{administrationBean.tablaUsuarios}"> 
        <f:facet name="header"> 
         <rich:columnGroup> 
          <rich:column> 
           <h:outputText value="Nombre"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Usuario"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Dependencia"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Email"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Tipo usuario"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Tipo dependencia"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value="Fecha límite"/> 
          </rich:column> 
          <rich:column> 
           <h:outputText value=""/> 
          </rich:column> 
         </rich:columnGroup> 
        </f:facet> 
        <rich:column> 
         <h:outputText value="#{user.nombre}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.usuario}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.dependencia}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.correo}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.tipoUsuario}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.tipoDependencia}"/> 
        </rich:column> 
        <rich:column> 
         <h:outputText value="#{user.fechaLimiteCarga}"/> 
        </rich:column> 
        <rich:column> 
         <a4j:commandLink value="Eliminar" 
             render="@form :formFechaLimite :formModificarContrasena" 
             actionListener="#{administrationBean.doEliminarUsuario(user.usuario)}"/> 
        </rich:column> 
       </rich:dataTable> 
      </h:form> 

      <br/> 

       <h:form id="formRegistroUsuarios"> 
        <a4j:outputPanel> 
         <br/><br/> 
         <fieldset style="width: 350px" > 
          <legend>Datos del usuario</legend> 
          <h:panelGrid id="camposUsuario" columns="2"> 
           <h:outputLabel value="Nombre" for="queryNombre"/> 
           <h:outputLabel value="Usuario" for="queryUsuario"/> 
           <h:inputText id="queryNombre" required="true" 
              requiredMessage="Introduzca el nombre." immediate="true" 
              value="#{administrationBean.queryNombre}"> 
            <f:ajax event="focus" 
              listener="#{administrationBean.doClearMessages}" 
              render="registroCompletado"/> 
           </h:inputText> 
           <h:inputText id="queryUsuario" required="true" 
              requiredMessage="Introduzca el nombre de usuario." 
              value="#{administrationBean.queryUsuario}"> 
           </h:inputText>         
           <rich:message ajaxRendered="true" for="queryNombre"/> 
           <rich:message ajaxRendered="true" for="queryUsuario"/> 

           <h:outputLabel value="Contraseña:" for="queryContrasena"/> 
           <h:outputLabel value="Dependencia:" for="queryDependencia"/> 
           <h:inputSecret id="queryContrasena" required="true" 
               requiredMessage="Introduzca la contraseña." 
               value="#{administrationBean.queryContrasena}"/> 
           <rich:select id="queryDependencia" required="true" 
              requiredMessage="Seleccione la dependencia." 
              defaultLabel="Dependencia..." 
              value="#{administrationBean.queryDependencia}"> 
            <f:selectItems value="#{administrationBean.selectDependencia}"/> 
           </rich:select> 
           <rich:message ajaxRendered="true" for="queryContrasena"/> 
           <rich:message ajaxRendered="true" for="queryDependencia"/>         

           <h:outputLabel value="Correo" for="queryCorreo"/> 
           <h:outputLabel value="Fecha límite:" for="queryFechaLimite"/> 
           <h:inputText id="queryCorreo" required="true" 
              requiredMessage="Introduzca el correo." 
              value="#{administrationBean.queryCorreo}"/> 
           <rich:calendar id="queryFechaLimite" datePattern="dd/MM/yyyy" 
               value="#{administrationBean.queryFechaLimite}"/> 
           <rich:message ajaxRendered="true" for="queryCorreo"/> 

          </h:panelGrid> 
          <h:panelGrid columns="3"> 
           <a4j:commandButton value="Agregar" execute="@form" 
                render="registroCompletado :formUsuariosRegistrados camposUsuario :formFechaLimite :formModificarContrasena" 
                action="#{administrationBean.doRegistrarUsuario}"/> 
          </h:panelGrid> 
          <a4j:outputPanel id="registroCompletado" style="font-size: 14px; color: #D17100"> 
           <h:outputText rendered="#{administrationBean.alreadyRegistered}" 
               value="Usuario ya existe !"/> 
           <h:outputText rendered="#{administrationBean.registrationComplete}" 
               value="Usuario registrado !"/> 
          </a4j:outputPanel> 
         </fieldset> 
        </a4j:outputPanel> 
       </h:form> 
0

如果你只想从表中删除一个用户,那么你必须使用selection从那里选择一个用户。
那么在这种情况下 -
设定selection属性表为 -

selection = "#{bean.selectionTableState}" 

和豆声明为

//import for Selection 
private Selection selectionTableState; 

,然后在action方法使用此选项来获得当前用户。

//suppose ClassA is an object class for representing all users in the table, 
//and make sure your **tablaUsuarios** is of that ClassA type. 
//so that u can catch one by selection 
ClassA classA = this.tablaUsuarios.get(Integer.parseInt(this.selectionTableState.getKeys().next().toString())); 

CLASSA现在在它的选择的用户。
你只需发送一个像userID这样的用户的主要价值到您的DAO通过使用sql查询删除用户。
我相信它会帮助你......