[英]Update Bean Property of a <rich:dataTable> using JavaScript in JSF
I have a <rich:dataTable>
and want to update the bean property
with 'onclick' using JavaScript
. 我有一个<rich:dataTable>
并且想使用JavaScript
使用'onclick'更新bean property
。 Please Find the tried posted code, 请找到尝试过的发布代码,
JSF Code JSF代码
<rich:dataTable value="#{myBean.beanList}"
rowIndex="rowIndex"
var="beanName">
<facet name="header">
<rich:column>
<h:outputText value="Sample Header"/>
</rich:column>
</facet>
<rich:column>
<a4j:commandLink value="Apple"
onclick="modifyScript(#{beanName.booleanProperty})"> <%--Calling modifyScript--%>
<a4j:jsFunction name="jsFunction">
<a4j:actionparam name="actionParam"
assignTo="#{beanName.booleanProperty}"/>
</a4j:jsFunction>
</a4j:commandLink>
</rich:column>
</rich:dataTable>
JavaScript 的JavaScript
function modifyScript(booleanProperty)
{
booleanProperty = !booleanProperty; <%--Modifying the bean property--%>
historyAllocatedFunction(booleanProperty); <%--Calling the JS Function to assign the updated bean property--%>
}
I strictly do not want to use action
and oncomplete
attributes of <a4j:commandLink>
, because I do not want to call the server
for updating the bean property
. 我严格不希望使用<a4j:commandLink>
action
和oncomplete
属性,因为我不想调用server
来更新bean property
。
The above code is not working fine, everytime it is taking the LastIndex of the <rich:dataTable>
. 上面的代码每次使用<rich:dataTable>
的LastIndex时都无法正常工作。
Help me in accessing the list based on the rowIndex
. 帮助我基于rowIndex
访问列表。
You can assign the bean property beanName.booleanProperty
to a hidden input. 您可以将bean属性beanName.booleanProperty
分配给隐藏的输入。 Like this 像这样
<rich:column>
<a4j:commandLink value="Apple" onclick="modifyScript(#{rowIndex})"></a4j:commandLink>
<h:inputHidden value="#{beanName.booleanProperty}" id = "hiddenInput"></h:inputHidden>
</rich:column>
Then using JS, you change the value of the hidden input. 然后,使用JS更改隐藏输入的值。 When the form is submitted, the hidden input will be assigned to server side bean property. 提交表单后,隐藏的输入将分配给服务器端bean属性。
Javascript Java脚本
function modifyScript(index)
{
$j("#formId\\:tableId\\:hiddenInput\\:" + index).value('<new-value>');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.