Nel codice seguente l'azione commandButton di jsf html viene chiamata perfettamente. Ma l'azione commandButton di primefaces non viene chiamata.PrimoFaces CommandButton Azione non chiamata all'interno di Composite
<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>
Se posto lo stesso codice è al di fuori di un composito (una normale pagina XHTML), entrambi funzionano bene:
<!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>
Questo è il codice di fagioli:
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;
}
}
Qualche suggerimento?
pulsante non viene licenziato, se non viene elaborato. ha senso. – erencan
Non lo fa, poiché l'attributo "processo" indica quali * altri * campi devono essere elaborati/inviati. L'impostazione "@questo" nell'attributo di processo non è richiesta per i pulsanti all'esterno di un composito. E, se lo fosse, sarebbe almeno "ridondante". –
Vorrei poterlo sospendere più di una volta. Questa è la risposta giusta, o dovrei dire @questo. Anche nel 2018 con le primeface 6. Non ho mai avuto problemi con p: l'attivazione di CommandButton fino a quando ne ho inserito uno in un composito. –