0

I want to have a validator for my password reset. It will look at the URL and parse the token_id out of it. I have the rest of the logic done. I need this validator to be called on page load from my jsf view. However I cannot find a way to invoke the validator using a preRender function. The code below is to call the userBean and check the token. How would I change this to call a validator rather than a managed bean property?

<f:metadata>
    <f:event listener="#{userBean.check()}" type="preRenderView"/>
</f:metadata>

resetPassword.xhtml

<h:body>
    <!-- Preload to assure the token is correct -->
    <ui:composition template="/WEB-INF/templates/base.xhtml">

        <ui:define name="title">Recover your username</ui:define>
        <ui:define name="metadata">
            <f:metadata>
                <f:viewParam name="tok_id" value="#{userBean.token}" validator="resetValidator" />
            </f:metadata>
        </ui:define>

        <ui:define name="content">
           You should receive a email shortly with your new password in it.
        </ui:define>
    </ui:composition>
</h:body>

Is there any chance it has to do with me using templates?

base.xhtml

<h:body>
   <div id="wrapper">
      <f:view>
        <ui:insert name="metadata"/>
    <!-- Header Begin -->
       <ui:insert name="header">
              <ui:include src="/WEB-INF/templates/header.xhtml" />
       </ui:insert>
           <!-- Header End -->
        <div id="mainBox">
           <div id="main">
                <!-- Content Begin -->
            <ui:insert name="content" >
               <ui:include src="/WEB-INF/templates/content.xhtml" />
            </ui:insert>
            <!-- Content End -->
            </div>
         </div>
                 <div style="clear: both"></div>
        <!-- Footer Begin -->
        <ui:insert name="footer">
            <ui:include src="/WEB-INF/templates/footer.xhtml" />
        </ui:insert>
        <!-- Footer End -->
    </f:view>
       </div>
       <h:outputScript library="js" name="base.js" />
 </h:body>

content.xhtml

<h:body>
    <ui:composition></ui:composition>
</h:body>
Sixthpoint
  • 1,161
  • 3
  • 11
  • 34

1 Answers1

0

Use <f:viewParam> instead of manually grabbing the request parameter.

<f:viewParam name="token_id" value="#{bean.tokenId}" validator="yourTokenIdValidator" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Please elaborate "did not work" in developer's perspective instead of in enduser's perspective. – BalusC Aug 07 '13 at 14:55
  • The validator is not triggered, I have read your article as well. It does not throw any errors. I am writting statements to the console if the validator is triggered currently. I will include my base template – Sixthpoint Aug 07 '13 at 14:58
  • So, there's no request parameter with name `token_id`? If you'd like to cover that validation case as well, add `required="true"`. – BalusC Aug 07 '13 at 15:00
  • I had changed it to be tok_id, if I do not have that in the URL it does throw a error with the required set to true. However, there is still no reponse from the validator which I have change to be called "resetValidator" – Sixthpoint Aug 07 '13 at 15:21