繁体   English   中英

显示或隐藏p的选项:inputText-JSF2 Primefaces

[英]Option to show or hide p: inputText - JSF2 Primefaces

我不知道如何通过选择选项selectOneMenu显示和隐藏字段(p:inputText)。 例如:我有一个selectOneMenu从1到10,单击10显示10个inputText。 单击1仅显示1个inputText。

我已经有了SectOneMenu和inputText(如下):

            <p:selectOneMenu value="#{bean.parametro.intervalo}">  
                <f:selectItem itemLabel="Select One" itemValue="" />  
                <f:selectItem itemLabel="1" itemValue="1" />  
                <f:selectItem itemLabel="2" itemValue="2" />  
                <f:selectItem itemLabel="3" itemValue="3" />  
                <f:selectItem itemLabel="4" itemValue="4" />  
                <f:selectItem itemLabel="5" itemValue="5" />  
                <f:selectItem itemLabel="6" itemValue="6" />  
                <f:selectItem itemLabel="7" itemValue="7" />  
                <f:selectItem itemLabel="8" itemValue="8" />  
                <f:selectItem itemLabel="9" itemValue="9" />  
                <f:selectItem itemLabel="10" itemValue="10" />  
            </p:selectOneMenu> 

要复制的inputText:

                <h:outputText value="portabilidadeGrupo" />  
                <p:selectBooleanCheckbox value="#{bean.parametro.portabilidadeGrupo}" />  

                <h:output Label for="numInicial" value="Nº Inicial Int:" />  
                <p:inputText id="numInicial" value="#{bean.parametro.numInicial}" />  

                <h:outputLabel for="numFinal" value="Nº Final Int:" />  
                <p:inputText id="numFinal" value="#{bean.parametro.numFinal}" />  

                <h:outputLabel for="idGrupo" value="Id do Grupo:" />  
                <p:inputText id="idGrupo" value="#{bean.parametro.idgrupo}" />  

                <h:outputText value="PTO" />  
                <p:selectBooleanCheckbox value="#{bean.parametro.pto}" /> 

谢谢!

我放弃了使用selectOneMenu并使用此Darryl Nortje动态字段示例解决了我的问题。

豆角,扁豆

package datatable;  

import java.util.ArrayList;  
import java.util.List;  

import javax.faces.component.html.HtmlDataTable;  

public class DatatableBean {  

  //Data table contents  
  private List<Person> people;  
  //Data table binding. TO figure out which row was acted on.  
  private HtmlDataTable table;  

  //vars to add a person.  
  private String firstname;  
  private String surname;  

  public DatatableBean() {  
    people = new ArrayList<Person>();  
  }  

  //ACTION METHODS TO ADD AND REMOVE A PERSON  
  public void removePerson() {  
    //FIRST figure out which row was acted on. Then remove that person from the people list.  
    Person selectedPerson = (Person) table.getRowData();  
    people.remove(selectedPerson);  
    //simple hey. There is another way to do this with binding the datatable to the bean.  
  }  

  public void addPerson() {  
    //here we create a new person object from the entered values, and add to the people list.  
    Person newPerson = new Person();  
    newPerson.setFirstname(getFirstname());  
    newPerson.setSurname(getSurname());  
    people.add(newPerson);  
  }  

  //HELPERS FOR DISPLAYING NICELY  
  public boolean isPersonAdded() {  
    return people.size() > 0;  
  }  

  //ALL GETTERS AND SETTERS HERE....  

}

JSP

<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>  
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>  
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>  
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>  


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
<html>  
<f:view>  
<head>  
  <title>Data table stuff</title>  
</head>  
<body>  

<div class="text_style">  

  <h:form id="mainform">  


<h:dataTable value="#{datatableBean.people}" var="tab"  
binding="#{datatableBean.table}" rendered="#{datatableBean.personAdded}">  

<h:column>  
<f:facet name="header">  
          <h:outputText value="Name"/>  
        </f:facet>  
        <h:outputText value="#{tab.firstname}"/>  
</h:column>  

<h:column>  
<f:facet name="header">  
          <h:outputText value="Surname"/>  
        </f:facet>  
        <h:outputText value="#{tab.surname}"/>  
</h:column>  

<h:column>  
<f:facet name="header">  
<h:outputText value="Click to remove"/>  
</f:facet>  

<h:commandLink action="#{datatableBean.removePerson}" value="remove"/>  
</h:column>  

</h:dataTable>  

<p>  
<h:outputText value="To add a new person, fill in these details then click add"/>  

<p>  
<h:outputText value="Firstname"/>  
<h:inputText value="#{datatableBean.firstname}" />  
<br>  
<h:outputText value="Surname"/>  
<h:inputText value="#{datatableBean.surname}"/>  
<br>  
<h:commandButton action="#{datatableBean.addPerson}" value="Add"/>  


</h:form>    
</div>  
</body>  
</f:view>  
</html>

尝试对该标签使用“渲染”和“更新”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM