Weak compactness of wave maps and harmonic maps