1
I need you to change the value of the Levelno input to 0 the factoryCode input is disabled, and otherwise nothing should happen. I have the following code:
<p:inputMask id="LevelNo" size="4" maxlength="9" mask="9?99999999" slotChar="" style="text-align: right;" value="#{MeuManageBean.requestDTO.levelNo}" rendered="#{MeuManageBean.mode eq 'MODE_NEW_REGISTER' or MeuManageBean.mode eq 'MODE_COPY_NEW' or MeuManageBean.mode eq 'MODE_EDIT'}">
<f:validateLongRange minimum="0" />
<f:convertNumber integerOnly="true"/>
<p:ajax event="change" process=" @this" update="@form" listener="#{MeuManageBean.enableOrDisableFieldsByLevelNo}" />
</p:inputMask>
<p:inputText id="factoryCode" size="4" value="#{MeuManageBean.requestDTO.factoryCode}" rendered="#{MeuManageBean.mode eq 'MODE_NEW_REGISTER' or MeuManageBean.mode eq 'MODE_COPY_NEW' or (MeuManageBean.mode eq 'MODE_EDIT' and MeuManageBean.disabledFieldsLevelZero == false) }" readonly="#{MeuManageBean.disabledFieldsLevelZero}" required="true">
<f:converter converterId="com.projeto.converter.UpperCaseConverter" />
</p:inputText>
The way it is, when I change the value of the factoryCode field and then change the value of Levelno, jsf deletes the value of the factoryCode field, because in the component tree the value is still "", if to disable the system has the expected behavior, otherwise the behavior expected by the user is that the value is maintained.
If I put the factoryCode in the ajax process, the system presents the validation error, because the field is required, I cannot put the immediate="true", because I need the component to be updated with ""if it has already been filled and I have other behaviors that I need to maintain even in ajax, as this is only part of my code.
Does anyone have any idea, how to achieve the behavior I hope using the ajax of primafaces
The validation error you give when you place to process
factoryCode
together is because of therequired="true"
?– falsarella
He even tried something like
required="#{MenuManageBean.requestDTO.levelNo ne '0'}"
?– falsarella
If this alternative doesn’t work, I think the way is to go via Javascript, disabled by hand, no onchange: http://stackoverflow.com/q/9651552/1064325
– falsarella
1 The error that gives, yes is the required true@falsarella
– Priscila Almeida
required="#{Menumanagebean.requestDTO.levelNo ne '0'}" is already like this, it does not validate, but if it is filled it erases because I need to update the form to recognize it and the lightNo as 0. Because in the case of update it still thinks that Menumanagebean.requestDTO.levelNo is not 0 and does not validate
– Priscila Almeida
In which situation does it fall into disabledFieldsLevelZero==false? It may be that it is erasing in this case?
– falsarella
works with the screen flow perfectly, but it does not validate pq for the "backend", ie the component list the value of the levelNo has not been changed yet so it does not validate when it has to validate, because of the code ** required="#{Menumanagebean.requestDTO.levelNo ne '0'}"**
– Priscila Almeida
It erases because the process is
@this
. You need to put@form
tbm, or at least those of the fields, otherwise update will bring the same old value.– falsarella
if I put @form it validates, because I may be changing from 1 to 2, for example, and in this case it is not 0 and validates.
– Priscila Almeida
About the Javascript solution, instead of putting the disable/enable logic on the onchange, put it on the oncomplete or onsuccess of p:ajax.
– falsarella
Strange it validate. Would it be
ne 0
, instead ofne '0'
? What is the type of the variablelevelNo
?– falsarella
Ah, yes, and I forgot to mention that in the Javascript life solution, you would change the process and update to
@this
.– falsarella