4

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
8
  • This should work just fine. Even more, the <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)? Commented Mar 14, 2013 at 20:54
  • Do you have getter and setter methods for returnTo? Commented Mar 14, 2013 at 20:59
  • yes, there are getter/setters Commented Mar 14, 2013 at 21:17
  • @BalusC I added the full page... Commented Mar 14, 2013 at 21:23
  • AFAIK, MyFaces doesn't support <f:metadata> inside <ui:composition>. Try this instead: stackoverflow.com/questions/9856847/… Commented Mar 14, 2013 at 21:26

1 Answer 1

6

Your <f:metadata> is outside <ui:define> and is therefore completely ignored. Add an <ui:insert name="metadata"> to the master template and put the <f:metadata> inside an <ui:define name="metadata"> of the template client.

See also:


Once you fixed that, you can safely remove the <f:param> from the command button. This job is already done by <o:form includeViewParams="true">. If you didn't have it, then the <f:param> would indeed have been mandatory and you'd need to copypaste the same over all command links and buttons in the same form.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.