Variational methods in Hamiltonian PDEs