2011-05-19 10 views
8

Tengo una clase de acción con 4 métodos de acción. Los cuatro métodos de acción de acción usan un resultado json.Struts2 Acción que se llama dos veces si el tipo de resultado es json

A través de instrucciones de registro y depuración, he verificado que si invoco el método de acción 1, también se invocan el método de acción 2 y 3. Pero no 4. Finalmente, se llama de nuevo al método de acción 1 y se genera el resultado json

Si cambio el tipo de resultado del método de acción 1 al asignador predeterminado con una ubicación jsp, solo se llama al método de acción 1. (este es el comportamiento que quiero con el resultado json) Espero que tenga sentido.

¿Alguien tiene alguna idea? Se pidió a este pregunta aquí https://stackoverflow.com/questions/3767698/struts2-if-result-type-json-and-method-defined-then-all-methods-get-invoked

Pero no hubo respuesta. Por favor, hágamelo saber si necesita más información.

@ResultPath("/WEB-INF/jsp/dta/") 
public class GroupEntityAction extends BaseAction { 
    /** 
    * 
    */ 
    private static final long serialVersionUID = 6750675222824235086L; 
    private static Logger log = Logger.getLogger(GroupEntityAction.class); 

    private List<EntityBusiness> theUnusedEntityBusinessList; 
    private String assignedEntities[]; 
    private long groupId; 
    private long businessId; 
    private String parentMe; 
    private long rptYear; 
    private String ssoId; 
    private String isSubmitted; 

    private String delimGoLiveEmails; 
    private List<String> theEmailList; 

    @Action(value = "ajaxGetAvailableEntityList", 
      results = { @Result(name = "success", type = "json") } 
      , 
      interceptorRefs = { @InterceptorRef("dtaStack"), 
        @InterceptorRef(value = "dtaStack", params = { "appInterceptor.allowedRoles", "ADMIN" }) } 
      ) 
      public String getEntityListsByBusiness() throws Exception { 

     if (rptYear == 0) { 
      return SUCCESS; 
     } 

     LookupService theSvc = new LookupService(); 

     if (businessId != 0) { 
      setTheUnusedEntityBusinessList(theSvc.getAvailableEntityListBizExceptIds(rptYear, businessId, ssoId, assignedEntities)); 
     } else { 
      setTheUnusedEntityBusinessList(theSvc.getAvailableEntityListParentMeExceptIds(rptYear, parentMe, ssoId, assignedEntities)); 

     } 

     log.debug(theUnusedEntityBusinessList.size()); 

     return SUCCESS; 
    } 

    @Action(value = "ajaxToggleGroupBusinessSubmitted", 
      results = { @Result(name = "success", type = "json") } 
      , 
      interceptorRefs = { @InterceptorRef("dtaStack") } 
      ) 
      public String toggleGroupBusinessReview() { 

     try { 
      new ProformaService().toggleIsSubmitted(getCurrentUser().getSsoId(), groupId, rptYear, businessId); 
     } catch (SQLException e) { 
      log.error(e.getMessage()); 
      return ERROR; 
     } 
     return SUCCESS; 
    } 

    @Action(value = "ajaxGetGoLiveEmailList", 
      results = { @Result(type = "json") } 
      , 
      interceptorRefs = { @InterceptorRef("dtaStack"), 
        @InterceptorRef(value = "dtaStack", params = { "appInterceptor.allowedRoles", "ADMIN" }) } 
      ) 
      public String getGoLiveEmailList() { 

     try { 
      List<TaxUser> theUserList = new SecurityService().getAll(); 

      List<String> theEmailList = new ArrayList<String>(); 
      for (TaxUser theUser : theUserList) { 

       if ((!theUser.getRoles().contains("ADMIN")) && (theUser.getIsActive().equalsIgnoreCase("Y"))) { 
        if (!theEmailList.contains(theUser.getEmail())) { 
         theEmailList.add(theUser.getEmail()); 
        } 
       } 
      } 

      setDelimGoLiveEmails(StringUtils.join(theEmailList.toArray(), "|")); 
      setTheEmailList(theEmailList); 
     } catch (SQLException e) { 
      log.error(e.getMessage()); 
      return ERROR; 
     } 

     return SUCCESS; 
    } 

    @Action(value = "ajaxGetChaserEmailList", 
      results = { @Result(name = "success", type = "json") } 
      , 
      interceptorRefs = { @InterceptorRef("dtaStack"), 
        @InterceptorRef(value = "dtaStack", params = { "appInterceptor.allowedRoles", "ADMIN" }) } 
      ) 
      public String getChaserEmailList() { 

     try { 

      List<String> theEmailList = new LookupService().getChaserEmailList(); 

      setDelimGoLiveEmails(StringUtils.join(theEmailList.toArray(), "|")); 
      setTheEmailList(theEmailList); 

     } catch (SQLException e) { 
      log.error(e.getMessage()); 
      return ERROR; 
     } 
     return SUCCESS; 
    } 

    public void setTheUnusedEntityBusinessList(
      List<EntityBusiness> theUnusedEntityBusinessList) { 
     this.theUnusedEntityBusinessList = theUnusedEntityBusinessList; 
    } 

    public List<EntityBusiness> getTheUnusedEntityBusinessList() { 
     return theUnusedEntityBusinessList; 
    } 

    public void setAssignedEntities(String assignedEntities[]) { 
     this.assignedEntities = assignedEntities; 
    } 

    public String[] getAssignedEntities() { 
     return assignedEntities; 
    } 

    public void setGroupId(long groupId) { 
     this.groupId = groupId; 
    } 

    public long getGroupId() { 
     return groupId; 
    } 

    public void setBusinessId(long businessId) { 
     this.businessId = businessId; 
    } 

    public long getBusinessId() { 
     return businessId; 
    } 

    public void setParentMe(String parentMe) { 
     this.parentMe = parentMe; 
    } 

    public String getParentMe() { 
     return parentMe; 
    } 

    public void setRptYear(long rptYear) { 
     this.rptYear = rptYear; 
    } 

    public long getRptYear() { 
     return rptYear; 
    } 

    public void setSsoId(String ssoId) { 
     this.ssoId = ssoId; 
    } 

    public String getSsoId() { 
     return ssoId; 
    } 

    public void setIsSubmitted(String isSubmitted) { 
     this.isSubmitted = isSubmitted; 
    } 

    public String getIsSubmitted() { 
     return isSubmitted; 
    } 

    public void setDelimGoLiveEmails(String delimGoLiveEmails) { 
     this.delimGoLiveEmails = delimGoLiveEmails; 
    } 

    public String getDelimGoLiveEmails() { 
     return delimGoLiveEmails; 
    } 

    public void setTheEmailList(List<String> theEmailList) { 
     this.theEmailList = theEmailList; 
    } 

    public List<String> getTheEmailList() { 
     return theEmailList; 
    } 
} 

En esta clase de acción, que intenta llamar ajaxGetGoLiveEmailList, y lo que consigo es ajaxGetGoLiveEmailList llamado primero, y luego ajaxGetChaserEmailList, y luego ajaxGetAvailableEntityList, y luego ajaxGetGoLiveEmailList es llamado de nuevo. ajaxToggleGroupBusinessSubmitted se omite.

Si cambio la anotación resultado de ajaxGetGoLiveEmailList a

results={@Result(location="something.jsp") 

, solamente ajaxGetGoLiveEmailList ser llamado.

Cuando miro el navegador de configuración, todos los mapas de acciones están configurados correctamente, apuntando a las llamadas al método correcto.

+0

Publique su código de acción o un caso de prueba que muestre el problema. –

Respuesta

17

El complemento JSON puede estar llamando a todos sus métodos que comienzan con "get" en un intento de serializarlos para su salida. Intenta cambiar el nombre de tus métodos a otra cosa.

+0

Eso fue todo, buena decisión. – Sumit

+0

Muchas gracias :) – Arun

+1

Tengo el mismo problema. Cambie el nombre de la función a "loadxxx". Ahora funciona. (: – Emerald214

Cuestiones relacionadas