0 Replies Latest reply on Feb 1, 2016 3:05 AM by scharreflorian

    Use an attribute from a JiveActionSupport class in another JiveActionSupport class

    scharreflorian

      Hello,

       

      I'm developping a Jive plugin but i have a problem which block my developpement, that's why I come here to know if you can help me

       

      I am trying to use an attribute from a class to another class, first of all i'll try to explain to you my differents class:

       

      ShowExternalUsers:

      This class is my class which is use to show my page

       

      public class ShowExternalUsers extends JiveActionSupport {
          /**
           * 
           */
          private static final long serialVersionUID = 1L;
      
          private static ManageUsersDAO muDAO;
          private List<ExternalUser> externalUsers;
      
          public ShowExternalUsers(){
              super();
          }
      
          public String execute() {
              externalUsers = new ArrayList<ExternalUser>();
              externalUsers.addAll(muDAO.getExternalUsersCommunity());
              return SUCCESS;
          }
         
          public List<ExternalUser> getExternalUsers() {
              return externalUsers;
          }
          
          public void setExternalUsers(List<ExternalUser> externalUsers) {
              this.externalUsers = externalUsers;
          }
      
          public static ManageUsersDAO getMuDAO() {
              return muDAO;
          }
      
          public static void setMuDAO(ManageUsersDAO muDAO) {
              ShowExternalUsers.muDAO = muDAO;
          }
      
          
      }
      

       

      ManageUsersDAO:

      This class is my DAO use to request the jive database

      public class ManageUsersDAO extends JiveJdbcDaoSupport{
          
          //Changer le fieldid correspondant au champ de la company, 12 en dev, 13 sur l'uat
          private static String GET_EXTERNAL_USERS_COMMUNITY = "select jusr.userid,jusr.username,jusr.email,jusr.firstname,jusr.lastname,jusr.creationdate,jusr.lastloggedin,jsgm.groupid,jsg.name,jusrown.firstname||' '||jusrown.lastname as proprietaire,jusrown.username as ldap_proprietaire,jup.value as bu_proprietaire "
                                              +"from jiveuser jusr,jivesgroupmember jsgm,jivesgroup jsg ,jiveuser jusrown,jiveuserprofile jup "
                                              +"where jusr.usertype=2 "
                                              +"and jsgm.userid=jusr.userid "
                                              +"and jsg.groupid=jsgm.groupid "
                                              +"and jsg.userid = jusrown.userid "
                                              +"and jup.userid=jsg.userid and jup.fieldid=12;";
          
          
          public List<ExternalUser> getExternalUsersCommunity() {
              
              SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
              List<ExternalUser> externalUsers = null;
              SimpleJdbcTemplate jdbc = getSimpleJdbcTemplate();
              
              externalUsers = jdbc.query(GET_EXTERNAL_USERS_COMMUNITY, new RowMapper<ExternalUser>() {
                  @Override
                  public ExternalUser mapRow(ResultSet rs, int rownumber) throws SQLException {
                      ExternalUser eu = new ExternalUser();
                      
                      eu.setUserid(rs.getString("userid"));
                      eu.setUsername(rs.getString("username"));
                      eu.setEmail(rs.getString("email"));
                      eu.setLastname(rs.getString("lastname"));
                      eu.setFirstname(rs.getString("firstname"));
                       
                      try{
                          eu.setCreateDate(sdf.format(new Date(Long.parseLong(rs.getString("creationdate")))));
                          eu.setLastLoggedIn(sdf.format(new Date(Long.parseLong(rs.getString("lastloggedin")))));
                      }
                      catch(Exception e){
                          System.out.println(e.getMessage());
                      }
                      
                      eu.setGroupid(rs.getString("groupid"));
                      eu.setCommunity(rs.getString("name"));
                      eu.setCommunityOwner(rs.getString("proprietaire"));
                      eu.setLdapOwner(rs.getString("ldap_proprietaire"));
                      eu.setBuOwner(rs.getString("bu_proprietaire"));
                      
                      return eu;
                  }
              });
              return externalUsers;
          }
          
         
      
      }
      

       

      Export.java:

      This class is called when you click on a button Export

      public class Export extends JiveActionSupport {
      
          private static ShowExternalUsers muShow;
          private static final long serialVersionUID = 1L;
          private InputStream inputStream;
           
          public InputStream getInputStream() {
              return inputStream;
          }
      
          public String execute(){
      
              System.out.println("EXPORT");
              try{
                  System.out.println("5 " + muShow.getExternalUsers());        
                  System.out.println("size : "+muShow.getExternalUsers());
              }
              catch(Exception e){
                  System.out.println(e.getMessage());
                  return ERROR;
              }
              System.out.println("4");
              return SUCCESS;
          }
      
          public ShowExternalUsers getMuShow() {
              return muShow;
          }
      
          public void setMuShow(ShowExternalUsers muShow) {
              Export.muShow = muShow;
          }
      
      
      }
      

       

      spring.xml :

      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:util="http://www.springframework.org/schema/util"
             xsi:schemaLocation="
              http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
              http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
             default-autowire="no" default-init-method="init" default-destroy-method="destroy">
      
          <bean class="com.younity.plugin.manageusers.ManageUsersPlugin"/>
      
          <bean id="manageusersDAO" class="com.younity.plugin.manageusers.ManageUsersDAO">
              <property name="dataSource">
                  <util:property-path path="dataSourceFactory.dataSource" />
              </property>
          </bean>
          <bean class="com.younity.plugin.manageusers.admin.ShowExternalUsers" id="mu-showExternalUsers-bean">
                  <property name="muDAO" ref="manageusersDAO" />
          </bean>
          <bean class="com.younity.plugin.manageusers.admin.Export" id="mu-exp-bean">
              <property name="muShow" ref="mu-showExternalUsers-bean" />
              </bean>
      </beans>
      

       

      struts.xml:

      <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
              "http://struts.apache.org/dtds/struts-2.0.dtd">
      <struts>
          <package name="manage-users-plugin-actions" extends="community-default">
          </package>
          
          <package name="manage-users-admin-actions" namespace="/admin" extends="community-admin-actions">
              <action name="mu-show-externalusers" class="com.younity.plugin.manageusers.admin.ShowExternalUsers">
                  <result name="success" type="freemarker">/plugins/manage-users-plugin/resources/templates/mu-show-externalusers.ftl</result>
              </action>
              <action name="mu-export" class="com.younity.plugin.manageusers.admin.Export">
                  <result name="success" type="stream">
                        <param name="contentType">application/octet-stream</param>
                        <param name="inputName">inputStream</param>
                        <param name="contentDisposition">attachment;filename="data.csv"</param>
                        <param name="bufferSize">1024</param>
                  </result>
              </action>
          </package>
      </struts>
      

       

       

      First of all I called the ShowExternalUsers which called the ManageUsersDAO to initiate the attribute externalUsers, then i want to click on the button Export which called the attribute externalUsers from ShowExternalUsers class but the externalUsers attribute is null in the Export class, i need to link this attribute between ShowExternalUsers.java and Export.java

      Any ideas why it's dont works please ?

       

      Thanks,

       

      Florian.