我有一个特定的要求,我必须通过 selectOneMenu 的 onchange 事件更新 dataTable 但似乎 dataTable 不是得到更新。我尝试使用 triggerChange() 函数,但没有成功。请找到我尝试过的以下代码。
xhtml
<p:selectOneMenu id="id" style="width:250px"
value="#{priceCharterMBean.traffic.id}"
required="true"
requiredMessage="Traffic is required"
filter="true"
filterMatchMode="startsWith"
widgetVar="w_menu"
onchange="updateTable();">
<p:ajax event="change" process="@this"
listener="#{priceCharterMBean.loadTEI}"
update="aTEModelList"
immediate="true"
partialSubmit="true" />
<f:selectItem itemLabel="Select" itemValue=""
noSelectionOption="true" />
<f:selectItems value="#{priceCharterMBean.trafficModelList}"
var="traffic" itemLabel="#{traffic.loadTrafficList}"
itemValue="#{traffic.id}" />
</p:selectOneMenu>
<p:dataTable style="width:350px" id="aTEModelList" var="aTEModelList" value="#{priceCharterMBean.aTEModelList}" rowKey="#{aTEModelList.id}">
<p:column style="display: none">
<f:facet name="header">
<h:outputText value="Expense Id" />
</f:facet>
<h:outputText id="expId" value="#{aTEModelList.id}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Expense Short Description" title="#{text.expenseshortdescription}" />
</f:facet>
<h:outputText id="expenseShortDesc" value="#{aTEModelList.expenseShortDescription}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Actual Expense Value" title="#{text.actualexpensevalue}" />
</f:facet>
<h:inputText id="actualTrafficExpense" maxlength="8" value="#{aTEModelList.actualTrafficExpense}" />
</p:column>
</p:dataTable>
javascript
function updateTable() {
w_menu.triggerChange();
}
上面的函数没有被调用,并且 dataTable 中的值保持不变,即使我更改了下拉列表中的值。
最佳答案
将 process、immediate、partialSubmit 放在一起是没有意义的。
现在 ajax 的主要目的是调用 triggerChange() 因此不需要通过 onchange 事件手动触发它。
尝试通过以下方式简化流程:
<p:selectOneMenu value="#{priceCharterMBean.traffic.id}">
<p:ajax process="@this" update="aTEModelList"
oncomplete="console.log('validation: ' + args.validationFailed)" />
</p:selectOneMenu>
你应该检查你的控制台输出,我包含了 oncomplete 只是为了确保你没有任何阻止更新过程的验证错误。
如果您有任何验证错误,您应该在这一点上努力以实现您的目标。
注意:事件的默认值为change。
关于javascript - triggerChange() 函数在 JSF 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26730677/
我想在一个没有Sass引擎的类中使用Sass颜色函数。我已经在项目中使用了sassgem,所以我认为搭载会像以下一样简单:classRectangleincludeSass::Script::FunctionsdefcolorSass::Script::Color.new([0x82,0x39,0x06])enddefrender#hamlengineexecutedwithcontextofself#sothatwithintemlateicouldcall#%stop{offset:'0%',stop:{color:lighten(color)}}endend更新:参见上面的#re
如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象
在Rails4.0.2中,我使用s3_direct_upload和aws-sdkgems直接为s3存储桶上传文件。在开发环境中它工作正常,但在生产环境中它会抛出如下错误,ActionView::Template::Error(noimplicitconversionofnilintoString)在View中,create_cv_url,:id=>"s3_uploader",:key=>"cv_uploads/{unique_id}/${filename}",:key_starts_with=>"cv_uploads/",:callback_param=>"cv[direct_uplo
我正在尝试用ruby中的gsub函数替换字符串中的某些单词,但有时效果很好,在某些情况下会出现此错误?这种格式有什么问题吗NoMethodError(undefinedmethod`gsub!'fornil:NilClass):模型.rbclassTest"replacethisID1",WAY=>"replacethisID2andID3",DELTA=>"replacethisID4"}end另一个模型.rbclassCheck 最佳答案 啊,我找到了!gsub!是一个非常奇怪的方法。首先,它替换了字符串,所以它实际上修改了
我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。问题1)我想知道rubyonrails是否有功能类似于primefaces的gem。我问的原因是如果您使用primefaces(http://www.primefaces.org/showcase-labs/ui/home.jsf),开发人员无需担心javascript或jquery的东西。据我所知,JSF是一个规范,基于规范的各种可用实现,prim
如何在Ruby中按名称传递函数?(我使用Ruby才几个小时,所以我还在想办法。)nums=[1,2,3,4]#Thisworks,butismoreverbosethanI'dlikenums.eachdo|i|putsiend#InJS,Icouldjustdosomethinglike:#nums.forEach(console.log)#InF#,itwouldbesomethinglike:#List.iternums(printf"%A")#InRuby,IwishIcoulddosomethinglike:nums.eachputs在Ruby中能不能做到类似的简洁?我可以只
说在前面这部分我本来是合为一篇来写的,因为目的是一样的,都是通过独立按键来控制LED闪灭本质上是起到开关的作用,即调用函数和中断函数。但是写一篇太累了,我还是决定分为两篇写,这篇是调用函数篇。在本篇中你主要看到这些东西!!!1.调用函数的方法(主要讲语法和格式)2.独立按键如何控制LED亮灭3.程序中的一些细节(软件消抖等)1.调用函数的方法思路还是比较清晰地,就是通过按下按键来控制LED闪灭,即每按下一次,LED取反一次。重要的是,把按键与LED联系在一起。我打算用K1来作为开关,看了一下开发板原理图,K1连接的是单片机的P31口,当按下K1时,P31是与GND相连的,也就是说,当我按下去时
我需要一个通过输入字符串进行计算的方法,像这样function="(a/b)*100"a=25b=50function.something>>50有什么方法吗? 最佳答案 您可以使用instance_eval:function="(a/b)*100"a=25.0b=50instance_evalfunction#=>50.0请注意,使用eval本质上是不安全的,尤其是当您使用外部输入时,因为它可能包含注入(inject)的恶意代码。另请注意,a设置为25.0而不是25,因为如果它是整数a/b将导致0(整数)。
我目前正在尝试学习RubyonRails和测试框架RSpec。assigns在此RSpec测试中做什么?describe"GETindex"doit"assignsallmymodelas@mymodel"domymodel=Factory(:mymodel)get:indexassigns(:mymodels).shouldeq([mymodel])endend 最佳答案 assigns只是检查您在Controller中设置的实例变量的值。这里检查@mymodels。 关于ruby-o