为什么我的控制器设置器在我的 PrimeFaces 项目中不起作用?
我正在使用 Showcase 源代码作为支持,使用 PrimeFaces 2.2.1 创建一些页面。
我创建了一个与 Spinner Showcase 完全相同的页面,具有相同的结构:
<h:form prependId="false">
<p:panel header="Spinners">
<h:panelGrid id="grid" columns="2" cellpadding="5">
<h:outputLabel for="spinnerBasic" value="Basic Spinner: " />
<p:spinner id="spinnerBasic" value="#{spinnerController.number1}" />
<h:outputLabel for="spinnerStep" value="Step Factor: " />
<p:spinner id="spinnerStep" value="#{spinnerController.number2}" stepFactor="0.25" />
</h:panelGrid>
</p:panel>
<p:commandButton value="Submit" update="display" oncomplete="dialog.show()" />
<p:dialog header="Values" widgetVar="dialog">
<h:panelGrid id="display" columns="2" cellpadding="5">
<h:outputText value="Value 1: " />
<h:outputText value="#{spinnerController.number1}" />
<h:outputText value="Value 2: " />
<h:outputText value="#{spinnerController.number2}" />
</h:panelGrid>
</p:dialog>
</h:form>
然后我创建了我的 SpinnerController
与 Showcase 中的完全一样,只是将包重命名为 org.myproject.view
(这是我正在使用的包名称)。
并将其添加到我的faces-config.xml中:
<managed-bean>
<managed-bean-name>spinnerController</managed-bean-name>
<managed-bean-class>org.myproject.view.SpinnerController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
但是当我单击“提交”按钮时,对话框显示带有的所有值0 。
使用断点,我可以看到我的 getNumber1
和 getNumber2
正在运行,但 setNumber1
和 setNumber2
从未运行。我可以尝试使用旋转器或直接键入输入字段来更改值,设置器也不会运行。
有谁知道我的展示项目中缺少什么?
I'm creating some pages with PrimeFaces 2.2.1 using the Showcase source-code as support.
I created a page exactly like Spinner Showcase, with the same structure:
<h:form prependId="false">
<p:panel header="Spinners">
<h:panelGrid id="grid" columns="2" cellpadding="5">
<h:outputLabel for="spinnerBasic" value="Basic Spinner: " />
<p:spinner id="spinnerBasic" value="#{spinnerController.number1}" />
<h:outputLabel for="spinnerStep" value="Step Factor: " />
<p:spinner id="spinnerStep" value="#{spinnerController.number2}" stepFactor="0.25" />
</h:panelGrid>
</p:panel>
<p:commandButton value="Submit" update="display" oncomplete="dialog.show()" />
<p:dialog header="Values" widgetVar="dialog">
<h:panelGrid id="display" columns="2" cellpadding="5">
<h:outputText value="Value 1: " />
<h:outputText value="#{spinnerController.number1}" />
<h:outputText value="Value 2: " />
<h:outputText value="#{spinnerController.number2}" />
</h:panelGrid>
</p:dialog>
</h:form>
Then I created my SpinnerController
exactly like that one in the Showcase, only renaming the package to org.myproject.view
(wich is the package name I'm using).
And added it to my faces-config.xml
:
<managed-bean>
<managed-bean-name>spinnerController</managed-bean-name>
<managed-bean-class>org.myproject.view.SpinnerController</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
But when I click on the Submit button, the Dialog shows all values with 0
.
Using breakpoints, I can see that my getNumber1
and getNumber2
are running, but setNumber1
and setNumber2
never run. I can try to change the values using the spinners or directly typing the input field, the setters don't run as well.
Does anyone know what I'm missing in my project that exists on the Showcase project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,PrimeFaces 有时确实让人头疼。
好吧,你帮我解决了 PrimeFaces 中的 jQuery 问题。现在我想我可以帮助您解决 PrimeFaces 问题:
prependId="false"
。生成时,您的 div 可以是“j_idt10:display”。您只需将“显示”放在命令按钮上,JSF 就会负责添加第一部分 (j_idt10)。h:panelGrid id="grid"
不会被任何其他控件调用,因此它不需要该 id。这里我只是做了这些步骤,回调就可以了。
Yes, PrimeFaces really do heads burns sometimes.
Well, you helped me with my jQuery problem inside PrimeFaces. Now I think I can help you with your PrimeFaces problem:
prependId="false"
. Your div can be "j_idt10:display" when is generated. You just need to put the "display" on the command button and JSF takes care about adding the first part (j_idt10).h:panelGrid id="grid"
isn't called by any other control, so it don't need that id.Here I just did these steps and the callback is ok.