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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:31:02+00:00 2026-06-13T07:31:02+00:00

I was validating my form, and I can get value of textbox but always

  • 0

I was validating my form, and I can get value of textbox but always retrieve null value in
the uiClass variable (Error: java.lang.NullPointerException):
Any suggest ?

Exception:

WARNING: /jsf/report/Edit.xhtml @39,99 listener="#{studentController.validate}": java.lang.NullPointerException
javax.el.ELException: /jsf/report/Edit.xhtml @39,99 listener="#{studentController.validate}": java.lang.NullPointerException
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:111)
    at com.sun.faces.facelets.tag.jsf.core.DeclarativeSystemEventListener.processEvent(EventHandler.java:131)
    at javax.faces.component.UIComponent$ComponentSystemEventListenerAdapter.processEvent(UIComponent.java:2464)
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:106)
    at com.sun.faces.application.ApplicationImpl.processListeners(ApplicationImpl.java:2168)
    at com.sun.faces.application.ApplicationImpl.invokeComponentListenersFor(ApplicationImpl.java:2116)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:288)
    at com.sun.faces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:246)

Caused by: java.lang.NullPointerException
    at entities.StudentController.validate(StudentController.java:163)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)  

@ManagedBean()
@SessionScoped
public class StudentController implements Serializable {
    public void validate(ComponentSystemEvent event) {
        FacesContext fc = FacesContext.getCurrentInstance();
        UIComponent components = event.getComponent();

        UIInput uiName = (UIInput) components.findComponent("frmStudent:name");
        UIInput uiClass = (UIInput) components.findComponent("frmStudent:myclass");

        String name = uiName.getLocalValue().toString();
        String myclass = uiClass.getLocalValue().toString();

        if (name.equals("") || name == null || name.isEmpty()) {
            FacesMessage msgName = new FacesMessage("Please enter name !");
            fc.addMessage(components.getClientId(), msgName);
            fc.renderResponse();
        } else if (myclass.equals("") || myclass == null || myclass.isEmpty()) {
            FacesMessage msgClass = new FacesMessage("Please select a class !");
            fc.addMessage(components.getClientId(), msgClass);
            fc.renderResponse();
        }
    }
}

My XHTML

<h:message for="textPanel" style="color:red;" />
<h:panelGrid id="textPanel" columns="4">
  <f:event listener="#{studentController.validate}" type="postValidate" />
    <h:inputText id="name" value="#{studentController.selected.name}" size="20" />
    <h:selectOneMenu id="myclass" value="#{studentController.selected.myclass}" style="width:180px;">
        <f:selectItem itemLabel="Select ..." itemValue="#{null}" noSelectionOption="true" />
        <f:selectItems value="#{studentController.classItems}"/>
    </h:selectOneMenu>
</h:panelGrid>
  • 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-13T07:31:03+00:00Added an answer on June 13, 2026 at 7:31 am

    Why dont you use required attributes?

     <h:inputText id="name" required="true" requiredMessage="Please enter name !" value="#{studentController.selected.name}" size="20" />
        <h:selectOneMenu id="myclass" required="true" requiredMessage="Please select a class !" value="#{studentController.selected.myclass}" style="width:180px;">
            <f:selectItem itemLabel="Select ..." itemValue="#{null}" noSelectionOption="true" />
            <f:selectItems value="#{studentController.classItems}"/>
        </h:selectOneMenu>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I can get the old value through UIInput#getValue() . But in many
I'm validating a form via an XML schema, and I get this error: [facet
How can I get the value of an HTML form to pass to JavaScript?
I have an issue in that a Symfony2 form can pass validation but still
I am validating a form and when there is any error in the textfield
Basically I am validating a form, I am collecting the error messages and I
I have a form where I can upload logos a plenty. I'm validating files
i have this simple JS for validating form, can someone tell me how to
I'm practicing form validation with JavaScript but when I try to retrieve the data
I'm validating my form, just checking if in the fields where a number should

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.