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

  • Home
  • SEARCH
  • 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 3600748
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:32:05+00:00 2026-05-18T20:32:05+00:00

Based on this previous question How to get ID of calling component in the

  • 0

Based on this previous question How to get ID of calling component in the getter method? , here’s another idea i want to ask your opinion about :

there are lots of duplicated code across jsf pages such as these examples (notice the repeating size and maxlength attribute) across components :

<h:inputText label="#{msgs.userId}" id="UserId" value="#{userBean.userId}" 
   required="true" 
   size="#{variableConfigBean.getSize(component.id)}" 
   maxlength="#{variableConfigBean.getMaxLength(component.id)}"
/>
<h:inputSecret label="#{msgs.password}" id="Password" value="#{userBean.password}" 
   required="true"  
   size="#{variableConfigBean.getSize(component.id)}" 
   maxlength="#{variableConfigBean.getMaxLength(component.id)}"
/>

Im thinking of :

  1. using composite component for that
    input text tag,
  2. hardcoding the size and maxlength in the implementation section of that composite component,
  3. so that i dont have to duplicate all
    these stuffs everytime i need to use
    that component.
  4. but i’ll have to open
    up all attributes in the interface
    section of that composite component

Is this idea ok, or perhaps there are other better ways to solve this problem ?

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

    You could do so. I’ve also implemented it in some projects. It only adds some (minor) overhead. You could for this particular purpose also just use a Facelets tag file instead of a JSF composite component. It’s not mandatory to define the attributes then. In your particular case you can refactor pretty much duplicates if you reuse the bean property name as id and key for message bundle label.

    E.g.

    <my:input type="text" bean="#{userBean}" property="userId" required="true" />
    <my:input type="secret" bean="#{userBean}" property="password" required="true" />
    

    with the following in a Facelets tag file:

    <c:set var="id" value="#{not empty id ? id : property}" />
    <c:set var="required" value="#{not empty required and required}" />
    
    <c:choose>
        <c:when test="#{type == 'text'}">
            <h:inputText id="#{id}" 
                label="#{msgs[property]}"
                value="#{bean[property]}" 
                size="#{config.size(id)}" 
                maxlength="#{config.maxlength(id)}" 
                required="#{required}" />
        </c:when>
        <c:when test="#{type == 'secret'}">
            <h:inputSecret id="#{id}" 
                label="#{msgs[property]}"
                value="#{bean[property]}" 
                size="#{config.size(id)}" 
                maxlength="#{config.maxlength(id)}" 
                required="#{required}" />
        </c:when>
        <c:otherwise>
            <h:outputText value="Unknown input type: #{type}" />
        </c:otherwise>            
    </c:choose>
    

    I’ve however implemented it with an <h:outputLabel> before and a <h:message> after which makes refactoring like this more reasonable.

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

Sidebar

Related Questions

No related questions found

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.