Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8900057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:00:46+00:00 2026-06-15T01:00:46+00:00

<ui:composition template=/WEB-INF/templates/base.xhtml xmlns=http://www.w3.org/1999/xhtml xmlns:ui=http://java.sun.com/jsf/facelets xmlns:h=http://java.sun.com/jsf/html xmlns:f=http://java.sun.com/jsf/core xmlns:p=http://primefaces.org/ui> <ui:define name=metadata> <f:metadata> <f:event type=preRenderView listener=#{resetPassword.loadUser} />

  • 0
<ui:composition template="/WEB-INF/templates/base.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:p="http://primefaces.org/ui">    
    <ui:define name="metadata">
        <f:metadata>
            <f:event type="preRenderView" listener="#{resetPassword.loadUser}" />
            <f:viewParam name="user" value="#{resetPassword.user}" />
        </f:metadata>
    </ui:define>

    <ui:define name="content">
        <h:form rendered="#{resetPassword.user != null}">
            <h:panelGrid class="form_panel" columns="2" width="596px">
                <h:outputLabel class="form_label" for="password" value="#{base['resetPassword.password']}" />
                <h:inputSecret class="form_inputText" id="password" value="#{resetPassword.password}">
                    <f:ajax event="keyup" execute="password" listener="#{resetPassword.validatePassword}" render="scorePanel complexity" />
                </h:inputSecret>

                (...) // Other labels and inputfields, no ajax
            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition> 

I have read about a lot of problems with preRenderView in combination with ajax-calls. The main problem I have come across is the postback issue.Though, in my case, ajax won’t fire at all with the preRenderView. Without the whole f:event-tag, my ajax-call does work correct.

resetPassword.loadUser() will set resetPassword.user, which is NOT null. I need to use the preRenderView instead of @PostConstruct in order to fill the f:viewParam. This param is needed when the form is submitted.

Why does my ajax-event break when <f:event type="preRenderView" /> is defined?

Note: <ui:insert name="metadata" /> in the template is located inside <h:head>.

Update

As BalusC commented, the issue is not visible in this part of the code.

public void loadUser(ComponentSystemEvent event) {
    if(!FacesContext.getCurrentInstance().isPostback()) {
        user = (hash != null) ? userService.getByIdAndPwdResetHash(userId, hash) : null;
    }
}

This code might return null but doesn’t (as my form is being loaded).

public void validatePassword(AjaxBehaviorEvent event) {
    System.out.println("Ajax works"); // Just for testing purposes so far
}

I don’t know what to add further, as this pretty much is all relevant code.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:00:47+00:00Added an answer on June 15, 2026 at 1:00 am

    This construct will fail when the #{resetPassword} is request scoped and the user property is not initialized during bean’s (post)construction.

    JSF will during apply request values phase namely re-evaluate the rendered attribute of an input component (this also includes all of its parent components) before processing the submitted value, as part of safeguard against tampered requests. In your case, the parent form is not rendered and thus all input components won’t be processed.

    You have basically 2 options:

    1. Make the bean @ViewScoped (or the CDI equivalent @ConversationScoped). This way it lives as long as you’re interacting with the same view (resp. conversation).

    2. Perform the initialization of user in (post)constructor. The pre render view is too late. As your bean is request scoped already, just use @ManagedProperty (or its homegrown CDI equivalent; Google has results on “@HttpParam”).

    See also:

    • commandButton/commandLink/ajax action/listener method not invoked or input value not updated – Point 5 applies to your case
    • @Inject to pass params to a CDI @Named bean via URL – Contains a concrete example of custom @HttpParam annotation as CDI substitution of JSF @ManagedProperty
    • ViewParam vs @ManagedProperty(value = "#{param.id}") – to understand the difference in its lifecycle better

    Unrelated to the concrete question, performing validation in an action(listener) method isn’t the right approach. Instead of <f:ajax listener>, use a normal Validator which you reference by input component’s validator attribute or a nested <f:validator>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I create a composition template: <ui:composition xmlns=http://www.w3.org/1999/xhtml xmlns:h=http://java.sun.com/jsf/html xmlns:f=http://java.sun.com/jsf/core xmlns:ui=http://java.sun.com/jsf/facelets xmlns:cs=http://java.sun.com/jsf/composite/composite> <h:panelGroup rendered=#{not empty
I have a template composition Button.xhtml which contains a <p:commandLink> : <ui:composition xmlns=http://www.w3.org/1999/xhtml xmlns:ui=http://java.sun.com/jsf/facelets
I have the following template (masterLayout.xhtml): <!DOCTYPE html> <html xmlns=http://www.w3.org/1999/xhtml xmlns:h=http://java.sun.com/jsf/html xmlns:ui=http://java.sun.com/jsf/facelets> <f:view contentType=text/html>
<html xmlns=http://www.w3.org/1999/xhtml xmlns:h=http://java.sun.com/jsf/html xmlns:ui=http://java.sun.com/jsf/facelets> <h:body> <title><ui:define name=title>Page 2</ui:define></title> <ui:composition template=template/common/commonLayout.xhtml> <ui:define name=content> This is
Here's my page: <html xmlns=http://www.w3.org/1999/xhtml xmlns:h=http://java.sun.com/jsf/html xmlns:cpanel=http://java.sun.com/jsf/composite/components/cpanel xmlns:f=http://java.sun.com/jsf/core xmlns:p=http://primefaces.prime.com.tr/ui xmlns:ui=http://java.sun.com/jsf/facelets> <h:head> <title></title> </h:head> <h:body>
In my .xhtml page, I have the following form: <ui:composition xmlns:ui=http://java.sun.com/jsf/facelets template=./../template/CustomerTemplate.xhtml xmlns:h=http://java.sun.com/jsf/html xmlns:f=http://java.sun.com/jsf/core
I've got a template in WEB-INF/templates/standardTemplate.xhtml In my Web Pages root, I've got an
Hi this is my folder structure: -Web Pages -WEB-INF -template.xhtml -gebruiker -index.xhtml -index.xhtml and
Consider a nested template: Base.xhtml: ... <h:outputText value=#{uiParamter}/> <ui:insert name=header/> ... etc. Layout.xhtml: <ui:composition
Have xhtml templ.xhtml layout. Include it to other .xhtml like: <ui:composition template=/template/templ.xhtml> Define conditionals

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.