2012-09-25 2 views

답변

2

당신은 아약스 리스너와 함께 할 수

당신이 필요로하는 것은 다음

이 설정을 변경하는 방법 (관리 빈에서 비활성화 부울 참조) 표가 무효 인 경우 알 수있는 부울 값입니다 호출 될 때마다 불리언 이것을 비활성화/렌더링 등


0과 같은 임의의 부울 값에 적용될 수

(XHTML에 selectBooleanCheckboxrendered="#{tableController.disabled}" 참조)

소스 코드 (XHTML) :

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html"> 
<h:head> 
    <title>Facelet Title</title> 
</h:head> 
<h:body> 

    <h:form> 
     <h:dataTable id="table" value="#{tableController.products}" var="item" border="1" rendered="#{tableController.disabled}" 
        headerClass="table-header" 
        styleClass="table-d" 
        rowClasses="table-row"> 

      <h:column> 
       <f:facet name="header"> 
        ID 
       </f:facet> 
       <h:outputText value="#{item.id}"/> 
      </h:column> 

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

      <h:column> 
       <f:facet name="header"> 
        Price 
       </f:facet> 
       <h:outputText value="#{item.price}"/> 
      </h:column> 

     </h:dataTable> 


     <h:selectBooleanCheckbox value="Id"> 
      <f:ajax render="@form" listener="#{tableController.enableDisable()}"/> 
     </h:selectBooleanCheckbox> 
    </h:form> 
</h:body> 
</html> 

관리 콩 :

import java.util.ArrayList; 
import java.util.List; 
import javax.faces.bean.ManagedBean; 
import javax.faces.bean.SessionScoped; 
import javax.faces.model.DataModel; 
import javax.faces.model.ListDataModel; 

@ManagedBean 
@SessionScoped 
public class TableController { 

private boolean disabled; 
private DataModel products; 

public TableController() { 

    List list = new ArrayList<Product>(); 

    Product p1 = new Product(1, "Z", 1.1); 
    Product p2 = new Product(2, "F", 2.5); 
    Product p3 = new Product(3, "A", 0.9); 

    list.add(p1); 
    list.add(p2); 
    list.add(p3); 

    products = new ListDataModel<Product>(list); 
} 


public void enableDisable(){ 
     disabled = !disabled; 
} 

public boolean isDisabled() { 
    return disabled; 
} 

public void setDisabled(boolean disabled) { 
    this.disabled = disabled; 
} 

public DataModel getProducts() { 
    return products; 
} 

public void setProducts(DataModel products) { 
    this.products = products; 
}  
} 

제품 클래스 :

public class Product { 

private int id; 
private String name; 
private double price; 


public Product(int id, String name, double price){ 

    this.id = id; 
    this.name = name; 
    this.price = price; 

} 

public void setId(int id) { 
    this.id = id; 
} 

public void setName(String name) { 
    this.name = name; 
} 

public void setPrice(double price) { 
    this.price = price; 
} 

public int getId() { 
    return id; 
} 

public double getPrice() { 
    return price; 
} 

public String getName() { 
    return name; 
} 

} 
관련 문제