Primefaces Filled Field Automatically [duplicate] - jsf

This question already has answers here:
Clear JSF form input values after submitting
(5 answers)
Closed 5 years ago.
I'm developing a project using JSF and Primefaces and I got some forms.
Every time I open those forms all fields are already filled with the last information I saved on database.
I'd like every time I open those forms all fields were blank.
How can I do this?
Thank you!!

What Scope are you using in your managed bean? if you are using session scope for example it will hold the last values of your bean properties as long as the application session exists. Depending on what you doing, I would use request scope instead. This will delete the bean when it is not being use and therefore clear the values when you request again. Or perhaps view scope, this will keep the values as long as you are in the same view. Another way would be to use javascript to clear the values by Ids.

if u are using
#SessionScoped
Try to change to :
#ViewScoped

Related

How to get id from request/response in JSF? [duplicate]

This question already has answers here:
How to find out client ID of component for ajax update/render? Cannot find component with expression "foo" referenced from "bar"
(6 answers)
Closed 4 years ago.
I have such id of dialog form form:processFilterPanel_fpanel_tv:dialogFormIO:j_idt195:ItemWidget_input
And I want to work with one element of form at backend side. The problem that this part of id j_idt195 is always changing by jsf (when it starts a new session) and I don't know how to get it. Have any ideas?
Just use id="yourFavId" on the component and reference it.
JSF gives those weird looking ids to the html components that didn't have a defined one.

How can I add 'if condition' in primefaces, jsf [duplicate]

This question already has answers here:
Conditionally displaying JSF components
(3 answers)
Closed 6 years ago.
I wanna add this action.
If EL is 'true' like this, #{trueFalseBean.isTrue}, I wanna pop up message without pressing any button like 'onload();', otherwise no action. How can I use if, else clause on JSF or PF? Please help me thanks
Define a boolean variable in your bean and set it with a method when an action is started. Then use variable last situation to make something.

Is there a way to validate JSF readonly fields? [duplicate]

This question already has an answer here:
Validate readonly components anyway on form submit
(1 answer)
Closed 7 years ago.
I'm working on a JSF project using PrimeFaces and I have some custom components to facilitate the work. One of them is a search component that is formed for a input text with a button that opens a dialog. In the dialog I have a data table that lists some data. When the user chooses some record, the input text is updated with this record and the the managedbean is updated too.
To avoid curious users, that could change the value of the input text, I set this field to readonly, but the field is required. The problem arises when the user does not select a value in the datatable and the input field remains empty. In this case, JSF doesn't validate readonly fields, and my validation rules are broken when the user doesn't provide no value.
Is there a way to validate readonly fields when I submit the form?
Thanks.
Although I marked it as a duplicate (which is the correct response to the question), Some alternatives/workarounds can be created
Force the user to select something in the datatable
Disable the submit button if no value was choosen in the datatable
Do a programmatic validation in the business method that return a message if the validation fails.

passing value while using view scope in jsf

I have a table with few rows and one of the columns consists a button,now when i click on the edit button it takes me to a new JSF page.The details in the edit page are not getting populated.I am using view scope for my Managed Bean.I have gone through some of the posts and understood that view scope will be lost once the user leaves from that page.
I have gone through various other posts which suggested me to pass value to another bean and then get it into new jsf or by using f:viewparam. I wanted to know how i could achieve this functionality:
I want this flow to be achieved using view scoped managed bean JSF1-->on click of edit button in table-->View Scoped Managed Bean-->JSF2(details need to be populated but shows null values)
In the edit details page the value is shown null.
Could you let me know how I can achieve this functionality.Thanks.

JSF Back Button [duplicate]

This question already has answers here:
back commandbutton in jsf
(5 answers)
Closed 8 years ago.
How do I make a link which navigates the user back one page (i.e. same as clicking browser back)?
Thanks.
To the point: just remember the request URL or the JSF viewId of the previous page so that you can use it in the href or value of the output/commandlink. There are several ways to achieve it, depending on how you're actually navigating through the pages and how "jsfish" you want to achieve it. You could pass it as a request parameter by f:param in h:outputLink, or you could set it as a bean property by f:setPropertyActionListener in h:commandLink, or you could create a PhaseListener which remembers the viewId and make use of navigation cases, or you could grab the -much less reliable- JavaScript history.go() function.

Resources