Variational Problems For Lagrangian And Legendrian Submanifolds