Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf 2 不显示项目标签_Jsf 2_Primefaces_Selectonemenu - Fatal编程技术网

Jsf 2 不显示项目标签

Jsf 2 不显示项目标签,jsf-2,primefaces,selectonemenu,Jsf 2,Primefaces,Selectonemenu,使用f:selectItems在视图中显示列表时,不会显示itemLabel上的值。此外,无法获取itemValue上的id。 我只想在selectItems上显示itemLabel 但是,展示一下: ID=1,descripcao=Livro 而不是: 利夫罗 我做错了什么?有什么想法吗 我有一个f:selectItems,如下所示: <h:panelGrid columns="2"> <h:outputText value="TIPO:"/

使用f:selectItems在视图中显示列表时,不会显示itemLabel上的值。此外,无法获取itemValue上的id。 我只想在selectItems上显示itemLabel

但是,展示一下: ID=1,descripcao=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;
    }
还有一把刀:

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>

只是一些注释:我想标准是使用itemValue={tipo},然后使用一个转换器用于tipo搜索jsf转换器。另外,jsf中的getter方法中不应该有逻辑,我认为应该将getListTipos中的代码移动到带有@PostConstruct的init方法中,然后从getterIn返回listTipos。换句话说,getListTipos方法返回了一个没有descripao属性集的Tipo实体列表?或者您是否已经排除了该部分表单是原因?这个问题不清楚。JSF在这里只是模型的演示者。如果模型一开始就已经损坏,JSF做不了什么。@BalusC属性descripcao已设置。但是f:selectItems不会在itemLabel上显示属性。这不是默认行为。因此,我们欢迎你的到来。同时,您是否检查了生成的HTML输出中的元素以排除其中一个和另一个?@BalusC在生成的HTML中是这样的:ID=1,descripao=LIVRO