1
0
-1

Hi,

I want to redirect to particular URL using Bean Shell Datalist Action.

My Bean Shell Code is:

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import java.lang.String;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppService;
import org.joget.apps.app.service.AppUtil;
import org.joget.commons.util.LogUtil;

import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.joget.apps.datalist.model.DataListActionResult;


    Connection con = null;
    try {
        // retrieve connection from the default datasource
        DataSource ds = (DataSource)AppUtil.getApplicationContext().getBean("setupDataSource");
        con = ds.getConnection();
        con.setAutoCommit(false);
        
  
        if (!con.isClosed()) {
            DataListActionResult result = new DataListActionResult();
            result.setType(DataListActionResult.TYPE_REDIRECT);
            
            int count = rowKeys.length;     
 
	        // Here Multiple Database Operations      
            con.commit();
            con.close();


            result.setUrl("https://www.google.com/");
            return result;
        }
    } 
    catch (Exception e) {
        con.rollback();         
    } 
    finally {
        if (con != null) {
            con.close();
        }
    }
   


Here, DB operations working perfectly but there is a issue to redirect to URL.

Can anyone tell me Is this is perfect for redirection or I can use another option for redirection.


Thanks!

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      I tried your simplified code to validate if redirection works or not.

      import org.joget.apps.datalist.model.DataListActionResult;
      
      DataListActionResult result = new DataListActionResult();
      result.setType(DataListActionResult.TYPE_REDIRECT);
      
      result.setUrl("https://www.google.com/");
      return result;
       

      redirection happens correctly. there might be something wrong with the logic in your overall code then.

        CommentAdd your comment...