When a farmer needs water, he likes rainy days. When friends go travelling, they like sunny days. These are ok .
But, it is more correct to say these :
When a farmer needs water, he hopes for rainy days. When friends have to travel, they hope for sunny days/they prefer to do it on sunny days .
"When " is used instead of "if" to show the something you will normally do at that time when it happens .
When a farmer needs water, he likes rainy days. > Does he not like it when he has water ?
Farmers like rainy days because they can have a lot of water.