JSF getting current state of the check-box - jsf

I am working on a JSP project, and I need a functionality that
whenever the check-box is checked, users are REQUIRED to choose an option (from a dropdown menu)
However, whenever the check-box is unchecked, picking an option will not be required.
Right now, my check-box looks like this:
<h:selectBooleanCheckbox class="someClass" value="#{someBean.check}" />
the check is a boolean value in my JAVA class, and my html page should be able to recognize the state of checkbox.
I am wondering how to apply the current state to my dropdown menu, so my dropdown menu will know if user needs to pick one option or not..
Will the use of Ajax listner work in this case?
How to get state of SelectBooleanCheckbox in Ajax Listener?
Or there's any other suggestions?
Thanks a lot!
my previous related question
Conditionally make inputs required depending on checkbox value

Related

Primefaces fetch dropdown values on show

I have a strange situation where one needs to dynamically populate dropdown values. The best idea I have come up with is creating a button, which triggers ajax request that fetches new dropdown values and on complete updates the dropdown and displays it.
I was wondering if there is any other more elegant way of handling situations like this. I am using the latest primefaces version 11.0.0.
I suggest to use the p:autoComplete component with the dropdown attribute set to true instead. It allows you to get the values when the button is clicked or when a query is typed. You don't need to take care of updating the component yourself. The only thing you need to do is have a completeMethod in your bean or have a completeEndpoint (REST endpoint).
With PrimeFaces 12 you can even (re)use a LazyDataModel as a suggestions provider.

Null value submitted for a conditionally disabled field in a reusable JSF popup

I have a popup dialog developed in IceFaces 1.8.x (JSF 1.2).
The dialog is reusable (used for account creation as well as modification) and has a cancel button with immediate = true (to avoid validations). This dialog suffered a problem in the past ,where old values were rendered on re-opening the dialog, but that problem is now fixed as directed here (by setting submittedValue to null etc.).
The problem that I am facing now is specific to a conditionally disabled input field (<ice:inputText>) and here is what happens:
The popup is first opened (say for account creation) and this field
is NOT disabled.
User then cancels this dialog and, as we have incorporated the fix mentioned above (setSubmittedValue(null)), the submittedValue for this field is set to null (along with other fields).
Now the user opens "modify account" dialog, where in this field IS disabled. Everything seems to be rendered fine until user makes any changes to the form.
When user changes some field (say name) in the form, a partial submit happens for the name field as expected, but along with it null value is submitted for this disabled field.
This problem can be worked around by adding a null check in the setter method for the field in question, but this is not the desired solution for the project - as there are multiple places where this could be needed and doesn't seem like a very intuitive thing to do.
So I need to understand:
Why is the setter for this disabled field getting called in the
first place? and that too with a null value. The setter is not
called for any other enabled fields.
More importantly, is there any way to fix this (other than adding null check in the setter)?
You must be using rendered attribute to show/hide the dialog
<ice:panelPopup modal="true" rendered="#{bean.enabled}">
When dialog is reopened, it is coming up with some residual values from previous instance
The solution (or workaround) is to use <c:if> instead of rendered attribute, this way the DOM is completely destroyed when dialog closes and created from scratch when dialog opens
<c:if test="#{bean.enabled}">
<ice:panelPopup modal="true">
...
</ice:panelPopup>
</c:if>
This way you even would not need the fix to set submittedValue to null

Keeping a rich:popupPanel open after page change

Is it possible to keep a rich:popupPanel open after a form has been submitted and another page loaded?
As an example, go to richfaces showcase and click "Call the popup" then browse somewhere else (using a tab like "Modal panel example" or the menu). The popup will disappear as soon as the form gets submitted. I would like to let it "survive" the page change (and possibly remain in the same position).
Thank you for any suggestions!
Yes, it is. You just need to set the attribute show to something that evaluates to true in the next request:
<rich:popupPanel id="popup" show="#{someBean.showPopup}" ...>
Then you just need to make sure the property the method getShowPopup returns true when the popup needs to be shown.
From the docs:
show | boolean | If "true" value for this attribute makes a modal
panel opened as default. Default value is "false"
See also this section on rich:popupPanel.

Using `immediate` for a cancel button but saving only some fields

I have a JSF 1.2 Form which is composed of several parts.
I have validation with required tag turned on.
I want to be able to clear a certain part of the form which has required fields so on the 'clear' button i used the immediate tag.
Now the challenge - When pressing the 'clear' button all the values that were filled since the last submission are restored to the last submitted state while I would like only the certain part of the form to be affected. (Meaning, all the values that are not in that part of the form should be sumbitted although the button pressed is immediate)
Is there a way to do this?
EDIT - Can I submit a value after every time it was filled? This might be a solution.
Thanks!
If you want to take some fields along with the cancel button with immediate="true", then you should also put immediate="true" on those fields.
If you want to skip validation on those fields as well, then you need to change required="true" to required="#{empty param['formId:cancelButtonId']}" so that it is only required when the cancel button is not been used to submit the form.
As to submitting the values on change, that's best to be achieved with ajax in combination with a value change listener. To achieve that you would need to upgrade to JSF 2.0 or to introduce an ajaxified JSF component library.

How to preselect a radio button in <af:tableSelectOne>?

We are using Oracle ADF/JSF 1.1 to show search results in a table starting with a radio button. Our requirement is to show search result with one of the <af:tableSelectOne> radio buttons preselected depending on the database value match. However, I am unable to preselect a radio button.
Here is the code snippet:
<f:facet name="selection">
<af:tableSelectOne text="Select" autoSubmit="true" id="radiobtn" />
</f:facet>
How can I preselect it?
I believe that you should change your selection strategy :)
As far as know you can't configure selection property of af:tableSelectOne. It is nested in facet of af:table component, component which drives af:tableSelectOne behaviour. So, in order to select certain row, you should check for property "selectionState" on af:table (I suppose you're using ADF 10.x version)
<af:table value="#{bindings.DemoView1.collectionModel}"
var="row" rows="#{DemoView1.DemoView1.rangeSize}"
first="#{bindings.FilterView1.rangeStart}"
emptyText="#{bindings.DemoView1.viewable ? \'No rows yet.\' : \'Access Denied.\'}"
selectionState="#{bindings.DemoView1.collectionModel.selectedRow}"
selectionListener="#{bindings.DemoView1.collectionModel.makeCurrent}"
id="table1"
I'm sure you'll find it. To get an idea, just drag'n'drop some table object to your jsf page from data control (i.e. view object if you are using ADF Business Components based Data Controls ) and choose table as wanted component, and last step , on that table choose selection option (you should get popup window after drag'n'drop).When you configure your af:table component that way, you can control selection by changing your view object's current row . (View object to which af:table is attached)
Regards

Resources