Bom Dia a todos.
Estou com um problema aqui e não consigo resolver. Acredito ser algo simples.
Preciso que quando clicar em um button ele chame o bean e mande um valor.
No método getForm(), eu crio o button (Na linha 228), ao desenhar na tela e clicar no mesmo ele entra no paanelsSelecionado() mas não abre a dialog.
Codigo Web:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head >
<title id="xx">Teste</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- Compatibilidade para IE -->
<meta http-equiv="X-UA-Compatible" content="IE=8, IE=9, IE=10" />
<!-- Plugin google -->
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<link href="images/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<script>
...
</script>
</h:head>
<body style="overflow: auto;"
onresize="tamanhoTela()" >
<h:form id="formTable"
binding="#{erpBean.form}" >
</h:form>
<!--LOGIN-->
<p:dialog id="telaLogin"
header="Bem-vindo ao ERP TECNICON"
draggable="false"
closable="false"
resizable="false"
visible="true"
widgetVar="telaloginTeste"
position="top"
width="376"
modal="true">
<h:form id="form2" >
<h:inputHidden id="largura1"
value="#{erpBean.largura}" />
<h:inputHidden id="altura1"
value="#{erpBean.altura}" />
<p:commandButton actionListener="#{erpBean.validaLogin}"
value="Entrar"
onclick="setarTamanho();"
ajax="true"
update=":formTable"
oncomplete="validaLogin(xhr, status, args)"/>
</h:form>
</p:dialog>
</body>
</html>
Código Java:
@ManagedBean(name = "erpBean")
@ViewScoped
public class ERPBean implements Serializable {
private static String[] manufacturers;
private HtmlForm form;
private HtmlPanelGrid png;
private String altura;
private String largura;
private Panel paanel;
private Panel dadosDash;
private int cont = 0;
private HashMap<Integer, UIComponent> hashDashBoard = new HashMap<Integer, UIComponent>();
private FacesContext fctx;
private ELContext elctx;
private Application app;
private ExpressionFactory exprFactory;
@PostConstruct
public void ERPBeanConstruct() {
setPaanel(new Panel());
fctx = FacesContext.getCurrentInstance();
elctx = fctx.getELContext();
app = fctx.getApplication();
exprFactory = app.getExpressionFactory();
CommandButton button = new CommandButton();
button.setId("testte");
button.setValue("TESTETE");
getPaanel().getChildren().add(button);
}
/**
* ------------------------------------------------------------------------
* Metodos
* ------------------------------------------------------------------------
*/
public void validaLogin(ActionEvent actionEvent) {
//vs = new TVariavelSessao();
RequestContext context = RequestContext.getCurrentInstance();
boolean retorno = false;
if (!altura.equals("") && !largura.equals("")) {
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
httpSession.setAttribute("altura", altura);
httpSession.setAttribute("largura", largura);
if (form.getChildCount() > 0) {
retorno = true;
}
}
context.addCallbackParam("loggedIn", retorno);
}
/**
* @return the form
*/
public HtmlForm getForm() {
try {
setForm(new HtmlForm());
HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession httpSession = request.getSession(false);
if (httpSession != null && httpSession.getAttribute("altura") != null) {
String altura = httpSession.getAttribute("altura").toString();
String largura = httpSession.getAttribute("largura").toString();
if (altura != null && largura != null) {
// FacesContext fc;
// ELContext elctx;
// Application application;
// ExpressionFactory exprFactory;
// fc = FacesContext.getCurrentInstance();
// elctx = fc.getELContext();
// application = fc.getApplication();
// exprFactory = application.getExpressionFactory();
setManufacturers(getManufacturers());
int alturaN = Integer.parseInt(altura);
int larguraN = Integer.parseInt(largura);
/**
* Cria o panel grid
*/
setPng(new HtmlPanelGrid());
getPng().setId("panelGrid" + getCont());
getPng().setRendered(true);
// png.setColumns(5);
getPng().setCellpadding("5");
getPng().setCellspacing("5");
getPng().setBorder(2);
getPng().setWidth("100%");
/**
* Verificar quantas colunas vai ter
*/
int tam = (manufacturers.length) - 1;
int colunas = 0;
int linhas = 0;
switch (tam) {
case 1:
getPng().setColumns(1);
colunas = 1;
linhas = 1;
break;
case 2:
getPng().setColumns(2);
colunas = 2;
linhas = 1;
break;
case 3:
case 4:
getPng().setColumns(2);
colunas = 2;
linhas = 2;
break;
case 5:
case 6:
getPng().setColumns(3);
colunas = 3;
linhas = 2;
break;
case 7:
case 8:
case 9:
getPng().setColumns(3);
colunas = 3;
linhas = 3;
break;
}
float larGrafico = (alturaN / linhas) - 40;
for (int i = 0; i < manufacturers.length - 1; i++) {
/**
* Cria o panel
*/
Panel p = new Panel();
p.setId("png" + getCont());
p.setHeader(manufacturers[i]);
p.setClosable(true);
p.setStyle("width: 100%; height: " + larGrafico + "px;");
/**
* Cria a tabview
*/
TabView tabView = (TabView) fctx.getApplication().createComponent(
"org.primefaces.component.TabView");
tabView.setStyleClass("font-size: 0.5em; padding: 0px; width: 100%; height: 100%;");
/**
* Cria as tabs
*/
Tab tab = new Tab();
tab.setId("tabLinha_" + getCont());
tab.setTitle("L" + getCont());
Tab tab2 = new Tab();
tab2.setId("tabBarra_" + getCont());
tab2.setTitle("B" + getCont());
Tab tab3 = new Tab();
tab3.setId("tabPizza_" + getCont());
tab3.setTitle("P" + getCont());
//-------------------------------------------------------------------
/**
* Graficos de Linha
*/
LineChart lineChart = retornaLineChart(app, fctx, getCont());
lineChart.setStyle("width: 100%; height: " + (larGrafico - 95) + "px;");
RemoteCommand rcLine = new RemoteCommand();
rcLine.setId("rcLine" + getCont());
rcLine.setName("updateLinha");
rcLine.setUpdate(lineChart.getId());
tab.getChildren().add(lineChart);
tab.getChildren().add(rcLine);
//-------------------------------------------------------------------
/**
* Graficos de Barra
*/
BarChart barchart = retornaBarChart(app, fctx, getCont());
barchart.setStyle("width: 100%; height: " + (larGrafico - 95) + "px;");
RemoteCommand rcBar = new RemoteCommand();
rcBar.setId("rcBar" + getCont());
rcBar.setName("updateBarra");
rcBar.setUpdate(barchart.getId());
tab2.getChildren().add(barchart);
tab2.getChildren().add(rcBar);
//-------------------------------------------------------------------
/**
* Graficos de Pizza
*/
PieChart pieChart = retornaPieChart(app, getCont());
pieChart.setStyle("width: 100%; height: " + (larGrafico - 95) + "px;");
RemoteCommand rcPie = new RemoteCommand();
rcPie.setId("rcPie" + getCont());
rcPie.setName("updatePizza");
rcPie.setUpdate(pieChart.getId());
tab3.getChildren().add(pieChart);
tab3.getChildren().add(rcPie);
//-------------------------------------------------------------------
Class[] argtypes = new Class[1];
argtypes[0] = ActionEvent.class;
String m = "#{erpBean.paanelsSelecionado}";
MethodExpressionActionListener actionListener =
new MethodExpressionActionListener(exprFactory.createMethodExpression(elctx, m, Void.class, argtypes));
ValueExpression expr =
exprFactory.createValueExpression(elctx, "go", String.class);
CommandButton submit = new CommandButton();
submit.setId("x" + getCont());
submit.setValueExpression("value", expr);
submit.setProcess("formTable");
submit.setOncomplete("dlg.show()");
submit.addActionListener(actionListener);
// submit.setUpdate("formTable");
submit.setRendered(true);
submit.setAjax(false);
/**
* Adiciona os filhos
*/
tabView.getChildren().add(tab);
tabView.getChildren().add(tab2);
tabView.getChildren().add(tab3);
p.getChildren().add(tabView);
p.getChildren().add(submit);
getPng().getChildren().add(p);
if (!hashDashBoard.containsKey(cont)) {
getHashDashBoard().put(getCont(), p);
}
setCont(getCont() + 1);
}
Dialog dialog = new Dialog();
dialog.setId("dialog");
dialog.setWidgetVar("dlg");
dialog.setHeader("Detalhe Grafico");
dialog.setResizable(false);
dialog.setWidth("600");
dialog.setHeight("600");
dialog.setHideEffect("clip");
dialog.setShowEffect("clip");
dialog.setModal(true);
dialog.getChildren().add(getPaanel());
form.getChildren().add(getPng());
form.getChildren().add(dialog);
}
}
return form;
} catch (Exception ex) {
Logger.getLogger(ERPBean.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
public void paanelsSelecionado(ActionEvent ae) {
System.out.println("---------------------Entrou------------------------");
/**
Preciso pegar a posicao do grafico no hash e setar no paanel para mostrar na dialog
*/
}
/**
* ------------------------------------------------------------------------
* Metodos Graficos
* ------------------------------------------------------------------------
*/
private LineChart retornaLineChart(Application application, FacesContext fc, int i) {
/**
* Graficos de Linha
*/
LineChart lineChart = (LineChart) application.createComponent(fc, "org.primefaces.component.chart.LineChart", "org.primefaces.component.chart.LineChartRenderer");
lineChart.setId("lc_" + i);
lineChart.setWidgetVar(lineChart.getId());
/**
* Cria os model dos graficos
*/
CartesianChartModel ccmLine = new CartesianChartModel();
/**
* Cria as series
*/
ChartSeries ana = new ChartSeries();
ana.setLabel("Ana");
ana.set("2005", (int) (Math.random() * 99) + 1);
ana.set("2006", (int) (Math.random() * 99) + 1);
ana.set("2007", (int) (Math.random() * 99) + 1);
ana.set("2008", (int) (Math.random() * 99) + 1);
ana.set("2009", (int) (Math.random() * 99) + 1);
ChartSeries beatriz = new ChartSeries();
beatriz.setLabel("Beatriz");
beatriz.set("2005", (int) (Math.random() * 99) + 1);
beatriz.set("2006", (int) (Math.random() * 99) + 1);
beatriz.set("2007", (int) (Math.random() * 99) + 1);
beatriz.set("2008", (int) (Math.random() * 99) + 1);
beatriz.set("2009", (int) (Math.random() * 99) + 1);
/**
* Adiciona os filhos
*/
ccmLine.addSeries(ana);
ccmLine.addSeries(beatriz);
lineChart.setValue(ccmLine);
return lineChart;
}
private BarChart retornaBarChart(Application application, FacesContext fc, int i) {
...
}
private PieChart retornaPieChart(Application application, int i) {
...
}
/**
* ------------------------------------------------------------------------
* GETTERs and SETTERs
* ------------------------------------------------------------------------
*/
...
}
Estou usando o primefaces 3.1.1.
Servidor GlassFish
JSF 2.1
Grata