Reputation: 1991
I have this JSF code
<f:view>
<h:form>
<h:commandButton value="Submit info" type="button" action="#{bean.submit}" />
</h:form>
</f:view>
I also have this bean
@ManagedBean(name="bean")
@RequestScoped
public class Bean{
public void submit(){
HttpURLConnection connection = null;
URL url;
String generatedUrl = "blalabla"; //Long url
StringBuffer response = new StringBuffer();
try {
url = new URL(generatedUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
int responseCode = connection.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while((inputLine = in.readLine()) != null){
response.append(inputLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
When I click the button, the submit method is not executed. Seems as if the button doesn't do anything. Since I set it as type="button", there is no redirect, but still, the method isn't executed.
Any ideas?
Upvotes: 0
Views: 91
Reputation: 31649
Change the type="button"
attribute for type="submit"
or just remove it, as type="submit"
is the default behaviour of the tag. type="button"
is normally used to execute client side methods or Ajax calls. Here you have another post by BalusC.
Upvotes: 2