JSF 2.0でコンポジットコンポーネントを使用する方法を学んでいます。JSF 2.0コンポジットコンポーネント内のメソッドの呼び出しに失敗しました
まず、このコンポーネントを作成しました。 これはmanagedBeanを宣言し、managedBeanのメソッドを直接呼び出します。
<h:commandButton
action = "#{cc.attrs.managedBean.toogleEditing}"
value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}"
update = "componentes"/>
これは、成分の完全なコードである:私は、メソッドの属性を作成し、この第二の試験で
<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>
<h:commandButton
action = "#{cc.attrs.managedBean.toogleEditing}"
value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}"
update = "componentes"/>
<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>
。
<composite:attribute
name = "action"
method-signature = "void action()"
required = "true"/>
上記の他のバージョンではなく、managedBeanからメソッドを呼び出す代わりに属性を使用してメソッドを呼び出します。
<h:commandButton
action = "#{cc.attrs.action}"
value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}"
update = "componentes"/>
This is the code of the second component:
<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:attribute
name = "action"
method-signature = "void action()"
required = "true"/>
</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>
<h:commandButton
action = "#{cc.attrs.action}"
value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}"
update = "componentes"/>
<p:commandButton
action = "#{cc.attrs.action}"
value = "#{cc.attrs.managedBean.editing?'Back':'Edit'}"
update = "componentes"/>
</h:panelGrid>
</h:form>
</f:view>
</composite:implementation>
</ui:component>
これは私が両成分呼び出しXHTMLページである:問題は、私は両方のコンポーネントを呼び出す場合、このいるindex.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"
xmlns:components="http://java.sun.com/jsf/composite/components">
<h:head id="head">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Editable HTML Text Sample</title>
</h:head>
<h:body id="body">
<f:view contentType="text/html">
<h:form>
<p:panel header="Editable HTML Text Sample">
<components:EditableHTMLText
managedBean = "#{editableHTMLText}"/>
</p:panel>
<p:panel header="Editable HTML Text Sample Direct Action">
<components:EditableHTMLTextPrimeFaces
managedBean = "#{editableHTMLText}"
action = "#{editableHTMLText.toogleEditing}"/>
</p:panel>
</h:form>
</f:view>
</h:body>
</html>
を属性タグ)が機能しません。 index.xhtmlの最初のコンポーネントについてコメントします。第二よりもうまく動作します。 何らかの矛盾がなければなりませんが、理由はわかりません。 ヒント?
そして、これは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;
}
}