Setar valores em uma array de String dentro de um formbean

2 respostas
S

Olá pessoal,

Gostaria de saber se alguem poderia me ajudar.

Eu tenho um array de string no meu formbean

public class MatrizDecisaoManualForm {

	private String[] behaviorArray;
	
public String[] getBehaviorArray() {
		return behaviorArray;
	}

	public void setBehaviorArray(String[] behaviorArray) {
		this.behaviorArray = behaviorArray;
	}
}
E estou tentando setar para ele  estes seguintes valores

MatrizDecisaoManualForm matriz = new  MatrizDecisaoManualForm ();

matriz .setBehaviorArray({“2”, “3”});

Então tenho a seguinte mensagem de erro

Multiple markers at this line
- Syntax error, insert “AssignmentOperator Expression” to complete Assignment
- Syntax error, insert “AssignmentOperator Expression” to complete Assignment
- voMatrizDecisaoManual.setBehaviorArray cannot be resolved or is not a field
- Syntax error, insert “;” to complete BlockStatements
- The left-hand side of an assignment must be a variable
- Syntax error, insert “;” to complete BlockStatements

Será que alguem poderia me passar a solução para que eu conseguisse setar vaores para ele.

2 Respostas

felipe_gdr

Tenta assim:

matriz .setBehaviorArray(new String[]{"2", "3"});

falouuuuu

ViniGodoy

Uma forma mais compacta pode ser:

public void setBehaviorArray(String ... behaviorArray) { this.behaviorArray = behaviorArray; }

O que te permite fazer:

matriz.setBehaviorArray("2", "3");
Criado 20 de novembro de 2009
Ultima resposta 20 de nov. de 2009
Respostas 2
Participantes 3