2012-09-19 56 views
2

OminiFaces的'o:methodParam'现在可以为我工作,如下所示。我怎样才能用另一种方式?我不知道我错过了什么。它可以与<h:commandButton><a4j:jsFunction>一起使用,而不使用Seam,当使用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

<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}',getDepartmentList()是纯粹的getter? – BalusC

+0

'ManageDepartmentAction'是JBoss Seam的'Conversation'范围。 'getDepartmentList()'是一个纯粹的getter方法。 'departmentList'已经在bean的初始状态从数据库中检索出来(通过使用@Begin)'。 'getDepartmentList()'方法只返回'departmentList'。 – CycDemo

+0

如果从JSF中将“@Named”(“@Name is typo?”)更改为@ManagedBean,会发生什么?请注意,有两个注释,在这种情况下,您需要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?

编辑

%的意见,改变了StringDepartment

DataTableBacking。Java的:

@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时,您是否以和我一样的方式进行操作?你能展示你的完整支持bean吗?

+0

我的开发环境是:'OminiFaes 1.1,JBoss AS 7.1.1,Richfaces 4.0.0,Seam 2.3,Spring 3.0,JPA 2.0'。 – CycDemo

+0

我测试了你的建议,我也用Ominiface 1.2 versin。 \t \t' \t \t ' 这两个操作方法获得相同的值NULL。 – CycDemo

+1

您是否还测试了Arjan的代码示例,甚至将其与您的实际代码进行比较,以查看技术设计是否在某种程度上可能导致问题的原因不同? – BalusC

0

我试图用javascript来解决这个问题。这可能是不适合的解决方案。 datatable通过row Index作为参数,因为我想获得每行数据表的ID为<h:commandButton>。当用户点击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>