Skip to main content

An elementary question - I hope

Please note these forums are being decommissioned and use the new and improved forums at
1 reply [Last post]
Joined: 2010-08-25

This is a question about Java EE - I use NetBeans 7 and Glassfish; I have used NetBeans to create a very simple web application that lists rows from a database table. All this works and I think I understand the principles, except for one thing. But first a little bit of detail - I have a list of user data, list.xhtml. If I want to edit one of the users, I can click on a link that is defined like this:

... <h:commandLink action="#{usersController.prepareEdit}" value="#{bundle.ListUsersEditLink}"/>

This will call a method 'UsersController.prepareEdit()' - when it returns, another form, edit.xhtml, is shown; it contains elements like:

... <h:inputText id="name" value="#{}" title="#{bundle.EditUsersTitle_name}" required="true" requiredMessage="#{bundle.EditUsersRequiredMessage_name}"/>

This displays the data contained in '' which seems reasonable; except - there is no element called 'selected' in this class as far as I can see. So where does it come from?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2012-04-05

I'm guessing your UsersController class looks something like this:

public class UsersController 
    private List<PersonBean> User;
    private static PersonBean selected;
    public UsersController()

    public List<PersonBean> getUser()
        return User;

    public void setUser(List<PersonBean> User)
        this.User = User;

    public static PersonBean getSelected()
        return selected;

    public static void setSelected(PersonBean selected)
        UsersController.selected = selected;

Note mine is based on PersonBean, same thing.
When you set the value of your inputText element to the bean, it looks for a
function called getSelected(), see code above, because it is of type PersonBean, it can then call getFirstName(), the cool and confusing bit is that it strips the get/set part off and converts the first letter to lowercase.

<h:inputText id="name" value="#{usersController.selected.firstName}"
             title="Some Name" required="true"
             requiredMessage="Some Msg"/>