Display a message with an array

1

I have a table that is full of information, before sending a request select the rows I want to send, when I have finished selecting the rows I click on the send button (it is sent correctly).

What I want is that when the rows are sent out a single message where I indicate the documents that have been sent, I have been trying with the following code but I get a separate sending message and I do not get a single message tell me the documents that have been sent.

public static String[] documentos;

protected void btnEnviarActionPerformed(ActionEvent e) {
        int[] selectedRow = tbDocSolicitud.getSelectedRows();
        int i = tbDocSolicitud.getSelectedRow();
        if (i == -1){
            JOptionPane.showMessageDialog(null,"Seleccione los documentos que desea solicitar"); 
        }
        else{
            for(int t : selectedRow){
                String codArchivo = (String) tbDocSolicitud.getValueAt(t, 0);
                String codCentroCosto = (String) tbDocSolicitud.getValueAt(t, 1);
                String tipoArchivo = (String) tbDocSolicitud.getValueAt(t, 4);
                String doc = (String) tbDocSolicitud.getValueAt(t, 6).toString().trim();
                String nivelArchivo = (String) tbDocSolicitud.getValueAt(t, 7);
                String lote = (String) tbDocSolicitud.getValueAt(t, 9);
                String fila = (String) tbDocSolicitud.getValueAt(t, 10);
                String usuarioSolicita = Constante.idUsuario;
                Objeto object = (Objeto) cboCentroCostoDestino.getSelectedItem();
                String centroCostoDestino = ((Objeto)object).getCodigo();
                String centroCostoOrigen = Constante.c_ccosto;
                if (centroCostoDestino.equals("0")){
                    JOptionPane.showMessageDialog(null, "Seleccione el Destino del Documento","Alerta",JOptionPane.WARNING_MESSAGE);
                    cboCentroCostoDestino.requestFocus();
                    return;
                }
                else{
                    MovimientoArchivoDTO m = new MovimientoArchivoDTO();
                    m.setC_c_archivo(codArchivo);
                    CentroCostoDTO c = new CentroCostoDTO();
                    c.setC_ccosto(codCentroCosto);
                    m.setC_ccosto(c);
                    m.setC_ccosto_origen(centroCostoOrigen);
                    m.setC_ccosto_destino(centroCostoDestino);
                    m.setC_tipo_doc(tipoArchivo);
                    m.setC_t_doc(doc);
                    m.setC_c_nivel_archivo(nivelArchivo);
                    m.setLote(lote);
                    m.setFila(fila);
                    m.setC_c_usuario_solicita(usuarioSolicita);
                    int estado = x.RegistrarSolicitud_SA(m);
                    if (estado == 1){
                        //JOptionPane.showMessageDialog(null,"Se mandó el Documento:"+" "+doc);
                        documentos = doc.split(" ");
                        String notificacion = "Se mandaron los siguientes documentos:\n";
                        for (String value : documentos) {
                            notificacion = notificacion + "-" + value + "\n";
                            System.out.println(value);
                        }
                        JOptionPane.showMessageDialog(null, new Object[] { notificacion }, "Solicitud Enviada", 1, null);
                    }
                    else
                        mensaje("Error en enviar");
                    }
            }
            ListarDocumentoSA(estado_flg);
        }
    }

These images are the messages that come to me for each document that has been sent, but what I want is that the documents that have been sent appear in a single message.

    
asked by Angelica 17.04.2017 в 22:50
source

1 answer

1
  

UPADTE 3:

Even though it works with UPDATE 2, to adjust to the title you could use:

Arrays.toString(documentos) in

JOptionPane.showMessageDialog(null, new Object[] { Arrays.toString(documentos) }, "Solicitud Enviada", 1, null);

to convert it into a string, but I think it would not work like now among others because the new values are not added.

as you do this documentos = doc.split(" ");

If you want to use this of the Arrays.toString() you would have to work that part.

On the other hand out of curiosity if the type of array is bidimentional for example, you can use Arrays.deepToString

import java.util.Arrays;

public class Test
{
    public static void main(String[] args)
    {
        int[][] ar_bid = new int[2][2];

        ar_bid[0][0] = 1;
        ar_bid[0][1] = 2;
        ar_bid[1][0] = 3;
        ar_bid[1][1] = 4;


        System.out.println(Arrays.deepToString(ar_bid));
        System.out.println(Arrays.toString(ar_bid));
    }
}

Arrays.toString() works fine for one-dimensional arrays, but it does not work well for multidimensional arrays.

the previous thing would have an exit more or less asi

[[1, 2], [3, 4]]
[[I@677327b6, [I@14ae5a5]
  

UPADTE 2:

It shows you several windows I think because it's iterated inside

for(int t : selectedRow){

and if estado == 1

int estado = x.RegistrarSolicitud_SA(m);
    if (estado == 1){

     JOptionPane.showMessageDialog(null, new Object[] { notificacion }, "Solicitud Enviada", 1, null);
    }

Look out of the initial iteration this line JOptionPane.showMessageDialog... comentela or something that is inside the for where the data on documents are iterated, and add something like this:

    //..
    }

    JOptionPane.showMessageDialog(null, new Object[] { sb.toString() }, "Solicitud Enviada", 1, null);
    ListarDocumentoSA(estado_flg); //encima de esta

that part of the code we are using.

  

UPDATE:

Try the following:

    StringBuilder sb = new StringBuilder();
    String notificacion = "Se mandaron los siguientes documentos:\n";
    sb.append(notificacion + "-")

    for (String value : documentos) {
       notificacion = notificacion + "-" + value + "\n";

       //si solo quiere el value
       sb.append(value + "  \n");

       //si quiere tambien el valor de notificacion como tiene arriba
       //elinimar el anterior -> sb.append(value + "  \n"); anterior
       //y usar el siguiente: solo tiene que descomentarlo

       //sb.append(notificacion);
    }

    //System.out.println(sb.toString());
JOptionPane.showMessageDialog(null, new Object[] { sb.toString() }, "Solicitud Enviada", 1, null);
  

ANTIQUE:

I do not understand your question well:

you say: .. I get a message with the first document that was sent, then another message with the other document that was sent and so ...

I imagine you are referring to this part of the code:

for (String value : documentos) {
   notificacion = notificacion + "-" + value + "\n";
   System.out.println(value);
}

I guess what you want to send is in value and what you get is what you want but this line by line for this System.out.println(value);

Then if I understood correctly, you can do it in several ways using:

System.out.print(value);

for (String value : documentos) {
   notificacion = notificacion + "-" + value + "\n";
   System.out.print(value + " ");
}

or in this other way:

String temp_value;

for (String value : documentos) {
   notificacion = notificacion + "-" + value + "\n";

   //usamos += para concatenar el texto
   //pero tengo la duda de si lo que quiere mostar es notificacion o value yo se lo dejo con value porque usted comento que se lo mostraba bien pero por filas, quizas tenga que usar temp_value += value + " "; para dar un espacio.
   temp_value += value; 
}

System.out.println(temp_value);

on the other hand maybe you could use the class StringBuilder

StringBuilder sb = new StringBuilder();

for (String value : documentos) {
   notificacion = notificacion + "-" + value + "\n";

   sb.append(value + " "); 
}

System.out.println(sb.toString());

P.D: was too long for a comment, if not this, you can comment and modify your question by adding an example of the expected output.

    
answered by 17.04.2017 / 23:08
source