有时,使用时<h:commandLink>
,<h:commandButton>
或者<f:ajax>
,在action
,actionListener
或listener
与标签相关的方法根本不被调用.或者,bean属性不会使用提交的UIInput
值进行更新.
有什么可能的原因和解决方案?
我创建了表单,我希望在新表创建时在表上显示以前的现有项目.我希望在填写表格时显示匹配的项目.但是当我尝试在没有完成表单的情况下过滤列表时,会出现验证消息,并且表格不会更新.
不知道是否可能,但我想做的事情是这样的:
<h:form id="form">
<h:outputText value="Name: "/>
<p:inputText value="#{itemsBean.name}" id="name" required="true"/>
<br/>
<h:outputText value="Description: "/>
<p:inputText value="#{itemsBean.description}" id="description" required="true"/>
<p:commandButton value="Save" update="form" actionListener="#{itemsBean.save}"/> //validate and save
<p:commandButton value="Filter" update="form" actionListener="#{itemsBean.updateItemsList}"/> //don't validate, and update the table.
<p:dataTable id="list" value="#{itemsBean.itemsList}" var="item">
<p:column>
<h:outputText value="#{item.name}"/>
</p:column>
<p:column>
<h:outputText value="#{item.description}"/>
</p:column>
</p:dataTable>
</h:form>
Run Code Online (Sandbox Code Playgroud)
我是JSF的新手.
我试图执行一个JSF2 bean方法,并在完成单击PrimeFaces的方法后显示一个对话框<p:commandButton>
.
<p:commandButton id="viewButton" value="View"
actionlistener="#{userBean.setResultsForSelectedRow}" ajax="false"
update=":selectedRowValues"
oncomplete="PF('selectedRowValuesDlg').show()">
</p:commandButton>
Run Code Online (Sandbox Code Playgroud)
<p:dialog id="selectedRowValues" widgetVar="selectedRowValuesDlg" dynamic="true">
<h:outputText value="#{userBean.selectedGroupName}" />
</p:dialog>
Run Code Online (Sandbox Code Playgroud)
当我单击命令按钮时,bean动作侦听器方法setResultsForSelectedRow
正确执行,但在方法完成时它不显示对话框.如果我删除actionlistener
,它会显示对话框.我不知道出了什么问题.
事件的执行顺序是什么?是否有可能执行actionlistener
和oncomplete
同步?
错误的代码是:
<h:form id="search_form">
<h:commandButton class="button" value="View" action="#{InfoBean.search}">
<f:ajax execute="search_form" render="linear1"></f:ajax>
<f:ajax execute="search_form" render="linear2"></f:ajax>
</h:commandButton>
<p:lineChart id="linear1" value="#{InfoBean.linearModel1}" legendPosition="e"/>
<p:lineChart id="linear2" value="#{InfoBean.linearModel2}" legendPosition="e"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
我想要做的是当我点击它时commandButton
,我想刷新这两个图表.但现在我使用了两个<ajax>
标签,其中第二个标签不起作用.
那么如何使用ajax渲染两个图表呢?
就在我以为我立即理解的时候...*叹气*
考虑以下JSF页面:
<h:inputText value="#{testBean.text}" required="true" />
<h:commandButton actionListener="#{testBean.doFoo}" value="Do Foo" />
<h:commandButton immediate="true" actionListener="#{testBean.doBar}" value="Do Bar" /><br />
<h:outputText value="#{testBean.didSomething}" />
Run Code Online (Sandbox Code Playgroud)
而这个支持bean:
public class TestBean {
private String didSomething = "Nothing done yet";
// + getter
public void doFoo() {
didSomething = "Did foo!";
}
public void doBar() {
didSomething = "Did bar!";
}
Run Code Online (Sandbox Code Playgroud)
从我所读到的所有内容中我可以期待以下内容:
当在没有为输入字段提供值的情况下尝试执行foo时,操作永远不会执行,因为在processValidationsPhase
发生错误期间,导致在此阶段之后直接重新呈现页面并显示错误消息.didSomething
保持不变的价值.(这按预期工作)
当在没有为输入字段提供值的情况下尝试执行bar时,applyRequestValuesPhase
由于immediate属性而执行该操作.变量didSomething
已更改.(这按预期工作)
接下来会发生什么,这个描述说明:
"null返回值(作为action方法的结果)导致处理继续正常进行,即验证非立即组件然后执行update-model(如果没有发生验证错误).对于返回void的动作侦听器方法,有必要调用facesContext.renderResponse();如果不需要正常流程."
由此我开始认为处理继续正常进行(因为我的动作方法既不返回结果也不返回力renderResponse()
),导致相同的验证错误.唯一的区别是它在设置后发生didSomething
.但是,这不会发生.相反,感觉网站仍然会跳过所有剩余的阶段,输入字段未被触及.它重新呈现没有错误消息. …
我们有一个更新动态包含的ajax导航菜单.包含文件各有各自的表单.
<h:form>
<h:commandButton value="Add" action="#{navigator.setUrl('AddUser')}">
<f:ajax render=":propertiesArea" />
</h:commandButton>
</h:form>
<h:panelGroup id="propertiesArea" layout="block">
<ui:include src="#{navigator.selectedLevel.url}" />
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但包含文件中的任何命令按钮在第一次单击时都不起作用.它仅适用于第二次点击.
我发现这个问题commandButton/commandLink/ajax动作/监听器方法没有被调用或输入值没有更新,我的问题在第9点描述.我明白我需要明确地包含在解决它的包<h:form>
中的ID <f:ajax render>
.
<f:ajax render=":propertiesArea :propertiesArea:someFormId" />
Run Code Online (Sandbox Code Playgroud)
但是,在我的情况下,表单ID事先是未知的.此表格最初也不会在上下文中提供.
上述方案有什么解决方案吗?
我们正在使用JSF-2.1.7和我们所有的表单发布请求.我试图证明是否使用<h:commandButton>
或<h:commandLink>
.<h:commandLink>
(href <a/>
)的外观可以使用style和jQuery来控制.
哪个推荐<h:commandButton>
或<h:commandLink>
?有什么真正的优势吗?
我必须流式传输网络摄像头视频,所以我使用ustream来做这个,它为我生成一个flash嵌入代码,我有一个关闭/打开灯的按钮,但是当我按下按钮时它会刷新整个页面,所以flash组件.
有一些方法不刷新页面仍然发送到命令?那么现在就是这样:
<h:form id="form_supervisory">
<h:panelGrid>
<h:column>
<iframe width="480" height="296" src="http://www.ustream.tv/embed/9599890" scrolling="no" frameborder="0" style="border: 0px none transparent;"> </iframe>
<h:commandButton value="Lâmpada" action="#{supervisoryc.invertBo}" />
<h:graphicImage value="#{supervisoryc.imageBo}" />
</h:column>
</h:panelGrid>
</h:form>
Run Code Online (Sandbox Code Playgroud) 我需要通过POST点击a在新窗口中打开一个JSF页面<h:commandButton>
.我知道我可以使用JavaScript实现这一点.但我想使用JSF而不是JavaScript来实现这个目标.
我怎样才能做到这一点?我正在使用JSF 2.0.
我知道我们需要显式添加process="@this"
以获取p:commandbutton
调用的操作,并且我也知道process属性默认为@form
primefaces.
由于进程是默认的,@form
因此按钮也不会与表单中的其他元素一起处理,并且应该调用其操作.
任何人都可以解释这背后的确切原因吗?
commandbutton ×10
jsf ×10
jsf-2 ×7
commandlink ×3
primefaces ×3
action ×2
ajax ×1
forms ×1
http-post ×1
new-window ×1
refresh ×1
validation ×1