Fer*_*afé 8 primefaces composite-component jsf-2
在下面的代码中,jsf html commandButton动作被完美地调用.但是没有调用primefaces commandButton动作.
<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>
Run Code Online (Sandbox Code Playgroud)
如果放置相同的代码在复合(普通的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>
Run Code Online (Sandbox Code Playgroud)
这是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;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?
Mau*_*ari 18
今天我用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}">通过调试应用程序,我看到验证和更新模型阶段已正确执行,但随后在调用应用程序阶段没有排队事件,因此未执行任何操作.实际上,我可以在没有任何PrimeFaces或JSF抱怨的情况下指定我喜欢的内容action和actionListener属性值<p:commandButton>.
相反,它们可以按预期工作,但是您没有部分处理,因此它们可能不是一个可行的解决方案:
<p:commandButton action="#{bean.myAction}" ajax="false"...><p:commandButton type="button"...> 嵌套 <f:ajax event="click" action="#{bean.myAction}"...>它必须是PrimeFaces的bug.
小智 5
当你使用复合组件时,它是否已经放在ah:form标签中?嵌套表单时,不会触发命令按钮操作.
另一个问题可能是您正在尝试的ajax部件.Primefaces按钮具有update属性,但标准JSF没有.它将始终完成页面的完整刷新(嵌入时除外或在其中使用f:ajax标记)
| 归档时间: |
|
| 查看次数: |
26584 次 |
| 最近记录: |