javaScript for ADF Faces 1.1 within a loop
-
30-09-2019 - |
문제
I am having issue with my js function within a ADF Faces af:interator. I have 3 controls within an af:iterator (af:ouputText, af:inputText, af:selectBooleanCheckBox) and I would like to have a js function on the checkbox so that when checking the checkbox, the text of the ouputText will be copied into the inputText.
The issue here is that within the af:iterator, adf will generate its own id or append a weird number for the ids and I am not sure if I should rely on those generated ids to write my js function. I know that I should be using PPR for this, but I can't.
Thank you very much!
해결책
You can use a combination of <af:clientAttribute/> and <af:clientListener/>
and some javascript to achieve this behavior.
You will also need to set clientComponent to true on the <af:inputText/>
.
This works in my test program.
<af:document id="d1">
<af:resource type="javascript">
function copyFromTo(evt) {
fromValue = evt.getSource().getProperty('fromValue');
fromIndex = evt.getSource().getProperty('fromIndex');
// iterator ID, then fromIndex, then inputText ID
id = 'i1:'+fromIndex+':it1';
inputComponent = AdfPage.PAGE.findComponentByAbsoluteId(id);
inputComponent.setValue(fromValue);
}
</af:resource>
<af:form id="f1">
<af:panelStretchLayout id="psl1">
<f:facet name="center">
<af:iterator id="i1" value="#{PageBean.outputTextValues}" var="row" varStatus="rowStatus">
<af:panelGroupLayout id="pgl1" layout="horizontal">
<af:selectBooleanCheckbox label="Copy" id="sbc1">
<af:clientAttribute name="fromValue" value="#{row}"/>
<af:clientAttribute name="fromIndex" value="#{rowStatus.index}"/>
<af:clientListener method="copyFromTo" type="click"/>
</af:selectBooleanCheckbox>
<af:spacer width="10" height="10" id="s1"/>
<af:outputText value="#{row}" id="ot1"/>
<af:spacer width="10" height="10" id="s2"/>
<af:inputText label="Label 1" id="it1" value="none" clientComponent="true"/>
</af:panelGroupLayout>
</af:iterator>
<!-- id="af_one_column_stretched" -->
</f:facet>
</af:panelStretchLayout>
</af:form>
</af:document>
다른 팁
Why cant you use PPR? The js IDs should not be relied upon at all, and they will change when lets say you decide to put your taskflow in a region or inside a portlet.
The field values should be based on VO attributes, if they are not DB backed, you can create a transient VO. then update the values on the VO and call
AdfFacesContext.getCurrentInstance().addPartialTarget(JSFUtils.findComponent("<comp_id of parent component>"));