2012-09-19 5 views
2

이제 OminiFaces의 'o : methodParam'이 다음과 같이 작동합니다. 다른 방법을 사용하려면 어떻게해야합니까? 내가 뭘 놓치고 있는지 모르겠다. Seam을 사용하지 않고 <h:commandButton><a4j:jsFunction>과 작동 할 수 있습니다. Seam을 사용하면 <a4j:jsFunction>과 작동하지 않습니다.Ominifaces EL 문자열 전달

개발 Eviroment는 RichFaces 4. Seam 2.3 OminiFaces 1.2 JBoss 7.1.1

@Name("DataTableBacking") 
public class DataTableBacking { 

    Department[] items = {new Department("AAA", "AAA"), new Department("BBB", "BBB"), new Department("CCC", "CCC")}; 

    public Department[] getItems() { 
     return items; 
    } 

    public void action(Department action) { 
     System.out.println("Action called with:" + action.getName()); 
    } 

} 

datatable.xhtml

태그 lib에
<h:html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:rich="http://richfaces.org/rich" 
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:richm="http://developmentTutorials.com/java"> 
     <h:body> 
      <h:form> 
      <h1>Data Table</h1> 
       <rich:dataTable id="departmentTable" value="#{DataTableBacking.items}" var="dep" style="width:100%"> 
        <rich:column style="width:100px;text-align:center;"> 
         #{dep.name} 
         <richm:confirmLink actionBeanMethod="#{DataTableBacking.action(dep)}" render="departmentTable"/> 
        </rich:column> 
       </rich:dataTable> 
      </h:form> 
     </h:body> 
</h:html> 

, confirmation.xml 내가 완전히 확실하지 않다

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:rich="http://richfaces.org/rich" 
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:o="http://omnifaces.org/ui" 
    xmlns:of="http://omnifaces.org/functions" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
    <o:methodParam name="methodParam" value="#{actionBeanMethod}" /> 

    <a4j:commandLink value="delete" onclick="#{rich:component('confirmation')}.show();return false" /> 

    <h:commandButton value="direct" action="#{methodParam}" /> 

    <a4j:jsFunction name="submit" action="#{methodParam}" render="#{render}" /> 

    <rich:popupPanel id="confirmation" width="250" height="150"> 
     <f:facet name="header">Confirmation</f:facet> 
     <h:panelGrid> 

      <h:panelGrid columns="1"> 
       <h:outputText value="Are you sure?" style="FONT-SIZE: large;" /> 
      </h:panelGrid> 

      <h:panelGroup> 
       <input type="button" value="OK" onclick="#{rich:component('confirmation')}.hide(); submit(); return false" /> 
       <input type="button" value="Cancel" onclick="#{rich:component('confirmation')}.hide(); return false" /> 
      </h:panelGroup> 
     </h:panelGrid> 
    </rich:popupPanel> 

</ui:composition> 
+0

확인하려면 뷰 범위의'# {ManageDepartmentAction} '이고 순수 getter 인 getDepartmentList()입니까? – BalusC

+0

'ManageDepartmentAction'는 JBoss Seam의 'Conversation' 범위입니다. 'getDepartmentList()'는 순수한 getter 메소드입니다. 'departmentList'는 이미 Bean 초기 상태'(@Begin을 사용하여)'에서 DB로부터 검색합니다. 'getDepartmentList()'메소드는 단지'departmentList'를 리턴합니다. – CycDemo

+0

JSF에서 @ManagedBean으로 "@Named"("@Name is typo?")를 변경하면 어떻게됩니까? 두 가지 주석이 있음을주의하십시오.이 경우 javax.faces가 필요합니다. –

답변

2

에 대한 null 값 . 후행 (흔히 되풀이되는 실수) 이후에 데이터가 없으면이 메소드를 전혀 호출하지 않아야합니다.

코드에 버그가 있습니다. 즉, a4j:jsFunction은 함수를 만들고이를 submit이라는 js 변수에 할당하며 모든 행에 동일하게 적용됩니다.

그래서 첫 번째 행은 submit=function(){RichFaces.ajax("j_idt15:departmentTable:0:j_idt18" ...이고 두 번째 행은 submit=function(){RichFaces.ajax("j_idt15:departmentTable:1:j_idt18" ...입니다.

대화 상자는 항상 마지막 행의 대화 상자를 호출합니다. 따라서 테이블에 피드하는 마지막 값으로 null이 있습니까?

@ManagedBean 
public class DataTableBacking { 

    String[] items = {"A", "B"}; 

    public String[] getItems() { 
     return items; 
    } 

    public void action(String action) { 
     System.out.println("Action called with:" + action); 
    } 

} 

datatable.xhtml :

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:rich="http://richfaces.org/rich" 
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:richm="http://developmentTutorials.com/java" 
> 
    <h:head/> 
    <h:body> 

     <h:form> 
      <rich:dataTable id="departmentTable" value="#{dataTableBacking.items}" var="dep" style="width:100%"> 
       <rich:column style="width:100px;text-align:center;"> 
        #{dep} 
        <richm:confirmLink actionBeanMethod="#{dataTableBacking.action(dep)}" render="departmentTable"/> 
       </rich:column> 
      </rich:dataTable> 
     </h:form> 

    </h:body> 
</html> 

confirmation.xhtml :

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:rich="http://richfaces.org/rich" 
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:o="http://omnifaces.org/ui" 
    xmlns:of="http://omnifaces.org/functions" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
    <o:methodParam name="methodParam" value="#{actionBeanMethod}" /> 

    <a4j:commandLink value="delete" onclick="#{rich:component('confirmation')}.show();return false" /> 

    <h:commandButton value="direct" action="#{methodParam}" /> 

    <a4j:jsFunction name="submit" action="#{methodParam}" render="#{render}" /> 

    <rich:popupPanel id="confirmation" width="250" height="150"> 
     <f:facet name="header">Confirmation</f:facet> 
     <h:panelGrid> 

      <h:panelGrid columns="1"> 
       <h:outputText value="Are you sure?" style="FONT-SIZE: large;" /> 
      </h:panelGrid> 

      <h:panelGroup> 
       <input type="button" value="OK" onclick="#{rich:component('confirmation')}.hide(); submit(); return false" /> 
       <input type="button" value="Cancel" onclick="#{rich:component('confirmation')}.hide(); return false" /> 
      </h:panelGroup> 
     </h:panelGrid> 
    </rich:popupPanel> 

</ui:composition> 

다음 약간 단순화 된 코드를 사용하여

, 나는 액션 메소드에 전달 된 매개 변수를 얻을 나는 직접 호출을 h:commandButton을 통해 추가하여 표현식의 유효성을 확인했다. Facelet 태그에 올바르게 표시됩니다. 이 예에서 delete 링크를 클릭하고 확인하면 두 행에 대해 action() 메서드에서 예상대로 마지막 요소 (B)를 가져옵니다.

JBoss AS 7.1.1, OmniFaces 1.2 Snapshot 및 RichFaces 4.0.0을 사용했습니다. OmniFaces 버전은 그 버전 사이에 methodParam을 변경하지 않았으므로별로 중요하지 않습니다. (저는이 특정 파트의 저자입니다).

어떤 서버 및 OmniFaces 및 RichFaces 버전을 사용하고 있습니까?

DataTableBacking 다음 StringDepartment로 변경 코멘트 당

편집.자바 :

@ManagedBean 
public class DataTableBacking { 

    Department[] items = {new Department(), new Department()}; 

    public Department[] getItems() { 
     return items; 
    } 

    public void action(Department action) { 
     System.out.println("Action called with:" + action); 
    } 

} 

Department.java :

public class Department { 

} 

(이전과 다른 모든 코드 같은)

이해야하고 (내 옆에) 실제로 어떤 차이가되지 않습니다. String 어레이를 Department 어레이로 변경하면 내가했던 것과 같은 방식으로 처리 했습니까? 너는 너의 가득 채우는 콩을 보여줄 수 있니?

+0

제 개발 환경은'OminiFaes 1.1, JBoss AS 7.1.1, Richfaces 4.0.0, Seam 2.3, Spring 3.0, JPA 2.0'. – CycDemo

+0

내가 제안한대로 테스트합니다. 1.2 절] \t \t \t \t ' 이 두 가지 동작 방법은'NULL '과 같은 값을 갖습니다. – CycDemo

+1

Arjan의 코드 예제를 테스트했거나 실제 코드와 비교하여 기술 설계가 문제의 원인 일 수있는 방법으로 다른지 확인하십시오. – BalusC

0

javascript으로이 문제를 해결하려고합니다. 부적절한 해결책이 될 수 있습니다. datatablerow Index을 매개 변수로 전달하므로 datatable의 각 행에 대해 <h:commandButton>이라는 ID를 얻고 싶습니다. ConfirmationBox에서 OK 버튼을 클릭하면 JavaScript가 <h:commandButton>을 클릭합니다.

confirmation.xml 데이터 테이블에서

<ui:composition xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:rich="http://richfaces.org/rich" 
    xmlns:a4j="http://richfaces.org/a4j" 
    xmlns:o="http://omnifaces.org/ui" 
    xmlns:of="http://omnifaces.org/functions" 
    xmlns:ui="http://java.sun.com/jsf/facelets"> 
    <o:methodParam name="methodParam" value="#{actionBeanMethod}" /> 
    <a4j:commandLink value="#{value}" onclick="#{rich:component('confirmation')}.show();return false"/> 

    <h:commandButton id="commandButton" value="direct" action="#{methodParam}" style="display:none;"/> 

    <rich:popupPanel id="confirmation" width="250" height="150"> 
     <f:facet name="header">Confirmation</f:facet> 
     <h:panelGrid> 

      <h:panelGrid columns="1"> 
       <h:outputText value="Are you sure ?" style="FONT-SIZE: large;" /> 
      </h:panelGrid> 

      <h:panelGroup> 
       <input type="button" value="OK" onclick="document.getElementById('#{index}:commandButton').click();#{rich:component('confirmation')}.hide();return false;" /> 
       <input type="button" value="Cancel" onclick="#{rich:component('confirmation')}.hide(); return false" /> 
      </h:panelGroup> 
     </h:panelGrid> 
    </rich:popupPanel> 

    </ui:composition> 

;

<rich:dataTable id="departmentTable" value="#{DataTableBacking.items}" var="dep" style="width:100%" rowKeyVar="index"> 
     <rich:column style="width:100px;text-align:center;"> 
      <f:facet name="header"> 
       <h:outputText value="Name"/> 
      </f:facet> 
      #{dep.name} 
      <richm:confirmLink value ="Delete" index="tableForm:departmentTable:#{index}" actionBeanMethod="#{DataTableBacking.action(dep)}" render="departmentTable"/> 
     </rich:column> 
    </rich:dataTable>