JSF 托管 bean
大家好,
我对这一切都很陌生,可能这将是一个愚蠢的问题,但
我有一个托管 bean,它有一个属性花 - 字符串,和一个属性列表 -
xhtml 中的花束,我有一个 h:inputText女巫,你应该输入一个花名,当你单击 ah:command 按钮时,它会调用一个操作 #{managementBEan.addFlower},在 addFlower 中,我想添加用户输入的花名并添加到列表中 --- 我正在使用 ah :form
但当我单击按钮时,jsf 似乎没有调用属性的 set 方法,flower 属性的值为 null,就像她声明的那样,
谢谢您的建议, 亚历克斯
Hy all,
i am new with all of this,and probably this would be a dumb question,but
i have an managed bean that has a property flower - String, and a property List - bouquet
in a xhtml i have an h:inputText in witch you should type a flower name and when you click a h:command button it callas an action #{managedBEan.addFlower}, in addFlower i want to add the flower name typed by the user and added in list --- i am using a h:form
but it seems that the set method for property aren't called by jsf when i click the button, the flower property have null as value, like she was declared
thank you for your sugestions,
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Bean:
Xhtml
这就是你所要做的一切。带有 get 和 set 的花朵实例以及“value”属性中带有花朵名称的
h:inputText
。当您单击按钮时,键入的值将放入 value 引用的属性中,因此如果您打印
flower.name
(在 addFlower 方法中),您将能够看到用户输入。actionListener
也可以工作,但您需要检查您为ActionEvent
使用的导入。 IDE 总是导入java.awt.event.ActionEvent
但正确的是javax.faces.event.ActionEvent
...java.awt
不会不起作用,我想这就是为什么你的方法没有被调用的原因。Bean:
Xhtml
Thats all you have to do. A instance for flower with get and set and a
h:inputText
with the flower name in "value" property.When you clicks the button, the value typed will be put in the property referenced in value, so if you print the
flower.name
(in addFlower method) you will be able to see the user input.actionListener
works too, but you need to check wich import you are using forActionEvent
. IDE always importjava.awt.event.ActionEvent
but the right one isjavax.faces.event.ActionEvent
...java.awt
doesn't work and I guess thats why your method is not called.您必须声明一个 actionListener,如下所示:
并且在您的 bean 中,您必须定义
执行该作业的 addFlower。
You have to declare an actionListener, like this:
and in your bean you must define addFlower
that execute the job.
标签是否围绕输入和按钮?
否则输入将不会被发送。
Does an tag surround both, the input and the button?
Otherwise the input will not be sent.