<p:selectonemenu> <f:selectitems>不显示itemLabel

时间:2015-04-23 19:09:47

标签: jsf-2 primefaces selectonemenu

当我使用f:selectItems在视图中显示List<Bean>时,不会在itemLabel上显示值。另外,在itemValue上没有获取id。 我想在selectItems上只显示itemLabel。

但是,请显示: ID = 1,Descricao = Livro

代替: 这份绿皮书

我做错了什么?有什么想法吗?

我有一个f:selectItems如下:

<h:panelGrid columns="2">

                <h:outputText value="TIPO:"/>
                <p:selectOneMenu value="#{publicacaoMB.publicacao.tipo}">
                    <f:selectItems value="#{tipoMB.listTipos}" var="tipo"
                                itemLabel="#{tipo.descricao}" itemValue="#{tipo.tipoId}"/>
                </p:selectOneMenu>
        </h:panelGrid>

和ManagedBean:

@ManagedBean
@SessionScoped
public class TipoMB extends ManagedBeanBasico implements Serializable{


    private static final long serialVersionUID = 2482494734070978599L;
    @ManagedProperty(name = "tipoFacade", value = "#{tipoFacade}")
    private TipoFacade tipoFacade;
    private List<Tipo> listTipos;
    private Tipo tipo;

public List<Tipo> getListTipos() {
        try {
            listTipos = tipoFacade.getTodosTipos();
        } catch (DAOException e) {
            e.printStackTrace();
        }
        return listTipos;

    }

门面:

public class TipoFacadeImpl implements TipoFacade, Serializable {


    private static final long serialVersionUID = -8560527136998650945L;
    @ManagedProperty(name="tipoDAO", value="#{tipoDAO}")
    private TipoDAO tipoDAO;
    private List<Tipo> listTipos;

public List<Tipo> getTodosTipos() throws DAOException {
        if(listTipos == null) {
            listTipos = tipoDAO.getTodosTipos();
        }
        return listTipos;
    }

和DAO:

public class TipoDAOImpl extends NamedParameterJdbcDaoSupport implements TipoDAO, Serializable {

    private static final long serialVersionUID = 8698127647660788120L;
    private SimpleJdbcInsert sji;
    @Value("#{queries.sql03}")
    private String sql03;

public List<Tipo> getTodosTipos() throws DAOException {
        try {
            RowMapper<Tipo> mapper = getRowMapper();
            return getJdbcTemplate().query(this.sql03, mapper);
        } catch (EmptyResultDataAccessException ex) {
            throw new DAOException("Não há registros na tabela de tipos.");
        } catch (DataAccessException e) {
            throw new DAOException(e.getMessage());
        }

    }

    private RowMapper<Tipo> getRowMapper() {
        RowMapper<Tipo> mapper = new RowMapper<Tipo>() {
            public Tipo mapRow(ResultSet rs, int rowNum) throws SQLException {
                Tipo t = new Tipo();
                t.setTipoId(rs.getInt("tipo_id"));
                t.setDescricao(rs.getString("descricao"));

                return t;
            }
        };
        return mapper;

也是web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>SdiInventario</display-name>
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>

    </welcome-file-list>
    <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>client</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
        <param-value>65535</param-value>
    </context-param>
    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>smoothness</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name>
        <param-value>true</param-value>
    </context-param>

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.xhtml</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>

    <listener>
        <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>



</web-app>

0 个答案:

没有答案