6 Replies Latest reply on Dec 27, 2008 8:31 PM by ZJ DA

    Auto Submit

    ZJ DA Newbie

      Hi,

      I have a login page and another application has a link to the page. The link includes user name and password. I want the login page to check for user name and password. If they are not empty, it will automatically submit to #{backbean.login} with no need of button clicking. I don't want to use the servlet filter since it is not neccessary for all requests to go through the filter. Any suggestion?

      Thanks,
      -ZJ

        • 2. Re: Auto Submit
          Thomas Kessler Newbie

          Whoops my markup didn't show, here:

          <body onload="doSomeThing()">


          • 3. Re: Auto Submit
            ZJ DA Newbie

            Thank you for your suggestion. Actually, I did use the onload as the following code. However, it did not work. IE keeps refreshing and FF does nothing. I set a break point in #{sessionInfo.loginAction}, but it never stops, meaning no request sends to the method. Any idea?

            -ZJ


            <body style="margin: 0px;" onload="document.loginForm.submit();">
            <f:view>
             <a4j:include id="header" viewId="/pages/header.xhtml" />
             <h:form id="loginForm">
             <h:panelGrid columns="3" cellspacing="5px" cellpadding="5px">
             <h:outputLabel value="User Name:" for="username" />
             <h:inputText id="username" value="#{sessionInfo.username}" />
             <h:message for="username" errorClass="ValidateError" />
             <h:outputLabel value="Password:" for="password" />
             <h:inputSecret id="password" value="#{sessionInfo.password}" />
             <h:message for="password" errorClass="ValidateError" />
             <rich:spacer></rich:spacer>
             <h:commandButton value="Login" action="#{sessionInfo.loginAction}" />
             <rich:spacer></rich:spacer>
             </h:panelGrid>
             </h:form>
             <a4j:include id="footer" viewId="/pages/footer.xhtml" />
            </f:view>
            


            • 4. Re: Auto Submit
              Thomas Kessler Newbie

              you may have to specify: "type=submit" on the "h:commandButton". i would also check the source of the page after it renders. you could also tie a "a4j:jsFunction" to the "loginAction" and call then call the javascript method defined in the "a4j:jsFunction" component.

              • 5. Re: Auto Submit
                ZJ DA Newbie

                Thanks. I added "type=submit", but it did not help. Here is the source of the page:

                <body style="margin: 0px;" onload="javascript:document.loginForm.submit();">
                ...
                <form id="loginForm" name="loginForm" method="post" action="/test/faces/pages/authentication.jsp" enctype="application/x-www-form-urlencoded">
                ...
                <input type="submit" name="loginForm:j_id51" value="Login" />
                


                I will try a4j:jsFunction as you suggested.

                Again, thank you and happy holiday.
                -ZJ

                • 6. Re: Auto Submit
                  ZJ DA Newbie

                  I looked at a4j:jsFunction and I think that it is not good for this case. Instead, I created a AuthenticationServlet which does the job.

                  Thank you and happy New Year.
                  -ZJ

                   if (request.getSession().getAttribute(UserSessionManager.USER_SESSION) == null) {
                   String userName = request.getParameter("username");
                   String password = request.getParameter("password");
                   if( userName == null || userName.length() == 0 || password == null || password.length() == 0 ) {
                   response.sendRedirect("faces/pages/authentication.jsp");
                   return;
                   } else {
                   try {
                   ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
                   IApi api = (IApi) context.getBean("api");
                   api.authenticate(userName, password, request);
                   } catch (ApiException ae) {
                   ae.printStackTrace();
                   }
                   }
                   }
                   response.sendRedirect("faces/pages/main.jsp");