[quote=nel][quote=djeffersonx]mas o problema não está no getKey pois esta linha está funcionando e montando como deveria, o problema é nesta linha:
.append(String.valueOf(itSrcMap.get(namePk)))
mas mesmo assim eu tentei a sua solução colocando o toString() no namePk mas sem sucesso…
Esse erro tá mt sem sentido pra mim…[/quote]
Cara, tu viu o código que te passei?
o namePk já é uma String, não precisa de toString. Eu disse para fazer o String.valueOf() no retorno do seu método getKey().
Faça como demonstrei acima e poste o resultado. Senão obtiver sucesso, faz o favor de postar a classe completa.[/quote]
Eu não coloquei o String.valueOf() no getKey pq não há problemas com ele, ele está resolvendo esta linha do código com sucesso, o erro de Cast acontece no itSrcMap.get(namePk) … mas mesmo assim eu fiz o teste com vc pediu e o erro persiste, e segue o código completo da classe, e o método onde está sendo realizada esta operação em questão é o createCmpHiddenToIds(…:
package br.com.virtuem.projurisweb.util.apresentacao.tags;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java_cup.internal_error;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import org.apache.poi.hssf.record.formula.AddPtg;
import org.springframework.web.util.ExpressionEvaluationUtils;
import com.sun.org.apache.commons.digester.ExtendedBaseRules;
import br.com.virtuem.projurisweb.config.Constants;
import br.com.virtuem.projurisweb.exceptions.ConfigurationException;
import br.com.virtuem.projurisweb.service.GenericService;
import br.com.virtuem.projurisweb.service.ServiceImpl;
import br.com.virtuem.projurisweb.util.apresentacao.BaseController;
import br.com.virtuem.projurisweb.util.apresentacao.BaseController.BUTTON;
import br.com.virtuem.projurisweb.vo.GenericVO;
public class TagPropertyGridExt extends TagGridExt{
private static final long serialVersionUID = 1L;
private boolean editable = false;
private String linkMethod = null;
private String msgTarget = "";
private String advancedSearch = "";
private String fastSearch = "";
protected String SelModel = null;
private String sm = Constants.true_str;
public void createComponent(){
String nomePk = getController(pageContext.getRequest()).getService().getPrimaryKey().get("name").toString();
ServiceImpl serv = (ServiceImpl) getController(pageContext.getRequest()).getService();
GenericVO voServ = serv.createVO(user);
List itensSrc = null;
try {
itensSrc = serv.lista(voServ, user);
} catch (ConfigurationException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
JSONBuilder source = (JSONBuilder) createSource(itensSrc, getKey(), getLabelValue());
String cmpHiddenWithIds = this.createCmpHiddenToIds(itensSrc, nomePk);
/*Set<Map.Entry<String, String>> sourceSet = source.entrySet();
String params = "";
for(Map.Entry<String, String> it: sourceSet){
params += it.getKey()+": Ext.getCmp('"+getId()+"').getSource()['"+it.getKey()+"'],\n";
}
params = new StringBuilder(params).delete(params.length()-2, params.length()-1).toString();*/
JSONBuilder pGrid = prototype("propertygrid");
pGrid.addPropertyType("autoHeight", "true")
.addPropertyType("autoWidth", "true")
.addPropertyType("source", source)
.addJson("listeners")
.addPropertyType("scope", "this")
.addPropertyType("propertychange", "function( source, recordId, value, oldValue ){" +
//"alert(recordId);"+
//"alert(Ext.getCmp(recordId).getValue());"+
"Ext.MessageBox.confirm('Confirmação', 'Tem certeza que deseja alterar este elemento?',"+
"function(btn){"+
"if(btn == 'yes'){"+
"Ext.Ajax.request({"+
"url : '"+getAction()+"',"+
"method: 'POST',"+
"params :{"+
Constants.ActionParam+":'altera', "+
nomePk+": Ext.getCmp(recordId).getValue(),"+
getLabelValue()+": value"+
//params+
"},"+
"success: function ( result, request ) {"+
"Ext.Msg.alert('Mensagem: ', 'Registro salvo com Sucesso!' );"+
"},"+
"failure: function ( result, request ) {"+
"Ext.Msg.alert('Mensagem: ', 'Falha ao salvar o Registro!' );"+
"}"+
"});"+
"}"+
"}"+
");"+
"}")
.closeJson()
.addPropertyType("items", "["+cmpHiddenWithIds+"],")
;
String pGridStr = pGrid.toString();
super.prototype("panel")
.addProperty("id", (tb.getProperty("id") == pGrid.getProperty("id")
? "ID_PANEL_PROP_GRID_"+pGrid.getProperty("id").toString().replaceAll("\"", "")
: tb.getProperty("id")))
.addPropertyType("autoHeight", true)
.addPropertyType("autoWidth", true)
.addPropertyType("colspan", "4")
.addProperty("layout", "fit")
.addJson("viewConfig")
.addPropertyType("forceFit", false)
.addPropertyType("scrollOffset", 0)
.closeJson()
.addPropertyType("split", false)
.addPropertyType("autoScroll", false)
.addPropertyType("items", pGridStr);
}
public String createCmpHiddenToIds(List itSrc, String namePk){
StringBuilder sb = new StringBuilder();
for(int i=0;i<itSrc.size();i++){
HashMap<String, String> itSrcMap = (HashMap<String, String>) itSrc.get(i);
//long x = 10;
//String a = ""+x;
//long pkLong = Long.parseLong(itSrcMap.get(namePk));
// <POG FROM HELL, RESOLVER CAST DE LONG PARA STRING ( itSrcMap.get(namePk).toString() )>
/*String itSrcStr = itSrcMap.toString();
char[] pkChar = itSrcStr.substring(itSrcStr.indexOf(namePk)+namePk.length()+1, itSrcStr.indexOf(namePk)+namePk.length()+1+15).toCharArray();
String pkStr = "";
for(int j=0;j<pkChar.length;j++){
if(Character.isDigit(pkChar[j])){
pkStr += pkChar[j];
}else{
break;
}
}*/
// <FimPog>
sb.append("{xtype: 'hidden', id:'")
.append(itSrcMap.get(getKey()))
.append("', value:'")
.append(itSrcMap.get(namePk))
//.append(pkStr)
.append("'}");
if((i+1) != itSrc.size()){
sb.append(",");
}
}
return sb.toString();
}
public String getId() {
return super.getId() + getProperty() + "_propGrid";
}
protected String getAlign(final String c) {
if (c != null && c.equals("imageSelector")) {
return "center";
}
return c.equals("money") || c.equals("indice") ? "right" : "left";
}
private String getReverseProperty() {
if (getProperty().indexOf("_FROM") > -1) {
return getProperty().replaceAll("_FROM", "_TO");
} else {
return getProperty().replaceAll("_TO", "_FROM");
}
}
@Override
public void preProcess() {
super.preProcess();
pageContext.getRequest().removeAttribute("colunas");
final Map p = getUtil().JSONtoMap(getServiceParams());
if (p.containsKey("LIST_LINK")) {
pageContext.getRequest().setAttribute("list_link", getUtil().EvaluateInString(
(String) p.get("LIST_LINK"), pageContext.getRequest(), pageContext));
}
List fields = null;
if (service.isDefaultCRUD(getServiceMethod())) {
fields = service.getDAO().getProperties();
if (fields == null || fields.size() == 0) {
fields = (List) service.getProperties().get(
Constants.ALL_FIELDS);
}
} else {
fields = (List) service.getMethod(getServiceMethod(), user).get(
Constants.ALL_FIELDS);
}
if (getLinkMethod() != null && isSelectionModel()) {
// SelModel = new JSONBuilder();
String name = (String) service.getPrimaryKey().get(Constants.name);
if(service.getListKey()!=null)
name = (String) service.getListKey().get(Constants.name);
List buttons = new ArrayList();
try {
buttons = (List) ((Map) pageContext.getRequest()
.getAttribute(Constants.BUTTONS)).get(getLabel());
} catch (Exception e) {
// TODO: handle exception
}
SelModel = "getSM('"
+ name
+ "',['"
+ getContainer().getId()
+ "','"
+ getContainer().getServiceMethod()
+ "',"
+ getUtil().JSONserialize(Arrays.asList(getUtil()
.extractArrayFromList(buttons, "id", false)))
+ ","
+ getUtil().JSONserialize(Arrays.asList(getUtil()
.extractArrayFromList(buttons, "RULE", false)))
+ ", '" + name+ "'] , '"
+ getId() + "')";
}
ArrayList pk = new ArrayList<Map>();
if (service.getProperties().get(Constants.RELATION_KEY) != null) {
List m = getUtil().match(fields, Constants.name, service.getProperties()
.get(Constants.RELATION_KEY));
if (m.size() > 0) {
pk.add(m.get(0));
}
}
fields = getUtil().filter(fields, "listable", null);
fields = getUtil().filter(fields, "type", "array");
getUtil().SortCollection(fields, "listable");
pk.add(service.getPrimaryKey());
// f = util.ManageCollection(f, "remove" , "primaryKey", null);
pk.addAll(fields);
if (getRestrict() != null) {
String[] res = getRestrict().split(",");
List temp = (List) pk.clone();
pk.clear();
for (String re : res) {
pk.addAll(getUtil().match(temp, Constants.name, re.trim()));// usar o
// defineColumn
// da
// util
// para
// caso
// onde
// a
// coluna
// é
// cascateada
}
}
final Iterator i = pk.iterator();
while (i.hasNext()) {
final Map e = (Map) i.next();
addColumn(e, pageContext.getRequest());
}
}
public int doEndTag() throws JspException {
linkMethod = null;
msgTarget = "";
SelModel = null;
sm = Constants.true_str;
advancedSearch = "";
fastSearch = "";
return super.doEndTag();
}
public boolean isSelectionModel() {
return (sm == null || sm.toString().trim().length() == 0) ? true : Boolean.valueOf(sm);
}
public JSONBuilder prototype(final Object xtype) { // generics
if (labelValue != null && labelValue.startsWith(ExpressionEvaluationUtils.EXPRESSION_PREFIX)) {
labelValue = (String) Evaluate(labelValue);
}
final JSONBuilder tb = super.prototype(xtype);
if (tb.get("id") == null) {
tb.addProperty("id", getId());
}
if (getName() != null) {
tb.addProperty(Constants.name, getName()); // Para o seletor do jQuery
}
return tb;
}
public void bindReload(final StringBuilder sb, final String[] cv,String values) {
String f = util.unContext(cv[0], service);
if (!cv[1].equals("reload")) {
f = cv[1];
}
sb.append(" Ext.getCmp('" + getId(cv[0], pageContext.getRequest())
+ "').on('change', function() { \n"
+ " var st = Ext.getCmp('" + "" + getId()
+ "').store; var val = escape(Ext.getCmp('"
+ getId(cv[0], pageContext.getRequest()) + "').getValue() != '' ? Ext.getCmp('"
+ getId(cv[0], pageContext.getRequest())
+ "').getValue() : 0); st.baseParams." + f
+ " = val; st.baseParams.FILTRO='"
+ getUtil().encode("{gA:[{c:{f:\"" + f + "\",o:\"=\",vc:\"")
+ "' +val+ '" + getUtil().encode("\"}}]}") + "';");
sb.append("Ext.getCmp('" + "" + getId() + "').clearValue(); \n");
sb.append("Ext.getCmp('" + "" + getId() + "').store.load(); \n");
sb.append("} ); st" + getName() + " = Ext.getCmp('" + "" + getId()
+ "').store; var val" + getName() + " = escape(Ext.getCmp('"
+ getId(cv[0], pageContext.getRequest()) + "').getValue() != '' ? Ext.getCmp('"
+ getId(cv[0], pageContext.getRequest()) + "').getValue() : 0); st"
+ getName() + ".baseParams." + f + " = val" + getName()
+ "; st" + getName() + ".baseParams.FILTRO='"
+ getUtil().encode("{gA:[{c:{f:\"" + f + "\",o:\"=\",vc:\"")
+ "' +val" + getName() + "+ '" + getUtil().encode("\"}}]}")
+ "';\n ");
}
public void postProcess() {
super.postProcess();
}
public boolean processParams() {
return true;
}
// Getters e Setters: \\
public void setEditable(boolean editable) {
this.editable = editable;
}
public boolean isEditable() {
return editable;
}
public String getLinkMethod() {
if (linkMethod == null || linkMethod.trim().length() == 0) {
return null;
}
linkMethod = getUtil().replace(linkMethod, new String[] { "$ID$" }, new String[] { getId() });
return getUtil().EvaluateInString(linkMethod, pageContext.getRequest(), pageContext);
}
public void setLinkMethod(String linkMethod) {
this.linkMethod = linkMethod;
}
public String getMsgTarget() {
return msgTarget;
}
public void setMsgTarget(String msgTarget) {
this.msgTarget = msgTarget;
}
public String getAdvancedSearch() {
return advancedSearch;
}
public void setAdvancedSearch(String advancedSearch) {
this.advancedSearch = advancedSearch;
}
public String getFastSearch() {
return fastSearch;
}
public void setFastSearch(String fastSearch) {
this.fastSearch = fastSearch;
}
public String getSelModel() {
return SelModel;
}
public void setSelModel(String selModel) {
SelModel = selModel;
}
public String getSm() {
return sm;
}
public void setSm(String sm) {
this.sm = sm;
}
public static long getSerialversionuid() {
return serialVersionUID;
}
}