Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Java Module 23

Jakarta Faces (JSF): component-based web UIs interview questions

Interview questions on “Jakarta Faces (JSF): component-based web UIs”: warm-ups, then what each harder question tests and how a good answer starts.

11 questions: 3 warm-ups and 8 with model answers · Levels: Fresher to senior

Warm-up questions

Short questions with short answers, each answered in full.

  1. Fresher

    Why does a Faces application deployed on Tomcat carry Mojarra and Weld in its WAR?

    Answered in the lesson Jakarta Faces 4.1: a first Facelets app

  2. Fresher

    Name the six phases of the Faces life cycle in order. Which of them does the first GET of a page run, and why?

    Answered in the lesson The Faces life cycle, phase by phase

  3. Fresher

    What is the difference between a converter and a validator in Faces, and in which phase does each run?

    Answered in the lesson Faces converters, validators and events

Questions with model answers

What each question tests, the first step of a good answer and the follow-ups to expect.

  1. Fresher to mid

    A Faces page on Tomcat renders normally, but the first post answers HTTP 500 with "Target Unreachable, identifier [visitor] resolved to null". How do you find the cause, and why did the page itself load without an error?

    What it tests
    Reading an Expression Language error, how CDI discovers beans on Tomcat, and why reading an expression tolerates a missing bean while writing one does not.
    First step
    Notice that only the post failed. Rendering reads the expression, and an unknown name reads as null; storing the posted value needs a real object. So the question is why no bean named visitor exists, and Tomcat's start-up log is the first place to look.
    Follow-ups

    From the lesson Jakarta Faces 4.1: a first Facelets app

    Model answer, Pro. Model answers open with any pass; prices are in the notice on this page.

    Opening the model answers with your pass…

    Model answers open with any MySmartCoPilot pass.

    • Pro pass · 1 week₹79$2.99
    • 30 days₹179$5.99
    • 1 year₹1,699$45

    One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

    It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  2. Mid to senior

    You inherit a JSF 2.2 application: javax.faces imports, @ManagedBean beans, pages with xmlns.jcp.org namespaces and a FacesServlet mapped to *.jsf. It must move to Faces 4.1 on Tomcat 11. What breaks, in which order do you fix it, and how do you prove the move worked?

    What it tests
    What Faces 3.0 and 4.0 renamed and removed, planning a migration in steps that each build, and proving it with tests that post forms rather than by looking at pages.
    First step
    Sort the changes by where they come from: the server (Tomcat 11 needs Mojarra, Weld and beans.xml in the WAR), the javax-to-jakarta rename of Faces 3.0, the removal of managed beans and JSP views in Faces 4.0, the namespace rename, and the servlet mapping.
    Follow-ups

    From the lesson Jakarta Faces 4.1: a first Facelets app

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 4 minutes
  3. Fresher to mid

    On a form with a name and a semester, a user types a valid name and an out-of-range semester. After the error message, the debugger shows that the bean's name is still null, and a colleague files a bug against Faces. Explain what happened, and when it matters.

    What it tests
    Knowing that Update Model Values runs for the whole form or not at all, where the submitted text lives meanwhile, and what that means for code and for users.
    First step
    Find the phase where the request stopped. The semester failed in Process Validations, and Faces jumped to Render Response, so Update Model Values never ran for any field. Then ask where the name that the user still sees comes from, since it is not in the bean.
    Follow-ups

    From the lesson The Faces life cycle, phase by phase

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  4. Mid

    A Cancel button has immediate="true", yet on one form pressing it shows "Value is required" next to a field. On the other forms it behaves. What do you look for, and how do you make Cancel reliable everywhere?

    What it tests
    What immediate does on a button and on an input, reading the order of a request, and choosing between a post, a redirect and a GET for Cancel.
    First step
    Compare that form with the others. An immediate button skips Process Validations, so the message must come from a field that is validated in Apply Request Values, the phase in which the button acts: look for an input marked immediate="true".
    Follow-ups

    From the lesson The Faces life cycle, phase by phase

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  5. Mid to senior

    Users who leave a form open over lunch get an HTTP 500 page with ViewExpiredException when they press Save. Explain what happened, and compare the ways to fix it, with what each one costs.

    What it tests
    Where server-side view state lives and what ends it, how client-side state differs, with numbers, and how an application fails gracefully.
    First step
    Start from the lunch break: Tomcat's default session timeout is 30 minutes. With server-side state saving the hidden field only names a view stored in the session, so a post after the session ended finds nothing to restore.
    Follow-ups

    From the lesson The Faces life cycle, phase by phase

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  6. Mid

    A subject drop-down list depends on a branch list and is refreshed with f:ajax when the branch changes. Choosing works, but Submit fails with "Subject: Validation Error: Value is not valid". The backing bean is request-scoped. Explain the failure and fix it.

    What it tests
    How selection components validate their value against their items, when the model is updated, and how bean scopes interact with Ajax requests.
    First step
    Ask when the subject list checks the posted value: in Process Validations, against its items. Then ask what the items are at that moment: they come from the bean's branch, and a request-scoped bean has not been updated yet.
    Follow-ups

    From the lesson Faces converters, validators and events

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  7. Mid to senior

    Where would you put each rule in a Faces application, and why: a name of 3 to 20 characters; a semester of 1 to 8 on one form; a roll number that must not be registered yet; practical marks that need theory marks?

    What it tests
    Telling model rules from view rules, the cost of each validation mechanism, and how cross-field rules and rules that need services fit into the life cycle.
    First step
    Sort the rules by who must obey them. A rule that holds wherever the data is saved belongs to the model; a rule of one form belongs to its page; a rule that needs a database or two fields needs Java code that runs in Process Validations.
    Follow-ups

    From the lesson Faces converters, validators and events

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes
  8. Mid

    A validator declared with @FacesValidator(value = "uniqueRoll", managed = true) injects a service with @Inject. Its page now answers HTTP 500: "could not be resolved by CDI. Check that beans.xml is present", although beans.xml is there. What is wrong, and why does even the GET fail?

    What it tests
    How CDI discovers beans in annotated mode, what managed = true changes for validators and converters, and when Faces creates a validator.
    First step
    Read beans.xml rather than looking for it: bean-discovery-mode="annotated" makes CDI see only classes with a bean-defining annotation. Then check the validator class for one; @FacesValidator itself is not bean-defining.
    Follow-ups

    From the lesson Faces converters, validators and events

    Model answer, Pro.

    In the answer:

    • Model answer
    • Follow-up answers
    • Common mistakes
    • Rubric
    • Variants
    • about 3 minutes

All Java interview questions · The Java track

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.