简体   繁体   English

JSF2.0:如何在Java中的MyComponent中编写h:form?

[英]JSF2.0: How to write h:form in MyComponent in Java?

I'm writing a JSF2.0-component as a Java class and Renderer class and so on. 我正在编写一个JSF2.0组件作为Java类和Renderer类等等。 I can't write parts of the output in the xhtml like 我不能在xhtml中编写部分输出

<h:outputText ... />

because the elements are generated dynamically. 因为元素是动态生成的。

  1. So I get the message "The button/link/text component needs to have a Form in its ancestry. Please add .". 所以我收到消息“按钮/链接/文本组件需要在其祖先中有一个表单。请添加。”。 Below you can see how I currently render a form. 您可以在下面看到我目前如何呈现表单。 Is this correct too? 这也是正确的吗? Or should change something to make the warning dissappear? 或者应该改变一些东西以使警告消失?

     private void encodeForm(Element elem) throws IOException { //ResponsWriter writer writer.startElement("form", form); encodeChildren(elem); writer.endElement("form"); } 
  2. Is it possible to connect an input-field to a variable that is created during runtime (ie an Object in a List)? 是否可以将输入字段连接到在运行时创建的变量(即列表中的对象)? If yes how? 如果有,怎么样? If no: I have to implement the decode()-method right? 如果不是:我必须实现decode() - 方法吗?
  3. How should I render a button that submits such a form? 我应该如何呈现提交此类表单的按钮? It should for example call a method in my component that then somehow (how? like the decode-method?) can process the user-input. 它应该例如在我的组件中调用一个方法然后以某种方式(如何?像decode-method?)可以处理用户输入。

Thanks for any help! 谢谢你的帮助!

Is this correct too? 这也是正确的吗? Or should change something to make the warning dissappear? 或者应该改变一些东西以使警告消失?

Your best bet would be to just remove the code you've shown and ask the users of said component to place it inside a form. 您最好的选择是删除您显示的代码,并要求所述组件的用户将其放在表单中。

At any length, what you're doing is writing markup for a form. 在任何情况下,您正在做的是为表单编写标记。 This is something else than actually putting a form component in the tree. 这不是实际将表单组件放在树中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM