Dynamic response of trapped ultracold bosons on optical lattices