在JSF 2.0中将用户名发送到数据库

时间:2013-11-11 08:54:01

标签: jsf

我在JSF 2.0中创建了一个登录应用程序并且它正常工作。我正在使用MySql数据库,其中有很多表。每个表都包含字段' created_by'。

现在我的问题是如何将用户名(登录的人)发送到' created_by'场?

这是我的代码。请告诉我我在哪里做错了。

@ManagedBean(name = "companyController")
@SessionScoped
public class CompanyController implements Serializable {


    private Company current;
    private DataModel items = null;
    @EJB
    private session.CompanyFacade ejbFacade;
    private PaginationHelper pagination;
    private int selectedItemIndex;
    @ManagedProperty(value="#{loginBean}")
    private LoginBean loginBean;

    public CompanyController() {
    }

    public Company getSelected() {
        current.setCreatedBy(loginBean.getUname());
        if (current == null) {
            current = new Company();
            selectedItemIndex = -1;
        }
        return current;
    }

我必须使用setter方法吗?如果是的话,为什么会这样呢?我不明白它的目的吗?

1 个答案:

答案 0 :(得分:0)

我明白了。我用setter方法解决了问题! :)

相关问题