2

私は Primefaces を使用していますが、setPropertyActionListener が起動されず、ビュー スコープのマネージド Bean のプロパティを設定していないという問題があります。

私の見解:

<p:column>
    <p:commandLink value="Supprimer" oncomplete="confirmation.show()"  >
        <f:setPropertyActionListener value="#{car}" target="#{typeMB.selectedType}" />  
    </p:commandLink>
</p:column>

マネージド Bean には、getter と setter の両方がある selectedType プロパティがあります。

私のマネージドBean:

@ManagedBean(name="typeMB")
@ViewScoped
public class TypeManagedBean implements Serializable {

    private static final long serialVersionUID = 1L;
    private Type newtype;  
    private Type selectedType;

    @ManagedProperty(value="#{TypeDao}")
    GenericDao<Type> typeDAO;

    public TypeManagedBean(){
        newtype = new Type();
    }

    public List<Type> getList_types() {     
        return typeDAO.readAll();
    }

    public void setTypeDAO(GenericDao<Type> typeDAO) {
        this.typeDAO = typeDAO;
    }

    public GenericDao<Type> getTypeDAO() {
        return typeDAO;
    }

    public Type getNewtype() {
        return newtype;
    }

    public void setNewtype(Type newtype) {
        this.newtype = newtype;
    }       

    public Type getSelectedType() {
        if(selectedType != null)
        System.out.println("get : le selected type : "+selectedType.getLibelle());
        return selectedType;
    }

    public void setSelectedType(Type selectedType) {        
        this.selectedType = selectedType;
        System.out.println("set le selected type : "+selectedType.getLibelle());
    }

}

私が望むものを達成するために何ができますか?

4

2 に答える 2

4

Primefaces (3.5) ユーザー ガイドのセクション<p:commandLink>、およびこのフォーラムの Primefaces リードによる声明によると、process属性のデフォルト値は で@allあり、ページ全体が送信されることを意味します。そのため、この送信からいくつかの検証エラーが発生し、リスナー メソッドの呼び出しが妨げられる可能性があります。それ以外の場合は、投稿したコードで期待どおりに動作するはずです。

process="@this"上記の仮定の良いテストは、属性を置くことです。「実行されるリンクに関連付けられたアクションは、リンク自体を部分的に送信することが必須です」ため、BalusC が正確にこれの機能とは何かで完全に説明しているように、テストを行うために属性を追加する必要があります。

もう 1 つチェックする必要があるのは、コマンド コンポーネントがフォームに属しており、ビューにネストされたフォームがどこにも含まれていないことです。

于 2013-03-11T18:36:58.747 に答える
1

次のコードが機能しています。

マネージド Bean:

package app.so.dev.web.controller;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import app.so.dev.web.model.Student;

@ManagedBean(name = "so15344819")
@ViewScoped
public class SO15344819 implements Serializable {

    private static final long serialVersionUID = 6686378446131077581L;
    private List<Student> students;
    private Student selectedStudent;

    @PostConstruct
    public void init() {
        students = new ArrayList<Student>();
        students.add(new Student("Student 1"));
        students.add(new Student("Student 2"));
    }

    public List<Student> getStudents() {
        return students;
    }

    public void setStudents(List<Student> students) {
        this.students = students;
    }

    public Student getSelectedStudent() {
        return selectedStudent;
    }

    public void setSelectedStudent(Student selectedStudent) {
        this.selectedStudent = selectedStudent;
    }
}

そしてxhtml:

<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core" xmlns:p="http://primefaces.org/ui" template="/WEB-INF/templates/globalTemplate.xhtml">

    <ui:define name="title">15344819</ui:define>
    <ui:define name="content">
        <p:growl id="growl" showDetail="true" />

        <h:form id="form">
            <p:dataTable id="students" value="#{so15344819.students}" var="student">
                <p:column>
                        <p:commandButton id="selectButton" update=":form:display" oncomplete="studentDialog.show()" icon="ui-icon-search" title="View">
                           <f:setPropertyActionListener value="#{student}" target="#{so15344819.selectedStudent}" />
                       </p:commandButton>
                   </p:column>
            </p:dataTable>

            <p:dialog header="Student Detail" widgetVar="studentDialog" resizable="false" id="studentDlg"
                            showEffect="fade" hideEffect="explode" modal="true">

                    <h:panelGrid id="display" columns="2" cellpadding="4" style="margin:0 auto;">

                        <h:outputText value="Name:" />
                        <h:outputText value="#{so15344819.selectedStudent.name}" style="font-weight:bold"/>                                               

                    </h:panelGrid>

                </p:dialog>
        </h:form>
    </ui:define>

</ui:composition>

環境:

  • JSF モハラ 2.1.7
  • プライムフェイス 3.4.2
  • JBoss AS 7.1

プライムフェイスショーケース

于 2013-03-11T19:03:38.760 に答える