gpt4 book ai didi

jsf-2 - PrimeFaces CommandButton Action 未在 Composite 内调用

转载 作者:行者123 更新时间:2023-12-04 04:57:49 25 4
gpt4 key购买 nike

在下面的代码中,jsf html commandButton Action 被完美调用。
但不调用primefaces commandButton Action 。

<ui:component          
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>
<composite:attribute
name="managedBean"
type="java.lang.Object"
required="true">
</composite:attribute>
</composite:interface>

<composite:implementation>
<f:view contentType="text/html">
<h:form id="componentes">
<h:panelGrid columns="3">
<h:panelGroup>
<h:outputText
escape = "false"
value = "#{cc.attrs.managedBean['value']}"
rendered = "#{!cc.attrs.managedBean['editing']}"/>
<p:editor
widgetVar = "editor"
value = "#{cc.attrs.managedBean.value}"
rendered = "#{cc.attrs.managedBean.editing}"/>
</h:panelGroup>
<!-- ACTION IS CALLED -->
<h:commandButton
action = "#{cc.attrs.managedBean.toogleEditing}"
value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}"
update = "componentes"/>

<!-- ACTION IS NOT CALLED -->
<p:commandButton
action = "#{cc.attrs.managedBean.toogleEditing}"
value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}"
update = "componentes"/>
</h:panelGrid>
</h:form>
</f:view>
</composite:implementation>
</ui:component>

如果将相同的代码放在复合之外(一个普通的 xhtml 页面),两者都可以正常工作:
<!DOCTYPE html 
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html
xml:lang="pt"
lang="pt"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.prime.com.tr/ui">

<h:head id="head">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Item de Texto</title>
</h:head>
<h:body id="body">
<f:view contentType="text/html">
<h:form id="componentes">
<h:panelGrid columns="3">
<h:panelGroup>
<h:outputText
escape = "false"
value = "#{editableHTMLText.value}"
rendered = "#{!editableHTMLText.editing}"/>
<p:editor
widgetVar = "editor"
value = "#{editableHTMLText.value}"
rendered = "#{editableHTMLText.editing}"/>
</h:panelGroup>

<!-- ACTION IS CALLED -->
<h:commandButton
action = "#{editableHTMLText.toogleEditing}"
value = "#{editableHTMLText.editing?'Back':'Edit'}"
update = "componentes"/>

<!-- ACTION IS CALLED -->
<p:commandButton
action = "#{editableHTMLText.toogleEditing}"
value = "#{editableHTMLText.editing?'Back':'Edit'}"
update = "componentes"/>
</h:panelGrid>
</h:form>
</f:view>
</h:body>
</html>

这是 bean 代码:
import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;


@ManagedBean
@SessionScoped
public class EditableHTMLText implements Serializable{

/**
*
*/
private static final long serialVersionUID = 8439126615761864409L;

private String value = "Test<br>of<br>HTML<br>text<br><b>ITEM</b><br>";
private boolean editing = false;


public void toogleEditing(){

this.setEditing(!this.isEditing());
System.out.println("Editing State: " + this.editing);
}


public String getValue(){

return value;
}


public void setValue(String value){

this.value = value;
}


public boolean isEditing(){

return editing;
}


public void setEditing(boolean editing){

this.editing = editing;
}

}

有什么建议?

最佳答案

今天,我在 PrimeFaces 5.1 中遇到了完全相同的问题。就我而言,我没有嵌套表单,而且我已经设置了 process p:commandButton 上的属性使用我想要处理的表单元素。然而,这还没有奏效。

“解决方案”是添加 @this到要处理的组件列表,如下所示:
<p:commandButton process="myFormField1 myFormField2 @this">
@this (通常不需要,因为按钮本身不需要处理/验证)我发现没有办法让其中的任何一个在复合中工作:

  • <p:commandButton action="#{bean.myAction}"...>
  • <p:commandButton type="button">嵌套 <p:ajax event="click" action="#{bean.myAction}"...>
  • <p:commandButton type="button" onclick="myAction()">与关联 <p:remoteCommand name="myAction" action="#{bean.myAction}">

  • 通过调试应用程序,我看到验证和更新模型阶段已正确执行,但随后在调用应用程序阶段不存在排队事件,因此未执行任何操作。实际上,我可以在 action 中指定任何我喜欢的内容。和 actionListener <p:commandButton> 的属性值没有 PrimeFaces 或 JSF 以任何方式提示。

    相反,这些确实可以正常工作,但是您没有进行部分处理,因此它们可能不是可行的解决方案:
  • <p:commandButton action="#{bean.myAction}" ajax="false"...>
  • <p:commandButton type="button"...>嵌套 <f:ajax event="click" action="#{bean.myAction}"...>

  • 它一定是一个 PrimeFaces 错误。

    关于jsf-2 - PrimeFaces CommandButton Action 未在 Composite 内调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7853609/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com