As per Roman C comment, no way to achieve what I wanted to do without coming back to the browser so that it can issue a POST request. So I have achieved what I wanted to do by rearchitecturing the code and focusing on the JSP.
<h3>
Showing available Service Providers :
<c:out value="${serviceProvider}" />
</h3>
<ul>
<c:forEach items="${serviceProviders}" var="sp">
<li><c:out value="${sp.name}" /> <c:if test="${sp.connected}"> : Connected with Permissions : <c:out
value="${sp.permissions}" />
<form action="<c:url value="<%=Uris.DISCONNECT%>" />" method="POST">
<button type="submit">Disconnect</button>
<input type="hidden" name="sp" value="${sp.name}" />
</form>
</c:if>
<c:if test="${!sp.connected}"> : Disconnected
<form action="<c:url value="${sp.URL }" />" method="POST">
<button type="submit">Connect</button>
<input type="hidden" name="scope" value="${sp.permissions}" />
</form></c:if></li>
</c:forEach>
</ul>
The controller then takes care of populating the service provider information depending of its connection status. If there is no connection to the service provider, the 2nd <c:if>
clause will build a connection button taking care of doing the post method with the right scope/permissions.
Here is the controller code (URIs.WORK points to the jsp shown above):
@RequestMapping(value = Uris.MAIN)
public String home(Model model) {
List <SPInfo> SPStatusList = new ArrayList<SPInfo>();
for (ServiceProviders sp : ServiceProviders.values()) {
SPConnectionRetriever spAccess = SPBank.getSPConnection(sp);
SPStatusList.add(new SPInfo(sp.toString(), spAccess.isconnected(), spAccess.getPermissions(),spAccess.getConnectUrl()));
}
model.addAttribute("nom", SecurityContext.getCurrentUser().getId());
model.addAttribute("serviceProviders", SPStatusList);
return Uris.WORK;
}
with SPInfo class looking as follows :
public class SPInfo {
private String name;
private boolean connected;
private String permissions;
private String URL;
public SPInfo(String name, boolean isConnected, String permissions, String URL) {
super();
this.name = name;
this.connected = isConnected;
this.permissions = permissions;
this.URL = URL;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isConnected() {
return connected;
}
public void setConnected(boolean isConnected) {
this.connected = isConnected;
}
public String getPermissions() {
return permissions;
}
public void setPermissions(String permissions) {
this.permissions = permissions;
}
public String getURL() {
return URL;
}
public void setURL(String uRL) {
URL = uRL;
}
}