ユーザーがテキストフィールドに挿入できる特定の記号を使用してキーボード(複合コンポーネント)を作成しています。ユーザーが選択した記号をこれらの入力値に設定するには、キーボードの属性として2つのコンポーネントp:inputTextとp:inputTextareaを定義する必要があります。問題は、コンポーネントをキーボード属性として使用できないことです。動かない。index.xhtmlファイルでinputTextを渡すにはどうすればよいですか?インデックス:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:pe="http://java.sun.com/jsf/composite/pe"
template="/pages/template/template.xhtml">
<ui:define name="content">
<p:inputText widgetVar="asd" id="asd" value="#{disciplineController.discipline.description}"/>
<pe:keyboard textField="asd"/>
<!-- How do I pass the p:inputText as attribute?
Already tried <pe:keyboard textField="#{asd}"/>, it gets null
-->
</ui:define>
</ui:composition>
キーボード
<composite:interface componentType="keyboardComponentBean">
<composite:attribute name="textField" type="org.primefaces.component.inputtext.InputText"></composite:attribute>
<composite:attribute name="textFieldArea" type="org.primefaces.component.inputtextarea.InputTextarea"></composite:attribute>
</composite:interface>
<composite:implementation>
<h:form>
<ui:repeat value="#{cc.attrs.SYMBOL_ARRAY}" var="symbol">
<ui:fragment rendered="#{symbol == cc.attrs.SYMBOL_ARRAY[0]}"> Conjuntos <br /></ui:fragment>
<ui:fragment rendered="#{symbol == cc.attrs.SYMBOL_ARRAY[11]}"> <br />Símbolos <br /></ui:fragment>
<ui:fragment rendered="#{symbol == cc.attrs.SYMBOL_ARRAY[24]}"> <br />Subscrito <br /></ui:fragment>
<ui:fragment rendered="#{symbol == cc.attrs.SYMBOL_ARRAY[39]}"> <br />Sobrescrito <br /></ui:fragment>
<ui:fragment rendered="#{symbol == cc.attrs.SYMBOL_ARRAY[55]}"> <br />Grego (maiúsculo) <br /></ui:fragment>
<ui:fragment rendered="#{symbol == cc.attrs.SYMBOL_ARRAY[65]}"> <br />Grego (minúsculo) <br /></ui:fragment>
<ui:fragment rendered="#{symbol == cc.attrs.SYMBOL_ARRAY[81]}"> <br />Setas <br /></ui:fragment>
<p:commandButton value="#{symbol}" action="#{cc.addText(symbol)}" />
</ui:repeat>
</h:form>
</composite:implementation>
</html>
FacesComponent:
package br.com.portal.education.Timer;
import javax.faces.component.FacesComponent;
import javax.faces.component.UINamingContainer;
import org.primefaces.component.inputtext.InputText;
import org.primefaces.component.inputtextarea.InputTextarea;
@FacesComponent("keyboardComponentBean")
public class Keyboard extends UINamingContainer {
private final String[] SYMBOL_ARRAY = {..símbolos..};
public String[] getSYMBOL_ARRAY() {
return SYMBOL_ARRAY;
}
public void addText(String symbol) {
Object textField = getAttributes().get("textField");
Object textFieldArea = getAttributes().get("textFieldArea");
if (textField != null){
((InputText) textField).setValue(((InputText) textField).getValue() + symbol);
}
if (textFieldArea != null){
((InputTextarea) textFieldArea).setValue(((InputTextarea) textFieldArea).getValue() + symbol);
}
}
}
入力コンポーネントをEL式にバインドできます。
<p:inputText widgetVar="asd" id="asd" binding="#{bindedAsd}" value="#{disciplineController.discipline.description}"/>
このようにして、それを属性として使用できます。
<pe:keyboard textField="#{bindedAsd}" />
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加