こんにちは、拡張するカスタム コンポーネントを作成しようとしていますUIInput
。そのコンポーネントでは、1 つの HTML 入力、1 つの HTML 送信ボタン、および 1 行のテキストを生成します。コードは以下のとおりです。
@Override
public void decode(FacesContext context) {
Map requestMap = context.getExternalContext().getRequestParameterMap();
String clientId = getClientId(context);
char sep = UINamingContainer.getSeparatorChar(context);
String symbol = ((String) requestMap.get(clientId + sep + "inputfield"));
setSubmittedValue(symbol);
}
@Override
public void encodeEnd(FacesContext context) throws IOException {
String clientId = getClientId(context);
char sep = UINamingContainer.getSeparatorChar(context);
//-----------------------this generates an html input-------------------------
encodeInputField(context, clientId + sep + "inputfield");
//Now if I uncomment the next line it generates another html, whose value always stays the same as the first one
//encodeInputField(context, clientId + sep + "inputfield2");
encodeSubmitButton(context, clientId + sep + "submit");
encodeOutputField(context);
}
private void encodeInputField(FacesContext context, String clientId) throws IOException {
// Render a standard HTML input field
ResponseWriter writer = context.getResponseWriter();
writer.startElement("input", this);
writer.writeAttribute("type", "text", null);
writer.writeAttribute("name", clientId, "clientId");
Object value = getValue();
if (value != null) {
writer.writeAttribute("value", value.toString(), "value");
}
writer.writeAttribute("size", "6", null);
writer.endElement("input");
}
private void encodeSubmitButton(FacesContext context, String clientId) throws IOException {
// render a submit button
ResponseWriter writer = context.getResponseWriter();
writer.startElement("input", this);
writer.writeAttribute("type", "Submit", null);
writer.writeAttribute("name", clientId, "clientId");
writer.writeAttribute("value", "Click Me!", null);
writer.endElement("input");
}
private void encodeOutputField(FacesContext context) throws IOException {
ResponseWriter writer = context.getResponseWriter();
//----------------weird value that comes out of nowhere-----------------------
String hellomsg = (String) getAttributes().get("value");
writer.startElement("p", this);
writer.writeText("You entered: " + hellomsg, null);
writer.endElement("p");
}
value
これですべて正常に動作しますが、属性がどこにString hellomsg = (String) getAttributes().get("value");
来るのかわかりません。このプログラムをデバッグしようとしましたが、getAttributes()
ハッシュマップにも奇妙なエントリが含まれており、キーが であるエントリが見つかりませんでし"value"
た。
最後に、2 つの html 入力を生成すると、2 番目の入力の値は常に最初の値と同じになります。
value
また、タグにa を含めることができることにも気付きました。たとえば<mycc:cinput value="yes">
、ページが読み込まれると、生成された html 入力の値が に設定されyes
ます。
私の疑問は次のとおりです。すべての UIInput にデフォルトvalue
属性がありますか? もしそうなら、その属性値は常にHTML入力のvalue
属性にリンクされていますか? value
もしそうなら、生成された最初のhtml入力の属性に常にリンクされていますか?
このような長い質問を読んでくれてありがとう。可能であれば、このような問題の解決策をどこで見つけられるか教えていただけますか? ランダムなGoogle検索結果をブラウジングして頭が痛いです@_@
どうもありがとう!