javasf@googlegroups.com
[Top] [All Lists]

[javasf] Re: <h:commandButton> sem submitar

Subject: [javasf] Re: <h:commandButton> sem submitar
From: Daniel Vieira
Date: Wed, 8 Jun 2011 11:03:34 -0700 PDT
@ManagedBean(name="analiseDeVinculosBean")
@SessionScoped
public class AnaliseDeVinculosBean {

                public String salvar() {
                String str = getUrlAnaliseSelecionada(); //home2
                System.out.println("path: " + str);

                String auxUrl [] = str.split("/");
                String nomeDoArquivo = auxUrl[auxUrl.length-1];
                String xml = "";
                FacesContext context = FacesContext.getCurrentInstance();
                System.out.println("JSON: " + json);
                Tools tools = new Tools();
                try {
                        xml = tools.Js2Xml(json, nomeDoArquivo);
                } catch (Exception e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }


                int index = str.lastIndexOf("/");
                String urlDoServidor = 
analiseEscolhida.getUri_file().toString();
                String localFile = "/opt/apache-tomcat-6.0.29/webapps/
AnaliseDeVinculos-HTML/BinRR/";
                localFile += str.substring((index+1));
                Tools.XML2Gzip(new File(localFile), nomeDoArquivo);

                        ScpTo scp = new ScpTo();
                       if(scp.scpFile(urlDoServidor, localFile, 
"192.168.166.80",
"root") <= 0) {
                           System.out.println("Enviei para o servidor");
                       } else {
                           System.out.println("Não enviei para o servidor");
                       }



                JOptionPane.showMessageDialog(null, "chego no finalzão do
salvar()");
                return null;

        }




------------------------------------------




xhtml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<html xmlns="http://www.w3.org/1999/xhtml";
      xmlns:h="http://java.sun.com/jsf/html";
      xmlns:f="http://java.sun.com/jsf/core";>
      <head>
        <link type="text/css" href="css/base.css" rel="stylesheet" />
                <link type="text/css" href="css/ForceDirected.css" 
rel="stylesheet" /
>
                <style type="text/css">
                        input.btn_salvar { display: none }
                </style>
        <script language="javascript" type="text/javascript" src="lib/
jit.js"></script>
        <!--<script language="javascript" type="text/javascript"
src="new_morph.js"></script> -->
        <script language="javascript" type="text/javascript"
src="#{analiseDeVinculosBean.javascript}"></script>
        <script type="text/javascript">
                function fnCommitSalvarGrafo() {
                        document.getElementById('form_graph:salvar').click();
                }
                </script>
        <title>Analise de Vinculos - WEB</title>
      </head>
      <body onload="init();">
            <div id="left-container">
                        <div id="inner-details"></div>
                </div>
                <div id="id-list"></div>
                <div id="top-container">
                        <h:form 
action="#{analiseDeVinculoBean.analiseDeVinculo}">
                        <br/>
                                <table width="75%">
                                <tr>
                                        <td align="left">Analises:</td>
                                        <td align="left">
                                                <h:selectOneMenu
value="#{analiseDeVinculosBean.idSelecionado}" styleClass="analise"
                                                        immediate="true" 
onchange="submit();"
valueChangeListener="#{analiseDeVinculosBean.mudouSelecao}">
                                                        <f:selectItems
value="#{analiseDeVinculosBean.combo}"/>
                                                </h:selectOneMenu>
                                        </td>
                                </tr>
                                <tr>
                                        <td colspan="2"><h:messages/></td>
                                </tr>
                            </table>
                        </h:form>               </div>
                <div id="center-container">
                        <div id="log"></div>
                        <div id="infovis"></div>
                </div>

<h:form id="form_graph">
                                <h:inputHidden id="json" 
value="#{analiseDeVinculosBean.json}"/>
                                <h:commandButton id="salvar"
action="#{analiseDeVinculosBean.salvar}" value=""
class="btn_salvar">
                                <h:inputHidden id="id_mostrado"
value="#{analiseDeVinculosBean.ultIdSelecionado}"/>
                        </h:form>



É mais ou menos isso. Dei uma resumida só pras partes que interessam.
hehe
Toda vez que eu clico no salvar, do commandButton, minha aplicação
submita.
Eu quero que ela permaneça imóvel.










e aqui o meu faces-config:


<?xml version="1.0" encoding="UTF-8"?>

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee";
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd";
    version="2.0">

<navigation-rule>
        <description>Inicio</description>
        <from-view-id>redireciona.xhtml</from-view-id>

        <navigation-case>
                <from-outcome>inicio</from-outcome>
                <to-view-id>redireciona.xhtml</to-view-id>
        </navigation-case>
        <navigation-case>
                <from-action>#{analiseDeVinculosBean.novo}</from-action>
                <from-outcome>nova_analise</from-outcome>
                <to-view-id>inicio.xhtml</to-view-id>
        </navigation-case>
</navigation-rule>

<navigation-rule>
        <from-view-id>inicio.xhtml</from-view-id>
        <navigation-case>
                <from-action>#{analiseDeVinculosBean.salvar}</from-action>
                <from-outcome>json</from-outcome>
                <to-view-id>inicio.xhtml</to-view-id>
        </navigation-case>
</navigation-rule>

</faces-config>





On 8 jun, 14:21, Filipe Aguilar Santana <aguilar.l...@xxxxxxxxx>
wrote:
> Olá! Será que da pra explicar melhor o que quer fazer?
>
> Coloque parte do código em sua pagina e tb o método de seu MB....
>
> T+,
> Filipe.
>
> Em 8 de junho de 2011 14:04, Daniel Vieira 
> <daniel.sviei...@xxxxxxxxx>escreveu:
>
>
>
>
>
>
>
> > Valeuzão pelas respostas, galera, mas nenhum dos dois jeitos
> > funcionou. :(
>
> > Esse esqueminha do immediate="true" é só assim?
> > Continua submitando.
> > A propósito, meu formulário não é um formulário qualquer. É um canvas,
> > HTML5. Isso muda alguma coisa?
>
> > Só assim?
> > <h:commandButton id="salvar" action="#{analiseDeVinculosBean.salvar}"
> > immediate="true" value="" class="btn_salvar"/>
>
> > On 8 jun, 13:36, Filipe Aguilar Santana <aguilar.l...@xxxxxxxxx>
> > wrote:
> > > Se você colocar um immediate=”true” no commandButton ele tbm vai executar
> > a
> > > action sem enviar o formulário.
>
> > > Mais fácil né :-)
>
> > > Em 8 de junho de 2011 13:33, Filipe Aguilar Santana
> > > <aguilar.l...@xxxxxxxxx>escreveu:
>
> > > > Mais sobre o execute.
>
> > > > execute
> > > > A space-separated list of components that JSF executes on the
> > > > server during the Ajax call. Valid keywords for the execute
>
> > > > attribute are:
> > > > *@this - executa o componente (é o padrão)
> > > > @form - executa o formulario
> > > > @all - tudo rs
> > > > @none* - nada
>
> > > > If you don’t specify an execute attribute, JSF uses @this as the
> > default
> > > > value.
>
> > > > Em 8 de junho de 2011 13:22, Filipe Aguilar Santana <
> > > > aguilar.l...@xxxxxxxxx> escreveu:
>
> > > > É Submitar mesmo que fala? Engraçado rs
>
> > > >> :-)
>
> > > >> Em 8 de junho de 2011 13:21, Filipe Aguilar Santana <
> > > >> aguilar.l...@xxxxxxxxx> escreveu:
>
> > > >> Sim! Tem que usar a tag <f:ajax/> e fazer o execute em componentes
> > > >>> especificos do form.
>
> > > >>> tipo:
>
> > > >>> <h:outputText id="text" />
>
> > > >>> <h:commandButton>
> > > >>>        <f:ajax execute="text" />
> > > >>> </h:command...>
>
> > > >>> Obs. pra executar mais de um deixa um espaço em branco...tipo
> > > >>> execute="comp1 comp2 comp3"
>
> > > >>> T+,
> > > >>> Filipe.
>
> > > >>> Em 8 de junho de 2011 12:01, Daniel Vieira <
> > daniel.sviei...@xxxxxxxxx>escreveu:
>
> > > >>> Bom dia!
>
> > > >>>> Existe algum meio de usar o <h:commandButton> sem submitar meu
> > > >>>> formulário?
> > > >>>> Cada vez que eu chamo o bean, pelo no action do commandButton, meu
> > > >>>> formulário é submitado, ou seja. Ele reinicia.
>
> > > >>>> Há como executar a action sem submitar o form?
>
> > > >>>> Valeuzão
>
> > > >>>> --
> > > >>>> Você recebeu esta mensagem por que é membro do  Javasf
> > > >>>>http://groups.google.com/group/javasf
>
> > > >>>> Conheça também o Java Brazil:
> > > >>>>http://groups.google.com/group/thejavabrazil
>
> > --
> > Você recebeu esta mensagem por que é membro do  Javasf
> >http://groups.google.com/group/javasf
>
> > Conheça também o Java Brazil:http://groups.google.com/group/thejavabrazil

-- 
Você recebeu esta mensagem por que é membro do  Javasf
http://groups.google.com/group/javasf

Conheça também o Java Brazil: http://groups.google.com/group/thejavabrazil

<Prev in Thread] Current Thread [Next in Thread>