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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:56:34+00:00 2026-05-13T20:56:34+00:00

I have one method in my managed bean which returns javascript as a string.

  • 0

I have one method in my managed bean which returns javascript as a string. When the method is invoked from head tag, it works fine. But when it is invoked from body, the browser instead of rendering the javascript writes it as it is. What can be the problem?

In my JSF page when i do #{IndexBean.EastRegionGadgets} in head it works fine but it doesn’t in body. It outputs the HTML as it is. Here is the code:

package BusinessFacade;

import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.component.html.HtmlOutputText;


enum REGION{
    NORTH,EAST,WEST;
}

class Gadget{
    private String gadgetCode = "";
    private REGION gadgetRegion = REGION.WEST;

    public Gadget(String gadgetCode, REGION gadgetRegion){
        this.gadgetCode = gadgetCode;
        this.gadgetRegion = gadgetRegion;
    }

    public String getGadgetCode() {
        return gadgetCode;
    }

    public void setGadgetCode(String gadgetCode) {
        this.gadgetCode = gadgetCode;
    }

    public REGION getGadgetRegion() {
        return gadgetRegion;
    }

    public void setGadgetRegion(REGION gadgetRegion) {
        this.gadgetRegion = gadgetRegion;
    }

}

@ManagedBean(name="IndexBean")
@RequestScoped
public class IndexBean {
    ArrayList<Gadget> _list;
    public IndexBean() {

    }

    @PostConstruct
    public void initialize(){
        _list = new ArrayList<Gadget>();
        Gadget objGadget = new Gadget("<script type='text/javascript' src='http://cdn.widgetserver.com/syndication/subscriber/InsertWidget.js'></script><script>if (WIDGETBOX) WIDGETBOX.renderWidget('78d12c15-dc87-42f2-a78a-3f62a91a119a');</script><noscript>Get the <a href='http://www.widgetbox.com/widget/crystal-clock'>Crystal Clock</a> widget and many other <a href='http://www.widgetbox.com/'>great free widgets</a> at <a href='http://www.widgetbox.com'>Widgetbox</a>! Not seeing a widget? (<a href='http://docs.widgetbox.com/using-widgets/installing-widgets/why-cant-i-see-my-widget/'>More info</a>)</noscript>",REGION.WEST);
        _list.add(objGadget);

        objGadget = new Gadget("<script type='text/javascript' src='http://cdn.widgetserver.com/syndication/subscriber/InsertWidget.js'></script><script>if (WIDGETBOX) WIDGETBOX.renderWidget('1ccc3dee-8266-4b84-8191-13a4bf584d0c');</script><noscript>Get the <a href='http://www.widgetbox.com/widget/custom-clock'>Shiny Clock</a> widget and many other <a href='http://www.widgetbox.com/'>great free widgets</a> at <a href='http://www.widgetbox.com'>Widgetbox</a>! Not seeing a widget? (<a href='http://docs.widgetbox.com/using-widgets/installing-widgets/why-cant-i-see-my-widget/'>More info</a>)</noscript>",REGION.EAST);
        _list.add(objGadget);



    }

    public String getWestRegionGadgets(){
        HtmlOutputText objHtmlOutputText = new HtmlOutputText();
        String strGadgets = "";
        for(Gadget objGadget:_list ){
            if(objGadget.getGadgetRegion() == REGION.WEST){
                strGadgets += objGadget.getGadgetCode();
            }
        }
        return strGadgets;

    }

    public String getEastRegionGadgets(){

        String strGadgets = "";
        for(Gadget objGadget:_list ){
            if(objGadget.getGadgetRegion() == REGION.EAST){
                strGadgets += objGadget.getGadgetCode();
            }
        }
        return strGadgets;

    }


}
  • 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-05-13T20:56:34+00:00Added an answer on May 13, 2026 at 8:56 pm

    In my JSF page when i do #{IndexBean.EastRegionGadgets} in head it works fine but it doesn’t in body. It outputs the HTML as it is.

    I suppose you’re using <h:outputText> in body to output the HTML. As per the documentation it by default escapes HTML. You need to set its escape attribute to false.

    <h:outputText value="#{bean.html}" escape="false" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating a class that will have one public method, which returns a value
I have one method on JSF Managed Bean, i want after user call method,
I have one method with one letter(string\char?) as argument and one word active at
I have one combobox on the window form and I have one method which
i have one setinterval method which call php script every 3 sec to check
I have class which have one public method Start , one private method and
I have a session bean that uses Bean managed txns. This bean has one
I am facing an issue where I have one method which is calling another
I have one method that opens a file and passes off to another function
I have a project with a lot of panels. I have one method that

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.