How to check if a component in PrimeFaces is disabled? - java

I would like to know how to check if a component (ex. p:inputText, p:password, and etc.) is disabled in PrimeFaces through Java? Because I plan on processing my form dynamically depending on the state (disabled/enabled) of the component. I know about PartialSubmit in PrimeFaces but to use it, you have to type the ID of the component you only want to process, which I don't want since I'm hardcoding the components I will process. Thank you.
I'm using PrimeFaces-6.2.RC2.jar and JSF 2.2.16 Mojarra.

Related

ADF Web Application: how to add and modify UI components on page loading (before it's displayed)?

I would like to know which are the different available approaches to add, modify and delete UI components before a page loaded.
A practical example that I should handle is the following:
In my ADF Fusion Web Application (developed with JDev12.1.3) there are the pages login.jspx and main.jspx: if the user logs in correctly navigation to main.jspx happens.
In main.jspx there is an empty menu bar that at runtime I would like to fill with menus and menu items when the page loads, in function of the logged in user.
In the same page, in function of the logged in user, I also would like to add at runtime some UI components (output texts, buttons, ...) whith the chance to set their properties.
Could you kindly advice me which approaches I can follow to accomplish these duties?
Thanks,
Federico
Why not using the rendered attribute? Based on the condition the components will be rendered or not.
Personally the two approaches i've used on my works where:
1. Using the beforePhaseListener on the f:view component. Example: Before Phase on JSF page. But it might cause you some problems when taking account of adf lifecycle, especially if you have integrated parts (or even some simple jQuery components...).
2. And i think this would just do fine in your case, use a f:event component of type "preRenderComponent". Example: How to use prerendercomponent. I suggest this second option
Note: It's true that these aren't ADF Faces components, but since it's built on top of JSF, they work as they should. I can assure you they do work on 11g and don't expect any problems on 12c.
I see two approaches. Use addChild() and related methods to physically add/remove menu items, or have the menu pre-built and use the visible property to show hide items.
As far as making this happen in custom code, you can use a Backing Bean (Managed Bean) that contains the code to determine what items to add/remove or make visible based on whatever criteria you choose. To call this code, you can 1) use the Invoke action in the rebinding layer - have it call the desired backing bean method - make sure to drag the Invoke action the TOP of the executables list. This is the older, less preferred method. The newer, more preferred method is to add the backing bean method to the Task flow and have it navigate to the deserted page. This method can be part of the navigation form another page. Ex: After successful Login, navigate to your method an chav sit navigate to the Main page. The method will execute before the page loads and will set values to have the items added or visible or not.
RichSelectOneChoice choiceList;
List child = choiceList.getChildren();
child.clear();
for (int i = 0; i < child.size(); i++){
child.remove(i);
}
if ("1..1".equalsIgnoreCase(ccCode)){
UISelectItem addChild = new UISelectItem();
addChild.setItemLabel("1..1");
addChild.setItemValue("1..1");
child.add(addChild);
} else if ("0..1".equalsIgnoreCase(ccCode)){
UISelectItem addChild1 = new UISelectItem();
addChild1.setItemLabel("0..1");
addChild1.setItemValue("0..1");
child.add(addChild1);
UISelectItem addChild2 = new UISelectItem();
addChild2.setItemLabel("1..1");
addChild2.setItemValue("1..1");
child.add(addChild2);
}
Have you posted this question to he ADF forum, here?

GWT- dynamically make widgets non-editable

As per my requirements, I need to make a widget textbox prepopulate based on a selection, then under specific scenerios make the prepopulated field non-editable (from editable) without the page reloading.
The prepopulation works fine, but when I try to change my widget textbox to non-editable from the code (a validator), nothing changes. Of course I can easily make a field editable or noneditable easily on page load by setting my widget attribute directly in sql developer. But I need this to happen on the 'fly'.
So what is the proper strategy?
My thought is the widget is activated on load, and if I change the widget property I need a way to tell it to look there again w/o reloading the entire page?
Any thoughts would be greatly appreciated :)
I think TextBox#setReadOnly should work.

<ui:include> a custom component

I have a package with a taglib that consist of a few custom made component.
There is a component uses icefaces "Panel Popup", which I created to do multiple-value look-up and to be used across multiple project.
I have been trying to use <ui:include> to attach it to other popup bean and rendered when required.
But it just won't work. I even uses
<namespace:Component> <namespace:Component>, the page runs properly but just won't render
the component when I click a button to make it visible.
The component works properly when I use <ui:include src="url link"/>, but I do not want the component to exist in every project, I want to share it using a package.
May I know if there is other solution?
Thanks in advance
Caveman programmer!

manual swing data binding

I have rather big swing interface (several textboxes, comboboxes, checkboxes, custom popup dialogs etc) and a data model that has to be changed when ui control changes: new text is entered into text box, check box is clicked, etc.
The question is: what is the best practice to organize update+validation of input values.
Unfortunately I can not use binding framework like beansbinding.
Add appropriate listeners to the components, and update the model when the events are fired.
Or design your UI so that everything is saved to the model only when a Save or OK button is clicked. This also helps with validation, because you just need to validate everything at once, when the button is clicked.
Combine the answer of JB Nizet with validation in your components, for example by using JFormattedTextField (or an enhanced version of this). You can use the JFormattedTextField also as editor for JComboBox instances. You can add validation to JSlider instances.
In short, provide immediate feedback to the user when he types in an invalid value. That combined with validation on the model side makes a good application.
This can be compared to a modern website: client-side validation with javascript to give the user immediate feedback + server-side validation for validation which does not go through the UI, or to avoid nasty users bypassing your client-side validation

How do I have multiple components respond to a single event in JSF?

Here's the sit:
I have a JSF component which is basically a list of 'documents'
I have any number of document viewer components on the same page.
None of these components "know" about each other. In other words, they cannot be configured at design time to link to each other or anything like that.
When the user clicks a document link I wish each one of the document viewer components to be notified.
Basically the idea would be to have the document viewers publish the fact that they listen for a certain type of event ("DocumentSelectedEvent" say) which the doc list component would fire.
I can think of ways of doing this that are not JSF specific, but I'm wondering if the JSF event model can handle that sort of thing.
Anyone have any ideas?
I don't think there's a way of doing that with the standard JSF event model.
Is there any way you can bind the components to a backing bean? That way when an event happens you can just go through your list of components and notify each of them.
You need to just bind the components with a backing bean and use a ValueChangeListener to notify the backing bean. The listener method could change the state of the other components which are tied to respective UI components.
Are you trying to do it in a "Ajax" way without page being explicitly submitted?
ValueChangeEvent
I do not know how you implemented your document list but if it were say a dropdown or any other multi item list component you can do an Value Change Event and force a submit on change for the component. Then in the page code backing bean you can call the methods for your viewers to load whatever you like.
In your jsf you just specify the value change handler you wrote in the backing bean.
/**
* Handle document click value change.
*
* #param valueChangedEvent the value changed event
*/
public void handleDocumentSelect(ValueChangeEvent valueChangedEvent) {
String selectedDocument = valueChangedEvent.getNewValue();
doDocViewer1DisplayMethod(selectedDocument);
doDocViewe2DisplayMethod(selectedDocument);
}
Modify your jsf tag to use your new value change event handler and force the submit.
<f:componentTag
attr=xxx
attr=xxx
valueChangeListener="#{pc_BackingBean.handleDocumentSelect}"
onChange=submit();>

Categories

Resources