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.
Warm-up questions
Short questions with short answers, each answered in full.
-
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
-
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?
-
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.
-
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
-
- Why did the GET not fail?
- Which causes give exactly this message?
- How would a test catch it before users do?
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.
Passes can’t be bought right now, so the model answers can’t be opened at the moment. If you have a pass, enter your licence key.
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
-
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
-
- Mojarra still renders the old namespaces. Why change them anyway?
- What replaces @ManagedProperty?
- Why does the *.jsf mapping become a security problem?
- How do you test the move?
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
-
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
-
- Where does the text in the fields come from, if not from the bean?
- When does this behaviour hurt, and how do you work with it?
- What would immediate on the name field change?
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
-
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
-
- Did the cancel action run at all?
- Why does the typed text stay in the form after Cancel?
- Which kind of Cancel cannot be stopped by any rule?
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
-
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
-
- Would client-side state saving fix it, and what does it cost?
- What should the user see instead of a 500 page?
- Can the same error appear without any timeout?
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
-
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
-
- Why did the Ajax request work?
- Which scope fixes it, and what does that scope cost?
- Could you fix it without changing the scope?
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
-
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
-
- Why not put every rule in Bean Validation?
- How does the cross-field rule read the other field?
- Where do the messages come from, and how do they name the field?
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
-
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
-
- Why did the GET of the page fail, not only the post?
- Which annotation fixes it, and why that one?
- Why not switch beans.xml to bean-discovery-mode="all"?
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