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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:25:13+00:00 2026-06-17T01:25:13+00:00

I am trying to do some custom lightweight JSF component binding. In my bean

  • 0

I am trying to do some “custom lightweight” JSF component binding. In my bean (controlling some JSF page) i’m declaring a HahsMap where keys ranging over my h:inputText ids (appearing in the page) map these ids to custom HInputText<T> objects (T in the example given below is Long). Then i am using HInputText<T> objects to hold a subset of corresponding h:inputText attributes : value supposed to be of type T, rendered, required, etc. In this direction fields from the HInputText<T> objects give values to the h:inputText attributes.

My problem is that when using such an h:inputText inside a h:form, JSF validation does not take place : i can type alphanumeric chars in the h:inputText (supposed to hold a Long value) and my form submits without showing any errors. Note that required and rendered attributes are managed correctly (since required is set to true, i have an error when i leave the h:inputText field empty) and that when i try to display back the value of the h:inputText in the page using some h:outputText the alphanumeric chars are displayed.

Is there some trick to make JSF validation work without having to explicitly define a custom Validator for each h:inputText?

HInputText.class:

public class HInputText<T>
{
    private String id;
    private boolean rendered;
    private boolean required;
    private T value;
    private Class<T> myClass;

    // getters and setters for all fields

    public HInputText(Class<T> myClass, String id)
    {
        this.myClass = myClass;
        this.id = id;
        this.rendered = true;
        this.required = true;
    }
}

Code snippet from my Managed Bean :

@ManagedBean(name="saisieController")
@SessionScoped
public class SaisieController
{
    ...
    private HashMap<String,HInputText<Long>> htagLongInputTexts;

    public HashMap<String, HInputText<Long>> getHtagLongInputTexts()
    {
        return htagLongInputTexts;
    }

    public void setHtagLongInputTexts(HashMap<String, HInputText<Long>> hLongInputTexts)
    {
        this.htagLongInputTexts = hLongInputTexts;
    }

    public void addHtagLongInputText(HInputText<Long> hLongInputText)
    {
        getHtagLongInputTexts().put(hLongInputText.getId(), hLongInputText);
    }

    public HInputText<Long> getHtagLongInputText(String hLongInputTextId)
    {
        return(getHtagLongInputTexts().get(hLongInputTextId));
    }



    @PostConstruct
    public void init()
    {
        setHtagLongInputTexts(new HashMap<String, HInputText<Long>>());
        addHtagLongInputText(new HInputText<Long>(Long.class, "HIT_LongTestHIT"));
    }

    public String doNothing()
    {
        return null;
    }
}

and finally a snippet from my jsf page:

<h:form>
    <h:inputText
        id = "HIT_LongTestHIT"
        value = "#{saisieController.htagLongInputTexts['HIT_LongTestHIT'].value}"
        rendered = "#{saisieController.htagLongInputTexts['HIT_LongTestHIT'].rendered}"
        required = "#{saisieController.htagLongInputTexts['HIT_LongTestHIT'].required}"
    />
    <h:message for = "HIT_LongTestHIT" styleClass = "error-text" />
    <h:commandButton value = "submit" action = "#{saisieController.doNothing()}" />
    <h:outputText value = "#{saisieController.htagLongInputTexts['HIT_LongTestHIT'].value}" />
</h:form>
  • 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-17T01:25:14+00:00Added an answer on June 17, 2026 at 1:25 am

    Is there some trick to make JSF validation work without having to explicitly define a custom Validator for each h:inputText?

    No, that’s not possible. Due to type erasure the generic type information is not available during runtime. JSF/EL has no idea that T is actually a Long, let alone that there’s actually some T. You really need to explicitly specify a converter which is in this particular example the LongConverter with a converter ID of javax.faces.Long.

    <h:inputText ... converter="javax.faces.Long">
    

    or, dynamically so you want

    <h:inputText ...>
        <f:converter converterId="#{saisieController.htagLongInputTexts['HIT_LongTestHIT'].converterId}" />
    </h:inputText>
    

    You can find an overview of all available standard JSF converters in the javax.faces.convert package summary. You can find out their converter IDs by navigating to the Constant field values link on the public constant CONVERTER_ID.

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

Sidebar

Related Questions

I am trying to add some custom functionality to the MUI2 Components Page. When
i'm trying to add some custom attributes to the checkout(sales) page of magento 1.5.1.0
I'm trying to put some custom list adapters into their own classes to make
I'm trying to implement some custom model metadata in ASP.NET MVC 3. I can't
I'm trying to implement some custom template tags to to a little more with
I'm trying to set some custom AWS CloudWatch metrics using the Java SDK. I
I'm trying to create a MIME filter to do some custom processing of resources
I'm using Stylecop to come up with some custom rules and I'm trying to
I'm trying to create a custom form input that utilizes some images, it should
I am trying to make some custom art for my app that will be

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.