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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:28:00+00:00 2026-05-23T19:28:00+00:00

In our JSF 2.0 application at work, we include several javascript files via <h:outputscript>

  • 0

In our JSF 2.0 application at work, we include several javascript files via <h:outputscript>.

<h:outputScript library="javascript" name="DoStuff.js"/>

The resulting html references them as ‘text/javascript’.

<script type="text/javascript" src="/mycontext/javax.faces.resource/DoStuff.js.jsf?ln=javascript"></script>

According to this question, “text/javascript” is obsolete, what’s more, htmlunit complains about the type rather verbosely.
Of course, everything works just fine and I could shut off htmlunit’s logging, but I’d rather have JSF generate the correct type.

Is there a way to override the type chosen by <h:outputscript>?

  • 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-23T19:28:01+00:00Added an answer on May 23, 2026 at 7:28 pm

    This is hardcoded in the default renderer of the <h:outputScript>. Assuming that you’re using Mojarra, it’s the com.sun.faces.renderkit.html_basic.ScriptRenderer. According to the source, the type attribute is been set in the startElement method. You could just override it:

    public class ExtendedScriptRenderer extends ScriptRenderer {
    
        @Override
        protected void startElement(ResponseWriter writer, UIComponent component) throws IOException {
            writer.startElement("script", component);
            writer.writeAttribute("type", "application/javascript", "type");
        }
    
    }
    

    Or if you want to provide the enduser the possibility to specify the type attribute itself and default to application/javascript when unspecified:

    public class ExtendedScriptRenderer extends ScriptRenderer {
    
        @Override
        protected void startElement(ResponseWriter writer, UIComponent component) throws IOException {
            writer.startElement("script", component);
            String type = (String) component.getAttributes().get("type");
            if (type == null) type = "application/javascript";
            writer.writeAttribute("type", type, "type");
        }
    
    }
    

    To get it to run, register it as follows in faces-config.xml:

    <render-kit>
        <renderer>
            <component-family>javax.faces.Output</component-family>
            <renderer-type>javax.faces.resource.Script</renderer-type>
            <renderer-class>com.example.ExtendedScriptRenderer</renderer-class>
        </renderer>
    </render-kit>
    

    There’s by the way also the nice @FacesRenderer annotation which should work as follows

    @FacesRenderer(componentFamily="javax.faces.Output", rendererType="javax.faces.resource.Script")
    public class ExtendedScriptRenderer extends ScriptRenderer {
    
        // ...
    }
    

    However, when it’s already been definied by a standard renderer (the ScriptRenderer!), then the custom one will fail to override it by a @FacesRenderer. See also issue 1748.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our application is JSF , hibernate & Spring. Currently the url is in following
In a certain page of our JSF application, the user sees a table listing
In our application we use jsf,we have to redirect the user to home page
It's our first JSF app, and I'm in the middle of integrating our graphic
On our new platform we are utilizing JSF. Our WebTrends tags are not reflecting
Our application is interfacing with a lot of web services these days. We have
Our security manager dynamically inserts a bit of javascript at the top of every
I am still migrating to Glassfish instead of Jetty for our application servers and
I have been investigating a JSF upgrade on our existing web apps that are
Our application has a lot of .NET assemblies, which up until now, has not

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.