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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:42:04+00:00 2026-05-27T00:42:04+00:00

Hi i have created a custom converter in jsf for combo box using h:selectOneMenu,

  • 0

Hi i have created a custom converter in jsf for combo box using h:selectOneMenu,

my backing bean code in as follows

@ManagedBean(name="studentMgBean")
public class StudentMBean {
..............
............
.....
      public StudentVO getMyStudent(Integer studentId) {
          return this.myStudents.get(studentId);
      }
      private List<SelectItem> studentList;
      // getter setter of studentList
      private Map<Integer,StudentVO> myStudents;
      private StudentVO selectedStudent;
      // getter setter of selectedStudent

     @PostConstruct
     public void loadStudents(){
         ..........
         ........
         if(this.getStudentList() == null){ 
             this.setStudentList(new ArrayList<SelectItem>());
         }else{
             this.getStudentList().clear();
         }
         this.myStudents = new HashMap<Integer, StudentVO>();
         while(rs.next()){
              vo = new StudentVO(String.valueOf(rs.getInt("studentId")),
                    rs.getString("studentName"), rs.getString("contactNo"));
              selectItem = new SelectItem(vo.getStudentId(), vo.getStudentName());
              this.getStudentList().add(selectItem);
              this.myStudents.put(Integer.parseInt(vo.getStudentId()),vo);
         }
     }
}

this is my converter,

@FacesConverter(value="studentComboConv")
public class StudentComboBoxConverter implements Converter{
     @Override
     public Object getAsObject(FacesContext context, UIComponent component, String value) {
     FacesContext ctx = null;
     ValueExpression vex = null;
     StudentMBean studentMgmtBean = null;
     StudentVO studentVO = null;
     .........
     ........
     ......
     vex = ctx.getApplication().getExpressionFactory()
                     .createValueExpression(ctx.getELContext(),"#{studentMgBean}", StudentMBean.class);
     studentMgmtBean = (StudentMBean) vex.getValue(ctx.getELContext());
     studentVO = studentMgmtBean.getMyStudent(Integer.parseInt(value)); 
     ...........
     ........
     .....
     return studentVO;
  }

and this is my jsp where i am applying my converter to the combo box

 <td align="left">SELECT STUDENT</td>
 <td align="right">
     <h:selectOneMenu value="#{studentMgBean.selectedStudent}" id="cmbo" converter="studentComboConv">
        <f:selectItems value="#{studentMgBean.studentList}" />
     </h:selectOneMenu>
  .....
  ....
  .. 

Now my question is what does this line do in my converter

  vex = ctx.getApplication().getExpressionFactory() 
        .createValueExpression(ctx.getELContext(),"#{studentMgBean}", StudentMBean.class);
  studentMgmtBean = (StudentMBean) vex.getValue(ctx.getELContext());

What does ctx.getElContext() do ?

  • 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-27T00:42:04+00:00Added an answer on May 27, 2026 at 12:42 am

    It obtains the ELContext (<– click the link to see the javadoc), so that you’re able to evaluate an EL expression #{} programmatically in Java code. In your particular case, you’re basically programmatically evaluating the EL expression #{studentMgBean} to get the current instance of StudentMBean.

    In JSF 2.0 there’s by the way a shortcut by Application#evaluateExpressionGet() which does basically the same and hides the ELContext details under the hoods:

    StudentMBean studentMgBean = (StudentMBean) ctx.getApplication().evaluateExpressionGet(ctx, "#{studentMgBean}", StudentMBean.class);
    

    That said, your approach is pretty clumsy. If the converter is that tight coupled to a backing bean, you’d probably better make it a property of the backing bean instead:

    converter="#{studentMgBean.studentConverter}"
    

    with the converter as an inner class.

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

Sidebar

Related Questions

friends, i have created custom title bar using following titlebar.xml file with code <?xml
Setup: I have a combo-box, it's itemsource bound to an ObservableCollection<T> of a custom
In a create new user jsf page, I have a SelectOneMenu with a custom
i have created a custom user control which im using on my main xaml
I have created a custom MultiValue Converter to perform a bit of logic while
I have created custom posts and I want one page in my site to
I have created custom jQuery UI widget called uiPopover, very similar to UI-dialog (in
I have created custom cell in which there are n number of image views.
I have created a custom list as a feature in sharepoint. i need to
I have created a custom ExpandableListAdapter and everything works properly. What I'd like to

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.