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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:27:36+00:00 2026-06-05T12:27:36+00:00

I have created a page where I want to get the JSON response from

  • 0

I have created a page where I want to get the JSON response from a JSF page,
but when i try to get page it shows me whole html page.

<html xmlns="http://www.w3.org/1999/xhtml"><head>
        <title>Facelet Title</title></head><body>
[{"value": "21", "name": "Mick Jagger"},{"value": "43", "name": "Johnny Storm"},{"value": "46", "name": "Richard Hatch"},{"value": "54", "name": "Kelly Slater"},{"value": "55", "name": "Rudy Hamilton"},{"value": "79", "name": "Michael Jordan"}]

</body></html>
  • 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-05T12:27:38+00:00Added an answer on June 5, 2026 at 12:27 pm

    JSF is a MVC framework generating HTML, not some kind of a REST web service framework. You’re essentially abusing JSF as a web service. Your concrete problem is simply caused by placing <html> tags and so on in the view file yourself.

    If you really insist, then you can always achieve this by using <ui:composition> instead of <html>. You also need to make sure that the right content type of application/json is been used, this defaults in JSF namely to text/html.

    <ui:composition
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:ui="http://java.sun.com/jsf/facelets">
        <f:event type="preRenderView" listener="#{bean.renderJson}" />
    </ui:composition>
    

    with

    public void renderJson() throws IOException {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        ExternalContext externalContext = facesContext.getExternalContext();
        externalContext.setResponseContentType("application/json");
        externalContext.setResponseCharacterEncoding("UTF-8");
        externalContext.getResponseOutputWriter().write(someJsonString);
        facesContext.responseComplete();
    }
    

    But I strongly recommend to look at JAX-RS or JAX-WS instead of abusing JSF as a JSON web service. Use the right tool for the job.

    See also:

    • How to implement JAX-RS RESTful service in JSF framework
    • Servlet vs RESTful
    • What is the need of JSF, when UI can be achieved from CSS, HTML, JavaScript, jQuery?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a page on Wiki and I want to make the contents
I have created custom posts and I want one page in my site to
I have created a Page Tab Facebook App where I want to display different
I have these six static divs in my page and I want to create
I have created a page Education For All in facebook. In my website i
I have created a page on my site where users can post directly to
I have created login page forced login in several pages. Now i need to
I have created a page with a static image positioned to the ride side
I have created a custom post type named People. I have created a page
So, I have created a page with 3 frames, top, left and right where

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.