究竟是什么process,并update在PrimeFaces p:commandXxx组件和execute和render的f:ajax标签?
哪个在验证时有效?什么是update属性做,而不是更新的值从后端组件?不要process属性绑定值模型?究竟是什么@this,@parent,@all并@form在这两个属性?
下面的例子工作正常,但我对基本概念有点困惑.
<p:commandButton process="@parent"
update="@form"
action="#{bean.submit}"
value="Submit" />
Run Code Online (Sandbox Code Playgroud) 我正在使用Facelet模板技术在我正在处理的JSF 2应用程序中布局我的页面.
在我的header.xhtml中,primefaces要求菜单栏包含在h:form中.
<h:form>
<p:menubar autoSubmenuDisplay="true">
Menu Items here!
</p:menubar>
</h:form>
Run Code Online (Sandbox Code Playgroud)
所以,在我的内容页面中,我将有另一个h:form或更多.
如果我只是将h:form放在我的template.xhtml中,它会起作用吗?
<h:body>
<h:form>
<div id="top">
<ui:insert name="header"><ui:include src="sections/header.xhtml"/></ui:insert>
</div>
<div>
<div id="left">
<ui:insert name="sidebar"><ui:include src="sections/sidebar.xhtml"/></ui:insert>
</div>
<div id="content" class="left_content">
<ui:insert name="content">Content</ui:insert>
</div>
</div>
<div id="bottom">
<ui:insert name="footer"><ui:include src="sections/footer.xhtml"/></ui:insert>
</div>
<h:form>
</h:body>
Run Code Online (Sandbox Code Playgroud)
我实际上正在考虑一个用例,我需要在页面中使用多个h:form.
谢谢
我有多种形式,我有必填字段和可选字段.
要提交这样的表单,我需要对要执行的required属性进行验证,这样可以正常工作.要取消这样的形式我使用属性immediate="true"上p:commandbutton,这使得在其作用发生应用请求值 -PHASE如下处理:点击一个特定的按钮时如何跳过验证?
但是,对于大型表单,我想为用户提供一个Save-Button,以便他可以稍后继续.
为了保存当前状态,我还想忽略required-attribute的验证.但是,使用immediate="true"不起作用,因为那时我的save方法简单保存,因为JSF生命周期永远不会命中"UpdateModelValues"-Phase.(根据http://www.javacodegeeks.com/2012/01/jsf-and-immediate-attribute-command.html)
那么,如何绕过所需的检查但不跳过生命周期的一半?
我在一个字段上有一个带验证器的表单.我有两个h:commandButtons:Ok和Cancel.当我输入错误的数据并单击取消时,我会收到验证消息.当我点击取消时,我必须做什么验证器不运行?
我binding在以下问题中阅读了有关属性的组件绑定:
据我所知,它将视图中JSF标记后面的UI组件绑定到UIComponent辅助bean中的属性.但是,我很困惑组件绑定的用途以及何时应该使用它.有人可以用更简单的方式解释它并给出一些实际的例子吗?
当点击一个按钮时,如何跳过使用JSF的JSR-303 Bean验证?
解释一些方法有点冗长的问题......考虑一个表单中的列表:
<h:form id="form">
<h:commandButton value="Add row">
<f:ajax execute="foo" listener="#{bean.add()}" render="foo" />
</h:commandButton>
<h:dataTable id="foo" var="foo" value="#{bean.foos}">
<h:column>
Name: <h:inputText id="field" value="#{foo.name}" required="true" />
<h:messages for="field" />
</h:column>
<h:column>
<h:commandButton value="Remove">
<f:ajax execute=":form:foo" listener="#{bean.remove(foo)}" render=":form:foo" />
</h:commandButton>
</h:column>
</h:dataTable>
</h:form>
Run Code Online (Sandbox Code Playgroud)
当用户单击添加或删除行时,操作应该在没有验证的情况下执行.问题是,JSF重新呈现整个列表并尝试验证它.如果存在未验证的草稿更改,则会发生验证错误,并且永远不会调用侦听器方法(因为验证失败会阻止该操作).但是,添加immediate="true"到f:ajax允许方法执行,尽管有验证错误.但是,验证错误仍然会发生并显示在此处.
我看到两个选择:
1)使用immediate ="true"并且不显示验证错误
对于非验证按钮,设置immediate ="true"和h:消息:
<h:messages rendered="#{param['SHOW_VALIDATION']}" />
Run Code Online (Sandbox Code Playgroud)
然后设置保存按钮(实际上应该尝试保存表单)以发送该参数:
<h:commandButton>
<f:param name="SHOW_VALIDATION" value="true" />
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)
这会导致验证,但除非SHOW_VALIDATION存在参数,否则不会显示消息.
2)有条件地在facelets中声明验证:
<h:inputText>
<f:validateRequired disabled="#{!param['VALIDATE']}" />
</h:inputText>
Run Code Online (Sandbox Code Playgroud)
并保存按钮:
<h:commandButton>
<f:param name="VALIDATE" value="true" />
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)
这会导致字段仅在VALIDATE参数存在时进行验证(=按下保存按钮时).
但这些似乎都是一种黑客攻击.我怎样才能简单地使用JSR-303 Bean验证,但在声明时跳过它?
以下代码如何工作:
#{aaa.id}
<h:inputText id="txt1" binding="#{aaa}"/>
Run Code Online (Sandbox Code Playgroud)
我的意思是,通常组件绑定工作,通过在bean中指定属性(类型为UIComponent).这里没有bean也没有属性但是名称"aaa"被正确绑定(显示组件id - "txt1").它是如何工作的/指定的位置?
谢谢
更新:JSF2.0规范[pdf](第3.1.5章)说:
"组件绑定是一种特殊的值表达式,可用于促进将组件实例"连接"到JavaBean的相应属性...指定的ValueExpression必须指向UIComponent类型的读写JavaBeans属性(或适当的)子类)."
我试图在这篇文章中实现BalusC的答案,但当我尝试使所需的条件取决于向导外部的按钮时,它无法正常工作,我用来控制"后退"和"下一步"向导 怎么能实现这个?
<h:form id="form" enctype="multipart/form-data" acceptcharset="ISO-8859-1" >
<p:growl id="growl" sticky="true" showDetail="true"/>
<p:wizard id="wizard" flowListener="#{myBean.onFlowProcess}" showNavBar="false" widgetVar="wizardWV">
<p:tab id="tab1" title="Tab 1" >
<p:panel header="Panel for tab 1">
<p:message for="year" />
<br />
<table>
<tr>
<td>
<h:outputLabel value="Year: " />
</td>
<td>
<p:inputMask
id="year"
value="#{myBean.year}"
required="#{not empty param[nextPanel.clientId]}"
requiredMessage="Year is required!"
style="width:70px;"
mask="9999"
maxlength="4"
/>
</td>
</tr>
</table>
</p:panel>
</p:tab>
<p:tab id="tab2" title="Tab 2" >
<p:panel header="Panel for tab 2">
</p:panel>
</p:tab>
</p:wizard>
<p:commandButton id="backPanel" value="Back" onclick="PF('wizardWV').back();" styleClass="internalButton" …Run Code Online (Sandbox Code Playgroud) 我有一个包含很多组件的整个表单,包括ap:tab
当我点击p:commandButton id = c1来提交整个表单内容时:
什么是最好的解决方案?提前致谢.
jsf ×8
jsf-2 ×5
primefaces ×3
validation ×3
forms ×2
binding ×1
button ×1
components ×1
el ×1
facelets ×1
lifecycle ×1
nested ×1
process ×1
updates ×1