SetPropertyListener Problem when using with af:commandButton in oracle adf - oracle-adf

Hi I want to set a pageflowScope using setPropertyListener and when I use that in h:commandButton it works but when I use that in af:commandButton and when I hit the button it does not work but the second time I hit the button it works ... when I hit the button at the first time it should put the method result into a pageflowScope variable but it always do that in the second click ... I don't know why
here is my code
<af:panelFormLayout id="pfl2">
<af:inputText value="#{bindings.usrname.inputValue}" label="نام کاربری"
required="#{bindings.usrname.hints.mandatory}"
columns="#{bindings.usrname.hints.displayWidth}"
maximumLength="#{bindings.usrname.hints.precision}"
shortDesc="#{bindings.usrname.hints.tooltip}" id="it1">
<f:validator binding="#{bindings.usrname.validator}"/>
</af:inputText>
<af:inputText value="#{bindings.passwrd.inputValue}" label="رمزعبور"
required="#{bindings.passwrd.hints.mandatory}"
columns="#{bindings.passwrd.hints.displayWidth}"
maximumLength="#{bindings.passwrd.hints.precision}"
shortDesc="#{bindings.passwrd.hints.tooltip}" id="it2">
<f:validator binding="#{bindings.passwrd.validator}"/>
</af:inputText>
<af:button actionListener="#{bindings.execPLSQLProcedure.execute}" text="execPLSQLProcedure"
disabled="#{!bindings.execPLSQLProcedure.enabled}" id="b1">
<af:setPropertyListener from="#{bindings['return'].inputValue}"
to="#{pageFlowScope.Result}" type="action"/>
</af:button>
</af:panelFormLayout>
how can I fix it or please tell me an alternative way ...thanks

If you have to click two times for the action to trigger it is because on your first click your form hit data validation issues.
1) If you don't see it, you first need to add a partialTrigger to your button :
<af:commandButton partialTriggers="pfl2" partialSubmit="true" actionListener="#{bindings.execPLSQLProcedure.execute}" text="execPLSQLProcedure" disabled="#{!bindings.execPLSQLProcedure.enabled}" id="b1" >
<af:setPropertyListener from="#{bindings['return'].inputValue}" to="#{pageFlowScope.Result}" type="action"/>
</af:button>
whether the action should be done through a partial page submit or
not. Default is false: no partial page submit; the full page will be
refreshed. When set to true, the full page will not be refreshed. To
re-render specific components on your page in response to the partial
page submit, you have to tell ADF Faces. The easiest way to do this is
with the partialTriggers attribute.
2) If you want to bypass validation you can also add an immediate="true" attribute. In your case it doesn't look like you should as you want to validate the password length and requirement. See 1)
<af:commandButton immediate="true" partialTriggers="pfl2" partialSubmit="true" actionListener="#{bindings.execPLSQLProcedure.execute}" text="execPLSQLProcedure" disabled="#{!bindings.execPLSQLProcedure.enabled}" id="b1" >
<af:setPropertyListener from="#{bindings['return'].inputValue}" to="#{pageFlowScope.Result}" type="action"/>
</af:button>
see docs : https://docs.oracle.com/cd/E12839_01/apirefs.1111/e12419/tagdoc/af_commandButton.html
whether data validation - client-side or server-side - will be skipped
when events are generated by this component. When immediate is true,
the command's action and ActionListeners, including the default
ActionListener provided by the JavaServer Faces implementation, will
be executed during Apply Request Values phase of the request
processing lifecycle, rather than waiting until the Invoke Application
phase. Because validation runs during Process Validators (after Apply
Request Values, but before Invoke Application), setting immediate to
true will skip validation.

Related

Redirect from any component to another page in adf

Hello im new on af and I´m trying to redirect by clicking on any adf component to another page. But i dont want to use javascript only with adf and beans.
I have been looking for something similar to the onclick of javascript that you can use it on any html element and with a click you can invoke a function.
On my test i had tried to redirect to another page by clicking on a af:inputText like when i click on an af:link and execute the action with the name of the control flow case for navigate from one activity to another, looking on the documentation, the af:inputText doesn´t have any onclick/action event or something similar.
primera.jsff
<?xml version='1.0' encoding='UTF-8'?>
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:af="http://xmlns.oracle.com/adf/faces/rich">
<!--af:link When i click on it i get redirected to another jsff page on my project -->
<af:link text="link 1" id="link1" action="gonext"></af:link>
<!--I want a similar behavior here -->
<af:inputText label="Label 1" id="it1"/>
</ui:composition>
My task-flow has defined a control flow case from primera.jsff to a empty segunda.jsff named gonext
I just want the similar behavior on the af:inputText than on the af:link, but only using adf not javascript code. Thanks and sorry for the redaction.

adf selectOneChoice valueChangeListener not firing

My valueChangeListener for SelectOneChoice is not getting invoked when I am trying to select a value in the dropdown. It is invoked only when I click on the Blank Item in the dropdown (which we configure in ListOfValues).
On some research I have learnt that in your valueChangeListener, we must add
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
as our first line. But It is still not getting invoked on selection of any other value apart from null.
Code for my SelectOneChoice
<af:selectOneChoice value="#{bindings.Prefix.inputValue}"
label="#{bindings.Prefix.label}"
shortDesc="#{bindings.Prefix.hints.tooltip}"
id="soc3"
partialTriggers="formatIdId"
visible="#{bindings.Prefix.hints.visible}"
binding="#{backingBeanScope.CreateItemBackingBean.prefixField}"
required="#{bindings.ItemNumberType.attributeValue eq 'VPLU'}"
showRequired="#{bindings.Prefix.hints.mandatory}"
validator="#{backingBeanScope.CreateItemBackingBean.onValidatePrefix}"
autoSubmit="true"
valueChangeListener="#{backingBeanScope.CreateItemBackingBean.onChangePrefix}">
<f:selectItems value="#{bindings.Prefix.items}" id="si3"/>
<af:convertNumber groupingUsed="false"
pattern="#{bindings.Prefix.format}"/>
</af:selectOneChoice>
Code for my ValueChangeListener
public void onChangePrefix(ValueChangeEvent vce) {
vce.getComponent().processUpdates(FacesContext.getCurrentInstance());
System.out.println("vce.getOldValue()"+vce.getOldValue());
System.out.println("vce.getNewValue()"+vce.getNewValue());
System.out.println("I am in changed prefix");
}
valueChangeListener will fire only when you submit form. You can use any submit action for it or just turn on autosubmit property on component.
If you need to catch selection event without actually submitting data, you should use clientListener and handle it with javascript functions.
It may be your required tag preventing the valueChangeListener from firing.
required="#{bindings.ItemNumberType.attributeValue eq 'VPLU'}"
If "required" returns true, valueChangeListener won't be executed.
Also, remove "showRequired" attribute completely. Is not only not necessary, but is confusing because it has a different condition than "required" attribute.
Try a bit of debugging and set required="false".You can also remove "validator", "visible", see if it works without them, then add them back one by one.

Why submit called from inside of panelCollection doesn't submit data changes from the rest of page

My application is build using Oracle ADF 11gR1 (JDeveloper 11.1.1.7.0), and I have a problem with data submitted by commandLink placed inside of panelCollection.
I have following page fragment structure:
<af:panelAccordion id="pa1">
<af:showDetailItem id="sdi1">
<af:panelFormLayout id="panelFormLayout1">
<af:inputText value="#{bindings.C11.inputValue}" id="it34" />
<af:inputText value="#{bindings.N04.inputValue}" id="it32" />
<af:selectOneChoice value="#{bindings.N13.inputValue}" id="soc4" autoSubmit="true" >
<f:selectItems value="#{bindings.N13.items}" id="si4"/>
</af:selectOneChoice>
...
</af:panelFormLayout>
<af:showDetailItem>
...
<af:showDetailItem id="sdi4">
<af:panelCollection id="pc2">
<af:table value="#{bindings.Table.collectionModel}"
var="row" rows="#{bindings.Table.rangeSize}"
filterModel="#{bindings.Table.queryDescriptor}"
queryListener="#{bindings.Table.processQuery}"
varStatus="vs"
selectedRowKeys="#{bindings.Table.collectionModel.selectedRow}"
selectionListener="#{bindings.Table.collectionModel.makeCurrent}"
rowSelection="single" id="t2">
<af:column id="c19">
<af:commandLink id="cl1" textAndAccessKey="#{row.bindings.C0.attributeValue}" actionListener="#{pageFlowScope.Bean.handle}"/>
</af:column>
<af:column id="c17">
<af:inputText value="#{row.bindings.C1.inputValue}" id="it17" />
</af:column>
<af:column id="c16">
<af:inputText value="#{row.bindings.C2.inputValue}" id="it42" />
</af:column>
...
</af:table>
</af:panelCollection>
</af:showDetailItem>
</af:panelAccordion>
CommandLink (id="cl1") placed in table column c19 has defined actionListener. Method of this performs operation which base on data given in selected row in table and in controls from panelFormLayout above.
When commandLink is pressed, and actionListener method fired, I see (in the results and in debug) that data changes from panelFormLayout are not submitted, except the ones which has autosubmit set to true. But if I place the same commandLink outside of panelCollection all data are submitted.
My question is how I can force submit of data from whole pageFragment when actionListener is fired from panelCollection inside?
Autosubmit on all controls outside of panelCollection doesn't seem to be a good solution because of many uncessary POST requests.
The reason for this behaviour is the had optimised lifecycle which is used for some components including table and panelAccordion. His means that the values are only submitted inside the boundary of the component. In your case it means that only the showDetailItem is submitted.
To submit the form to you have to set the id if the link as partial trigger to the form.
A detailed description can be found in this presentation http://de.slideshare.net/mobile/stevendavelaar/18-invaluable-lessons-about-adfjsf-interaction in lesson 17
Perhaps try putting the panel collection inside a subform?

ADF toggle required attribute from checkbox

In my jsff file I have some input fields which are required by default. Now we want a way to toggle the required attribute using a checkbox. Several solutions have been tested, one of them like this:
<af:selectBooleanCheckbox id="sbc1" label="myLabel" value="#{sessionBean.skipInput}" autoSubmit="true"/>
<af:selectOneChoice label="myLabel" id="soc1" partialTriggers="sbc1" value="#{sessionScope.sessionBean.someValue}" required="#{!sessionBean.skipInput}">
<f:selectItems value="#{applicationScope.applicationBean.myItems}" id="si1"/>
</af:selectOneChoice>
When I check the checkbox to set the required attribute to false, the selectOneChoice will be red indicating that no value has been selected in the drowdown. How can I prevent this and simply remove the required attribute from the dropdown?
Your solution is the right approach, but the issue is that ADF can not change the checkbox value as long as the required constraint of the choice box is not fulfilled. So you will always get the "A selection is required" message and the new value of the check box will not be updated on the server as long as there is nothing selected in the choice box.
To solve this, you need to set the immediate property on the checkbox to true to skip validation, and add a valueChangeListener to handle the changes of the checkbox and manually call the render response phase:
<af:selectBooleanCheckbox id="sbc1" label="Skip Choice"
value="#{sessionBean.skipInput}"
autoSubmit="true"
immediate="true"
valueChangeListener="#{sessionBean.toggleSkipInput}"/>
public class SessionBean {
...
public void toggleSkipInput(ValueChangeEvent vce) {
setSkipInput(Boolean.TRUE.equals(vce.getNewValue()));
FacesContext.getCurrentInstance().renderResponse();
}
}
For more information, see
http://docs.oracle.com/cd/E23943_01/web.1111/b31973/af_lifecycle.htm#CIAHCFJF
https://blogs.oracle.com/jdevotnharvest/entry/partial_submit_vs_auto_submit

h:commandLink JSF file download

I am trying to create a download link in a JSF page. The page has many richfaces fields that have validation enabled. Some have validator methods attached to them, some just have the required attribute set to true. The download link is an h:commandlink element. This link is supposed to download a file from the server. When I click on the link, validation on a few fields is triggered. How can I avoid this?
Thanks.
Either put it in a separate form,
<h:form>
... other input fields ...
</h:form>
<h:form>
<h:commandLink value="Download" action="#{bean.download}" />
</h:form>
or use immediate="true" so that all input fields which do not have this attribute set will be skipped in the process
<h:commandLink value="Download" action="#{bean.download}" immediate="true" />
The issue was with the file on the server side. Issue resolved.

Resources