1

selectManyCheckboxjsf ページのコンポーネントからアイテムを無効化および有効化する際に、あなたの助けが必要です。まず、selectManyCheckbox コンポーネントは、(ローン - 健康 - 譲渡) の 3 つのチェックボックスを表示しています。リストは、コードを持つ Bean から生成されます。

private List<hrCertificate> hrCertificatesList = new ArrayList<hrCertificate>(); 

//Getter and Setter

Private String loanFlag="";

@PostConstruct
public void init() {

    this.hrCertificatesList.add(new hrCertificate(("Loan"), "LC"));
    this.hrCertificatesList.add(new hrCertificate(("Health"), "HI"));
    this.hrCertificatesList.add(new hrCertificate(("Trasnfer"), "TE"));    
}

同じ Bean で、Yes または No のいずれかを返す SQL ステートメントを実行し、その値をloanFlag変数に追加します。したがって、フラグ = "Y" の場合、ユーザーができるようにローン チェックボックスを有効にする必要があります。それ以外の場合は、から無効にする必要がありますselectManyCheckboxselectManyCheckbox問題は、上記のコードでアイテムをリストして常に有効にしているアイテムを無効にして有効にするロジックを適用する際に困難に直面していることです。

selectManyChexkbox のコード:

 <p:selectManyCheckbox id="hrCertificates" value="#{user.selectedHRCertificates}" layout="pageDirectio>
     <f:selectItems value="#{user.hrCertificatesList}" 
         var="hrCertificate" itemLabel="#{hrCertificate.hrCertificateName}"
         itemValue="#{hrCertificate.hrCertificateCode}"/>

 </p:selectManyCheckbox>

では、ロジックを適用する方法

4

2 に答える 2

0

hrCertificate クラスを編集してdisabledブール値フィールドを追加していただけますか? はいの場合は、最も簡単な解決策を追加できitemDisabled="#{hrCerticate.disabled}"ます。f:selectItems

別のオプションは、 のMap<hrCertificate, Boolean>代わりにを使用することList<hrCertificate>です。

private Map<hrCertificate, Boolean> hrCertificatesMap = new HashMap<hrCertificate, Boolean>();

@PostConstruct
public void init() {
     hrCertificatesMap.put(new hrCertificate(("Loan"), "LC"), null);
     hrCertificatesMap.put(new hrCertificate(("Health"), "HI"), null);
     hrCertificatesMap.put(new hrCertificate(("Trasnfer"), "TE"), null);
 }

 // Then when you're done with your SQL query, update your Map to add the corresponding boolean values...

.xhtml

<p:selectManyCheckbox id="hrCertificates" value="#{user.selectedHRCertificates}" layout="pageDirectio>
    <f:selectItems value="#{user.hrCertificatesMap.keySet().toArray()}" var="hrCertificate" itemLabel="#{hrCertificate.hrCertificateName}" itemValue="#{hrCertificate.hrCertificateCode}" itemDisabled="#{user.hrCertificatesMap.get(hrCertificate)}" />
</p:selectManyCheckbox>
于 2015-07-03T09:05:45.830 に答える
-1

まず、プロパティはそれを裏付ける実際の属性を廃止しないことに注意してください。必要なのは getter だけです。したがって、次のことができます。

public class MyBean implements Serializable {

   private FilterEnum certFilter = FilterEnum.NO_FILTER;
   private List<Certificate> certificates;

   ... // including certificates initialization.

   public FilterEnum getCertFilter() {
     return this.certFilter;
   }

   public void setCertFilter(FilterEnum certFilter) {
     this.certFilter = certFilter;
   }

   public List<Certificate> getCertificates() {
     // I am sure there is a cooler way to do the same with streams in Java 8
     ArrayList<Certificate> returnValue = new ArrayList<>();
     for (Certificate certificate : this.certificates) {
       switch (this.certFilter) {
       case FilterEnum.NO_FILTER:
         returnValue.add(certificate);
         break;
       case FilterEnum.ONLY_YES:
         if (certificate.isLoan) {
           returnValue.add(certificate);
         }
         break;
       case FilterEnum.ONLY_NO:
         if (!certificate.isLoan) {
           returnValue.add(certificate);
         }
         break;
       }
     }
     return returnValue;
   }
 }

「.xhtml 内」でフィルターを実行したい場合は、c:forEachJSTL を( itemではなくitem に<f:selectItem>注意) と組み合わせることができますが、これにより xhtml がより複雑になり、Ajax を使用する場合に問題が発生する可能性があります。それ。

于 2015-07-03T09:04:42.927 に答える