Maybe you´re the innocent type that finds this offensive, but actually this happens more often than you think! People just don´t mention this, with good reason, to their partner. Which makes sense because I think it would be painful if your partner has to fantasize about someone else during sex to get turned on. But I´d say if this happens a lot then you should talk about it, because there is only that much fantasy can do for you. Sooner or later you´ll have to deal with the fact that you´re not attracted to your partner anymore.
I think we´ve all done it at least once, fantasizing about someone else during sex isn´t a bad thing but I wouldn´t make a habit out of it. But maybe if you´re not really in the mood for sex and your partner is then maybe it helps if you fantasize a bit, it´s a great way to spice things up a bit. Of course roleplay helps even more, but that means that you´ll have to talk about a sexual fantasy with your partner and not everyone is always that open about those things. But it´s not a bad idea to talk about it, just try to be delicate about these things because you don´t want to give your partner the idea that he or she isn´t attractive or that you´re not attracted to him or her anymore. That´s something you want to avoid at all costs!
If fantasizing about other people becomes a frequent thing during sex then you might want to talk to your partner, because as much as it might seem harmless it´s of course not a good thing if you constantly do that. Maybe some people aren´t offended by that, but I don´t think people would like it if you think of someone else while having sex with them. For some it can be a sensitive subject and others couldn´t care less, it really depends on the person but I do think that in a serious relationship people wouldn´t appreciate that.
But what if your boyfriend or husband has erection problems? Well I don´t think fantasizing about other people will make that go away but if you think that it will help then you can always try it. But I don´t think it will make things better for the relationship, because I think you´ll feel worse when he´ll get erections while fantasizing about other people. That might give you the idea that he´s no longer attracted to you, which doesn´t really come as a suprise to me. But if it does work for you and it doesn´t bother your partner then it might not be a bad idea, just be careful with such things because it can get ugly if you´re not careful!