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 8077035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:23:30+00:00 2026-06-05T15:23:30+00:00

I’m building a login form composite component. The page that uses it will pass

  • 0

I’m building a login form composite component. The page that uses it will pass an event handler that will validate the username and password. Usually (not using composite components) when we perform cross field validation via postValidate, the event handler has to lookup the fields’ components by name. It would be preferable for the validator not to do this, because these are inner details of the component that should be abstracted.

Any idea how I might get the converted values of the username and password fields in a postValidate handler without knowing the inner details of the composite component?

Update:
The point of this is not to avoid looking up components by name at all, but to be able to cross-field validate the composite component’s fields in a way that doesn’t require the using page and/or bean to know the inner details of the component.

  • 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-05T15:23:32+00:00Added an answer on June 5, 2026 at 3:23 pm

    This can be done. In the following code, take particular note of the postValidate event in the composite component and the postValidate method in the backing component. Notice how it resolves the MethodExpression attribute and invokes the passed-in method.

    Here’s the composite component:

    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:cc="http://java.sun.com/jsf/composite"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:p="http://primefaces.org/ui">
    
        <!-- Login form. -->
        <cc:interface componentType="com.example.LoginForm">
            <cc:attribute name="emailAddress" type="java.lang.String" required="true"/>
            <cc:attribute name="rememberMe" type="java.lang.Boolean" required="true"/>
            <cc:attribute name="checkCredentials"
                          method-signature="void checkCredentials(java.lang.String,java.lang.String,java.lang.String)"
                          shortDescription="Parameters are clientId, username and password. If credentials are invalid, attach a FacesMessage to the component specified by clientId."
                          required="true"/>
            <cc:attribute name="actionListener" method-signature="void actionListener()" required="true"/>
            <cc:attribute name="registerOutcome" type="java.lang.String" required="true"/>
            <cc:attribute name="recoverPasswordOutcome" type="java.lang.String" required="true"/>
            <cc:attribute name="headerTitle" type="java.lang.String" default="Sign In"/>
            <cc:attribute name="emailAddressLabel" type="java.lang.String" default="Email address:"/>
            <cc:attribute name="passwordLabel" type="java.lang.String" default="Password:"/>
            <cc:attribute name="rememberMeLabel" type="java.lang.String" default="Stay signed in on this machine"/>
            <cc:attribute name="loginLabel" type="java.lang.String" default="Sign In"/>
            <cc:attribute name="recoverPasswordLabel" type="java.lang.String" default="Forgot password?"/>
            <cc:attribute name="emailAddressRequiredMessage" type="java.lang.String" default="Email address required"/>
            <cc:attribute name="passwordRequiredMessage" type="java.lang.String" default="Password required"/>
            <cc:attribute name="registerLabel" type="java.lang.String" default="Register"/>
        </cc:interface>
    
        <cc:implementation>
            <h:outputStylesheet library="components/example/login-form" name="style.css"/>
    
            <div id="#{cc.clientId}">
                <h:form id="form">
    
                    <f:event type="postValidate" listener="#{cc.postValidate}"/>
    
                    <div style="margin-top:10px;">
                        <p:panel header="#{cc.attrs.headerTitle}" styleClass="loginPanel">
                            <div class="login-form_errorContainer">
                                <p:messages rendered="#{facesContext.maximumSeverity.ordinal ge 2}"/>
                            </div>
                            <h:panelGrid columns="3">
                                <h:outputText styleClass="login-form_label" value="#{cc.attrs.emailAddressLabel}"/>
                                <h:panelGroup styleClass="login-form_cell">
                                    <h:inputText id="emailAddress"
                                                 value="#{cc.attrs.emailAddress}"
                                                 required="true"
                                                 requiredMessage="#{cc.attrs.emailAddressRequiredMessage}"
                                                 styleClass="login-form_field"
                                                 immediate="true"/>
                                </h:panelGroup>
                                <h:panelGroup/>
    
                                <h:outputText styleClass="login-form_label" value="#{cc.attrs.passwordLabel}"/>
                                <h:panelGroup styleClass="login-form_cell">
                                    <h:inputSecret id="password"
                                                   value="#{cc.attrs.password}"
                                                   required="true"
                                                   requiredMessage="#{cc.attrs.passwordRequiredMessage}"
                                                   styleClass="login-form_field"
                                                   immediate="true"/>
                                </h:panelGroup>
                                <h:link styleClass="login-form_link" value="#{cc.attrs.recoverPasswordLabel}" outcome="#{cc.attrs.recoverPasswordOutcome}"/>
    
                                <h:panelGroup/>
                                <p:selectBooleanCheckbox value="#{cc.attrs.rememberMe}" itemLabel="#{cc.attrs.rememberMeLabel}" immediate="true"/>
                                <h:panelGroup/>
    
                                <h:panelGroup/>
                                <h:panelGroup>
                                    <p:commandButton id="submitForm" value="#{cc.attrs.loginLabel}" actionListener="#{cc.attrs.actionListener}" update="form"/>
                                    <span class="login-form_or">or</span>
                                    <h:link styleClass="login-form_link" value="#{cc.attrs.registerLabel}" outcome="#{cc.attrs.registerOutcome}"/>
                                </h:panelGroup>
                                <h:panelGroup/>
                            </h:panelGrid>
                        </p:panel>
                    </div>
                </h:form>
            </div>
        </cc:implementation>
    </html>
    

    The backing component:

    @FacesComponent("com.example.LoginForm")
    public class LoginFormComponent extends UIInput implements NamingContainer
    {
        @Override
        protected Object getConvertedValue(FacesContext context, Object newSubmittedValue) throws ConverterException
        {
            UIInput emailAddressComponent = (UIInput) findComponent(EMAIL_ADDRESS_ID);
            UIInput passwordComponent = (UIInput) findComponent(PASSWORD_ID);
            String emailAddress = (String) emailAddressComponent.getValue();
            String password = (String) passwordComponent.getValue();
            return new LoginFormValue(emailAddress, password);
        }
    
        public void postValidate(ComponentSystemEvent e) {
            FacesContext ctx = getFacesContext();
    
            // Don't validate credentials if the username and/or password fields are invalid.
            if (!ctx.getMessageList(EMAIL_ADDRESS_ID).isEmpty() || !ctx.getMessageList(PASSWORD_ID).isEmpty())
            {
                return;
            }
    
            LoginFormValue value = (LoginFormValue) getConvertedValue(null, null);
            MethodExpression checkCredentials = (MethodExpression) getAttributes().get(CHECK_CREDENTIALS_ATTRIBUTE_NAME);
            checkCredentials.invoke(ctx.getELContext(), new Object[]{getClientId(), value.getEmailAddress(), value.getPassword()});
        }
    
        @Override
        public String getFamily()
        {
            return "javax.faces.NamingContainer";
        }
    
        public static final String CHECK_CREDENTIALS_ATTRIBUTE_NAME = "checkCredentials";
        public static final String EMAIL_ADDRESS_ID = "form:emailAddress";
        public static final String PASSWORD_ID = "form:password";
    }
    

    The LoginFormValue class for completeness:

    public class LoginFormValue
    {
        public LoginFormValue(String emailAddress, String password)
        {
            this.emailAddress = emailAddress;
            this.password = password;
        }
    
        public String getEmailAddress()
        {
            return emailAddress;
        }
    
        public String getPassword()
        {
            return password;
        }
    
        private String emailAddress;
        private String password;
    }
    

    The page that uses the login form:

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:p="http://primefaces.org/ui"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:ex="http://java.sun.com/jsf/composite/components/example">
        <h:head>
            <title></title>
        </h:head>
        <h:body>
            <ui:composition template="/WEB-INF/templates/myLayout.xhtml">
                <ui:define name="windowTitle">Sign In</ui:define>
                <ui:define name="body">
    
                    <ex:login-form emailAddress="#{loginBean.emailAddress}"
                                   rememberMe="#{loginBean.rememberMe}"
                                   checkCredentials="#{loginBean.checkCredentials}"
                                   actionListener="#{loginBean.submit()}"
                                   recoverPasswordOutcome="recover-password"
                                   registerOutcome="signup"/>
    
                </ui:define>
            </ui:composition>
        </h:body>
    </html>
    

    And finally, the page’s backing bean:

    @Named
    @RequestScoped
    public class LoginBean implements Serializable
    {
        public String getEmailAddress()
        {
            return emailAddress;
        }
    
        public void setEmailAddress(String emailAddress)
        {
            this.emailAddress = emailAddress;
        }
    
        public boolean isRememberMe()
        {
            return rememberMe;
        }
    
        public void setRememberMe(boolean rememberMe)
        {
            this.rememberMe = rememberMe;
        }
    
        /** Action listener for login-form. Called after validation passes. */
        public void submit()
        {
            User user = userDao.findByEmailAddress(emailAddress);
            userRequestBean.login(user.getUserId());
    
            // Remember me
            if (!rememberMe)
            {
                return;
            }
    
            // Handle rememberMe here (create a cookie, etc.)
        }
    
        /** Called by the backing component's postValidate event handler */
        public void checkCredentials(String clientId, String emailAddress, String password)
        {
            if (!securityEjb.checkCredentials(emailAddress, password))
            {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Incorrect email address/password", null);
                FacesContext ctx = FacesContext.getCurrentInstance();
                ctx.addMessage(clientId, message);
                ctx.renderResponse();
            }
        }
    
        private String emailAddress = "";
    
        private boolean rememberMe = true;
    
        @Inject
        private UserRequestBean userRequestBean;
    
        @EJB
        private SecurityEjb securityEjb;
    
        @EJB
        private UserDao userDao;
    
        @EJB
        private LoginCookieDao loginCookieDao;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.