h:inputText not updating from bean automatically - jsf

I have an h:inputText in my form. The value is not properly updating when I update its panelGroup. JSF version is 2.1.13.
If I used disable="true" OR displaying the bean value in h:outputText OR refresh the page its updating properly. But by default its not happening.
<span style="min-width: 100px;"> First Name: #{NewPatient.newPatientBean.firstName}</span>
<h:inputText id="fname"
value="#{NewPatient.newPatientBean.firstName}"
onchange="initialCaps(this);" maxlength="50">
<f:ajax execute="#this" event="blur"/>
</h:inputText>
In the above code
First Name: #{NewPatient.newPatientBean.firstName} is properly updating but the inputText is not.
Kindly let me know the mistake and solution for the above issue. Thanks in advance.

That will happen when a validation error occurred during the current or previous postbacks. The input component will then not redisplay the model value, but only the initially submitted value when the component itself failed validation or the local value when another component in the same form failed validation.
As the concrete functional requirement is completely absent in the question, it's not possible to propose the right solution for this. So here's just a link which explains the problem more generically which should give new insights as to the cause and the solution: How can I populate a text field using PrimeFaces AJAX after validation errors occur?

Related

jsf inputtext doesn't show value from bean

I have the follow situation:
I have a bean that send to form some data, but only in outputlabel the data from the bean is displayed.
I tried to use primefaces, but the same problems persist.
my code:
<h:outputLabel value="#{Bean.name}" id="name2" />
<h:inputText value="#{Bean.name}" id="name" />
<p:inputText value="#{Bean.name}" id="name3" />
Any idea why?
You should have given the bean's code also, to help us better analyze the problem.
Normally you should check for the following:
Check whether you are specifying a correct bean name. Normally
bean's name is same as that of class, except that first letter
should be lowercase. In your case it should be #{bean.name} or else,
specify your custom name with #Named("Bean").
Check whether the getters and setters such as getName() are properly
provided. It may happen that you might have reset the name property in
your bean in the get method itself. Because of which first time it
shows you properly in outputLabel and then in next call to getName it may give you null or empty String. To check this, try put your inputText tag first, and check.
I solve my problem.
When I tried show the values, I was trying recover data from database by pass an ajax action. So, When I clicked at button to retrieve the datas, some of my inputText were set as a required. And because this the data is just displaying into label and not inside of inputtext with required. But because ajax, the request were not called correctly.
When I remove the required from inputtext, it works fine.

Input fields not clearing after the validation fails

I have a form, it contains username and password etc... if i gave any wrong value the validation will fail. next if i see the form na that previously given values are coming in the input fields.. i cleared the bean values also. but the input fields are not yet cleared.
i have cleared the input fields using the following link 1st step.
https://cwiki.apache.org/MYFACES/clear-input-components.html
this is working but what the problem is this is working only in <rich:datatable> 1st page.
if i have navigate to second page and next pages and all that Popup panel itself not opening.
i am using the jsf version 2.0,
Please provide a good solution.
Thanks,
You can add OmniFaces Library to your project and use their ResetInputAjaxActionListener
Like this
<h:commandButton value="Update" action="#{bean.update}">
<f:ajax execute="#this" render="#form" />
<f:actionListener type="org.omnifaces.eventlistener.ResetInputAjaxActionListener" />
</h:commandButton>
Read more about it on BalusC blog Reset non-processed input components on ajax update
Are you using session scope ? Change it to request scope. Otherwise, add your xhtml page and bean class.

JSF/Richfaces/A4j ==> component/field conversion and reRendering problem

I have an input field in a JSF Page like the following (maps to BigDecimal on backing bean)
<h:inputText disabled="#{volumeBean.grossVolumeDisabled}" id="grossVolume" size="10" validateOnExit="true" value="#{volumeBean.enteredGrossVolume}" >
<a4j:support ajaxSingle="true" event="onblur" ignoreDupResponses="true" oncomplete="checkFieldValidation(this)" onsubmit="updateDirty()"/>
</h:inputText>
And an a4j:commandButton to "refresh" all the data from the database on the page:
<a4j:commandButton accesskey="T" action="#{volumeBean.revert}" button-type="ajax" disabled="#{volumeBean.revertDisabled}" id="volumeBean_reset" immediate="true" reRender="volumesTable" value="#{msg.button_RESET}"/>
Here are the steps to reproduce my problem:
And please note that the error occurs regardless of whether there is a reRender attribute set on the a4j:support
Here are the steps to reproduce - just to clarify further:
navigate to the screen where the BigDecimal input field exists
type aa into the field (should be a number but put non-numeric characters purposely)
tab off the field
notice that an error is reported 'aa' is not a valid netVolume
click on the RESET button
all of the changed fields have their original values EXCEPT those that have non-numeric data entered
unless the user manually deletes the non-numeric data in the fields or refreshes the entire screen, the "bad data" sticks
When you do a reset, you fire an Ajax request, the entire form is submitted and you get validation error again. So the field still has the old (incorrect) value.
Try adding the parameter ajaxSingle="true" to the button. I've found that immediate="true" is not adequate for bypassing validation on ajax components.

rendered attribute on inputText

I have a search form tied to a backing bean that contains 4 input text fields. The design i am working from indicates that the user should be able to see the search results, but they should not be editable. i decided to use the rendered attribute to show the inputs if the managed bean is empty, and to show an output text tag if it's not:
<t:inputText styleClass="inputText" id="name" rendered="#{not searchCriteria.fieldsEntered}"
value="#{searchCriteria.name}" autocomplete="off"></t:inputText>
<h:outputText value="#{searchCriteria.name}" rendered="#{searchCriteria.fieldsEntered}"></h:outputText>
The display part works correctly, but I am noticing that only the first field is stored in the managed bean when more than 1 search field is entered.
I removed a rendered attribute from an inputText, and sure enough that's causing my problems. I can infer what's going on here, but I don't understand why.
I believe in this situation I will just remove the outputText tags and change rendered to disabled. I am just curious why my initial plan is incorrect.
The rendered="false" will cause the input element not being rendered and thus its value will not be submitted to the server side. If you're using a request scoped bean, the initial value will not be set. You'd like to either put the bean in session scope or to add a h:inputHidden along the h:outputText which transfers the value to the subsequent request.
Since you're already using Tomahawk's t:inputText I'd suggest to rather use its displayValueOnly attribute instead of the rendered attribute and a complementary h:outputText.
In a nut:
<t:inputText displayValueOnly="#{searchCriteria.fieldsEntered}" ... />

ReRendering a JSF Component

Can I rerender a jsf ui component when a valuechangelistener method is run?
The reason i'm asking is that my valuechangelistener method changes the values of the input boxes in the backing bean but they don't seem to be rerender.
What happens eventually is that the values that are printed on screen are saved to the backing bean, overriding the values loaded through the valuechangelistener method.
The following doesn't work:
<h:inputText id="inputbox_id" value="#{name}"/>
<h:selectOneMenu valueChangeListener="#{myBean.changeCountryMenu}">
<a4j:support event="onchange" rerender="inputbox_id" action="#{bean.test}>
</h:selectOneMenu>
Notice that bean.test() is never run. (UPDATE: It does, I had a renderResponse() that skipped it before. The values still do not reRender though)
So the solution I thought of is to rerender the inputbox from the valueChangeListener.
If there is some other better solution i'd be glad to hear...
Thank you!
Ben.
The attribute name is reRender (with capital R the second time). Perhaps you have to add immediate="true" ?
Also, check this article

Resources