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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:19:10+00:00 2026-06-17T11:19:10+00:00

PROBLEM: The PrimeFaces p:focus tag is not focusing . -I.e., when the xhtml page

  • 0

PROBLEM:

The PrimeFaces “p:focus” tag is not focusing.
-I.e., when the xhtml page is presented to the user, no input fields are in focus.

QUESTION:

Why not? How can I get “p:focus” to work properly in this simple app?

(NOTE: using Java 6, Mojarra v2.1.11, PrimeFaces v3.4.2)

index.jsp

<?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">
<html 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:c="http://java.sun.com/jsp/jstl/core"
      xmlns:p="http://primefaces.org/ui">
    <f:view contentType="text/html">
        <h:head>
            <title>testcal2 - index.xhtml</title>
            <meta charset="utf-8" />
        </h:head>
        <h:body>
            <h:form id="queryForm">

                <f:event type="postValidate" listener="#{testBean.validate}" />

                <h:panelGroup id="msgsx">
                    <p:messages showSummary="true"/>
                </h:panelGroup>

                <p:panel id="queryPanel"  header="Test p:focus..." style="width:100%;">

                    <p:focus context="queryPanel"/>

                    <h:panelGroup id="msgs" style="height:1.5em; text-align: center;display:block">
                        <p:message id="lastName_msg"    for="lastName"     style="display:none;" showSummary="false"/>
                        <p:message id="birthDate_msg"   for="birthDate"    style="display:none;" showSummary="false"/>
                        <p:message id="startDate_msg"   for="startDate"    style="display:none;" showSummary="false"/>
                    </h:panelGroup>

                    <h:panelGroup id="querypanelgroup" style="display:inline-block;">

                        <h:panelGroup>
                            <h:panelGroup style="text-align:right;vertical-align:middle;display:inline-block;width:150px">
                                <p:outputLabel style="margin-right: 5px;"  value="Last Name:" for="lastName"/>
                            </h:panelGroup>
                            <h:panelGroup style="margin-left: 4px; vertical-align:middle;display:inline-block;width:250px;">
                                <p:inputText
                                    id="lastName"
                                    value="#{testBean.parmMap['lastName']}"
                                    requiredMessage="last name required"
                                    size="95"
                                    maxlength="95"
                                    onfocus="$('#queryForm\\:msgs > div').hide();$('#queryForm\\:msgs > div').eq(0).show();return false;" >
                                </p:inputText>
                            </h:panelGroup>
                        </h:panelGroup>

                        <br/>
                        <br/>

                        <h:panelGroup>
                            <h:panelGroup style="text-align:right;vertical-align:middle;display:inline-block;width:150px">
                                <p:outputLabel style="margin-right: 5px;"  value="Birth Date:" for="birthDate"/>
                            </h:panelGroup>
                            <h:panelGroup style="margin-left: 4px; vertical-align:middle;display:inline-block;width:250px;">
                                <p:inputText
                                    id="birthDate"
                                    value="#{testBean.parmMap['birthDate']}"
                                    requiredMessage="birth date required"
                                    converter="dpConverter"
                                    styleClass="datePicker"
                                    onfocus="$('#queryForm\\:msgs > div').hide();$('#queryForm\\:msgs > div').eq(1).show();$(this).mask('99/99/9999');return false;">
                                    <p:ajax event="change" process="@this" update="@this"/>
                                </p:inputText>
                            </h:panelGroup>
                        </h:panelGroup>

                        <br/>
                        <br/>

                        <h:panelGroup>
                            <h:panelGroup style="text-align:right;vertical-align:middle;display:inline-block;width:150px">
                                <p:outputLabel style="margin-right: 5px;"  value="Start Date:" for="startDate"/>
                            </h:panelGroup>
                            <h:panelGroup style="margin-left: 4px; vertical-align:middle;display:inline-block;width:250px;">
                                <p:inputText
                                    id="startDate"
                                    value="#{testBean.parmMap['startDate']}"
                                    requiredMessage="start date required"
                                    converter="dpConverter"
                                    styleClass="datePicker"
                                    onfocus="$('#queryForm\\:msgs > div').hide();$('#queryForm\\:msgs > div').eq(2).show();$(this).mask('99/99/9999');return false;">
                                    <!-- optional to populate another field with same value...
                                    onchange="$('...hashSymbolHere...queryForm\\:endDate').val($(this).val());">
                                    -->
                                    <p:ajax event="change" process="@this" update="@this"/>
                                </p:inputText>
                            </h:panelGroup>
                        </h:panelGroup>

                        <br/>
                        <br/>

                        <p:commandButton
                            id="submit"
                            value="Submit"
                            oncomplete="applyDatePicker();"
                            type="submit"
                            update="@form"
                            process="@form"
                            action="#{testBean.submitQuery}"
                            style="width:150px;"
                            styleClass="button"/>

                        <p:commandButton
                            value="Reset"
                            update="@form"
                            onclick="location.reload();return true;"
                            process="@this"
                            actionListener="#{testBean.reset}"
                            immediate="true"
                            ajax="false"/>

                    </h:panelGroup>
                </p:panel>
            </h:form>

            <h:outputStylesheet library="styles"    name="query.css"      />
            <h:outputScript      library="primefaces" name="/jquery/jquery.js" />
            <h:outputScript      library="primefaces" name="/jquery/plugins/ui/jquery-ui.custom.js" />
            <h:outputScript     library="primefaces" name="/jquery/plugins/inputmask/maskedinput.js" />
            <h:outputScript      library="js" name="index.js" target="head" />

        </h:body>
    </f:view>
</html>

index.js

$(document).ready(function()
{
    applyDatePicker();
});


function applyDatePicker(){

    $('.datePicker').datepicker(
    {
        showOn: 'button',
        buttonText: "Choose",
        showButtonPanel: true,
        showOptions: {direction: 'up'},
        changeYear: true,
        changeMonth: true,
        yearRange: "c-120:c+0"
    });
}

TestBean.java

package aaa.bbb.ccc.war;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.LinkedHashMap;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIForm;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.event.ComponentSystemEvent;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Component("testBean")
@Scope("request")
public class TestBean implements Serializable
{
    public TestBean()
    {
        parmMap = this.getParmMap();
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("parmMap", parmMap);
    }

    public void reset(ActionEvent event)
    {
        LinkedHashMap<String, Object> m = new LinkedHashMap<String, Object>();
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("parmMap");
        setParmMap(m);
    }

    public String submitQuery()
    {
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove("hitlistData");

        if (this.getParmMap().isEmpty())
        {
            return "";
        }

        return "/page2.xhtml?faces-redirect=true";
    }

    private static LinkedHashMap<String, Object> parmMap;
    public LinkedHashMap<String, Object> getParmMap()
    {
        LinkedHashMap<String, Object> map = (LinkedHashMap<String, Object>) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("parmMap");

        if (null == map)
        {
            map = new LinkedHashMap<String, Object>();
        }
        return map;
    }

    public void setParmMap(LinkedHashMap<String, Object> map)
    {
        parmMap = map;
        FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put("parmMap", parmMap);
    }
    private static SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");

    public void validate(ComponentSystemEvent e) throws ParseException
    {
        LinkedHashMap parmMap = this.getParmMap();
        UIForm queryForm = (UIForm) e.getComponent();
        FacesContext fc = FacesContext.getCurrentInstance();

        UIInput lastName_c = (UIInput) queryForm.findComponent("lastName");
        String lastName = (String) (lastName_c.getValue());

        UIInput birthDate_c = (UIInput) queryForm.findComponent("birthDate");
        String birthDate = (String) birthDate_c.getValue();

        UIInput startDate_c = (UIInput) queryForm.findComponent("startDate");
        String startDate = (String) startDate_c.getValue();

        try
        {
            if (null != lastName && lastName.trim().length() > 0)
            {
                if (null == birthDate || birthDate.length() < 1)
                {
                    birthDate_c.setValid(false);
                    fc.addMessage(birthDate_c.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, birthDate_c.getRequiredMessage(), birthDate_c.getRequiredMessage()));
                }
                else
                {
                    birthDate_c.setValid(true);
                }
            }
            else
            {
                birthDate_c.setValid(true);
            }

            if (null == startDate || startDate.trim().length() < 1)
            {
                startDate_c.setValid(false);
                fc.addMessage(startDate_c.getClientId(), new FacesMessage(FacesMessage.SEVERITY_ERROR, startDate_c.getRequiredMessage(), startDate_c.getRequiredMessage()));
            }
            else
            {
                startDate_c.setValid(true);
            }

            if (fc.getMessageList().size() > 0)
            {
                fc.renderResponse();
            }
        }
        catch (Exception e1)
        {
            e1.printStackTrace();
        }
    }
}
  • 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-17T11:19:12+00:00Added an answer on June 17, 2026 at 11:19 am

    It’s because you’re returning false on focus here:

    <p:inputText
        ...
        onfocus="$('#queryForm\\:msgs > div').hide();$('#queryForm\\:msgs > div').eq(0).show();return false;" >
    </p:inputText>
    

    Returning false causes the event’s default behaviour to be blocked.

    To fix your problem, simply remove return false; from onfocus attribute of the input component.

    <p:inputText
        ...
        onfocus="$('#queryForm\\:msgs > div').hide();$('#queryForm\\:msgs > div').eq(0).show();" >
    </p:inputText>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working with MyFaces/Primefaces and I have a problem to get information using
can I base the p:dataTable (primefaces) width on its containing string length? Problem is:
I'm trying to use primefaces <p:dialog> combined with <p:commandButton> . In my .xhtml page
I am experiencing a problem with Ajax and PrimeFaces. What the page should do
I have a problem with java primefaces, I have my xhtml as follows; <p:layoutUnit
i've problem when wanna implement jsf 2.0, primefaces 3.1.1 and springframework 3.0.2, i can't
One more question concerning JSF.Particularly, Primefaces. Have following problem with ajax update of elements
I have problem to let user know about exceptions occurred in PrimeFaces LazyDataModel#load method.
I have a simple problem. I have a Primefaces Datatable. When the user clicks
Can I use jsf component libraries(primefaces) with spring mvc .I have problem with client

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.