I have the following page:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:o="http://omnifaces.org/ui" xmlns:thehub="http://java.sun.com/jsf/composite/components/thehub" template="/templates/masterTemplate.xhtml"> <f:metadata> <f:viewParam id="returnToViewParam" name="returnTo" value="#{loginMB.returnTo}" required="true" /> <f:viewParam id="oauth_verifierViewParam" name="oauth_verifier" value="#{loginMB.oauth_verifier}" /> <f:viewParam id="oauth_tokenViewParam" name="oauth_token" value="#{loginMB.oauth_token}" /> <f:event type="preRenderView" listener="#{loginMB.preRenderView()}" /> </f:metadata> <ui:define name="body"> <o:form id="loginForm" includeViewParams="true"> <div class="form-vertical well"> <h4>New Users</h4> <h5> <h:link outcome="signup">Click here to create an account</h:link> </h5> <hr /> <h4>Existing Users</h4> <h:commandButton id="googleLoginCommandLink" styleClass="btn" action="#{loginMB.redirect()}" value="Google"> <f:param name="returnTo" value="#{param.returnTo}" /> </h:commandButton> <div class="clearfix"></div> </div> </o:form> </ui:define> </ui:composition> And the following bean:
@ManagedBean @RequestScoped public class LoginMB implements Serializable { private static final long serialVersionUID = 1L; private String returnTo; public void redirect() { log.debug("redirect() returnTo:{}", returnTo); ......getter/setters } No matter what I do, I can't seem to get returnTo bound once the commandButton is clicked. Since this is a login page, I'd really not like to have LoginMB be a @ViewScoped bean.
Advice? Is there a better way to handle this scenario?
EDIT:
- I'm running this on TomEE+ Server v1.5.1 which is served up by MyFaces 2.1.10
- Added full page
- Clarified the problem: Inside the
redirect()function, returnTo is null
<f:param>is completely unnecessary if you use<o:form includeViewParams="true">. You only need it if you aren't using<o:form>. To be sure, I have even tried it locally and it works just fine. Your concrete problem is likely caused elsewhere not visible in the information provided so far. What JSF impl/version are you using? Is the<f:metadata>properly declared inside the template composition (and thus not outside)?returnTo?<f:metadata>inside<ui:composition>. Try this instead: stackoverflow.com/questions/9856847/…