2013-03-11 2 views
2

Primefaces를 사용하고 있는데 setPropertyActionListener가 실행되지 않아 뷰 범위가 지정된 관리 빈의 속성을 설정하지 않는 문제가 있습니다.Primefaces의 명령 링크에 첨부 할 때 속성 작업 수신기가 호출되지 않습니다.

내보기 :하는 게터와 세터 모두가

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

관리되는 콩은 selectedType 속성이 있습니다.

내 관리 빈 :

@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()); 
    } 

} 

내가 내가 원하는 것을 달성하기 위해 무엇을 할 수 있는가?

+1

'

'의'process = "@ this"'속성을 추가하십시오. 귀하의 구성 요소가 * 하나 *''에 포함되기를 바랍니다. 맞습니까? – skuntsel

+0

고마워요. 작동합니다. 그렇습니다. 내 구성 요소가 h 안에 있습니다. 양식 – simonTifo

+0

안녕하세요. – skuntsel

답변

3

Primefaces (3.5) user's guide 섹션에 <p:commandLink>Primefaces lead on this forum에 의해 진술에 따르면, process 속성의 기본값은 전체 페이지가 제출됩니다 것을 의미 @all입니다. 따라서이 제출의 유효성 검증 오류가있을 수 있으므로 수신 대기 메소드가 호출되지 않습니다. 그렇지 않으면 게시 한 코드에서 예상대로 작동합니다.

위의 가정에 대한 좋은 테스트는 process="@this" 속성을 넣는 것입니다. BalusC가 완벽하게 설명하고있는 것처럼 What is the function of this exactly에 '링크 실행과 관련된 작업, 링크 자체를 부분적으로 제출하는 것이 필수적'이므로 테스트를 수행 할 속성을 추가해야합니다.

확인해야 할 또 다른 사항은 명령 구성 요소가 양식에 속하며보기에 중첩 된 양식이 어디에도 들어 있지 않다는 것입니다.

1

다음 코드는 작동 :

의 관리 빈 :

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 인 Mojarra 2.1.7
  • Primefaces 3.4.2
  • 보스

Primefaces Showcase 7.1 AS.