servlets - JSF replacing <p:button> with <h:commandLink> -
i have working <p:button>
invokes method inside managed bean follows:
<h:form id="loginform"> <p:button value="facebook connect" href="#{loginpagecode.facebookurlauth}" /> <br /> <h:outputtext value="#{loginpagecode.userfromsession}"/> </h:form>
and decided replace link, did following:
<h:form id="loginform"> <h:commandlink action="#{loginpagecode.getfacebookurlauth}" value="#{loginpagecode.userfromsession}" /> </h:form>
but unfortunately <h:commandlink>
doesn't invoke method don't know why?
note: method inside managed bean returns url servlet, commandlink have call these servlet when clicked using url returned>
there'a major misunderstanding going here. <p:button>
not invoke action method in managed bean @ all. el expression in href
attribute not evaluated when button pressed. evaluated when html representation of button rendered. if put break point on getter of facebookurlauth
, you'll see it's invoked when page button displayed , not when button pressed. if check jsf-generated html output rightclick, view source, you'll see button navigates javascript in onclick. it's pure navigation button, not submit button.
the <h:commandlink>
generates link uses javascript submit parent form. not designed perform pure navigation. should using <h:outputlink>
, <h:link>
or <a>
instead. it's apparently external url, <h:link>
insuitable.
thus, so
<h:outputlink value="#{loginpagecode.facebookurlauth}">facebook connect</h:outputlink>
or just
<a href="#{loginpagecode.facebookurlauth}">facebook connect</a>
this have been more straightforward if understand jsf merely html code generator , when you're familiar basic html.
Comments
Post a Comment