Refer from programmatically created JSF-code to other element for rerendering - jsf

I am using Apache MyFaces lib to create JSF Tags, for example HtmlAjaxCommandLink. There is a method setReRender(parameter) to identify the corresponding element, which should get updated. In my HTML-source the corresponding anchor has an id-attribute with the value 'subformContainer_7_facesMessagesContainer'.
What do I have to set as a parameter? Thanks in advance.
Currently the area (a t:div) is not rerendered at all. To evaluate if the area is rerendered I am using a randomNumberString, so I should recognize if the value changes.
String rrString = "subformContainer_7_facesMessagesContainer";System.out.println("DEBUG rrString : " + rrString);
treeResizeButton.setReRender(rrString);

If you want to tell JSF to re-render a component in the current Ajax request, you can use the API for PartialViewContext:
PartialViewContext partialViewCtx = FacesContext.getInstance().getPartialViewContext();
partialViewCtx.getRenderIds().add("putYourClientIdHere")
Or, if you use the OmniFaces library, you can simply use Ajax#update.

Related

Is it possible to dynamically generate the <f:validateBean> tag?

I am dynamically generating some Primefaces input and output components, and I need to be able to disable validation on these components in certain use cases, while still updating the model. (Like a save button). It looks like the proper way to do that in xhtml would be to use <f:validateBean disabled="#{myBean.someCondition}/>
However, I cannot figure out how to create this component dynamically. I searched through the javax.faces package and could not find any validateBean component. I thought maybe it would be a property that I need to set on the UIInput component, but none of the methods outlined in that API seem to what I need.
Is this possible?
Edit:
As a reference, here is the component I am creating:
UIInput input = new InputText();
input.setId(field.getFieldKey());
input.setValueExpression("value", expressionFactory.createValueExpression(elContext, field.getFieldValue(), String.class));
input.addClientBehavior("blur", ajaxBehavior);
input.addValidator(new BeanValidator());
You might want to explore these paths :
Set immediate to true on your input.
input.setImmediate(true);
Extend BeanValidator with an empty validate method and pass an instance to your input.
input.addValidator(new DummyBeanValidator());
Hope this helps.

Process only input fields whose values have been modified?

Is there any easier way to set to process only those input fields within a h:form whose values have actually been changed at the client side ignoring those that havent changed?
Using JSF 2.2 with
Primefaces 3.2
Not in JSF 2.2, nor in PrimeFaces 3.2.
Closest what you can get is PrimeFaces 3.3 (currently only available as snapshot) with new client ID selector syntax which is borrowed from the jQuery selector API. Unfortunately, this doesn't support some :changed selector (even already not in jQuery selector API).
This is not exactly trivial to implement and integrate in PrimeFaces JS API. You basically need to hook a change listener on every single input element in the background wherein you collect client IDs of those who have been changed.

Is there a JSF component that supports autocomplete and can hold multiple values?

I'm developing an application in JSF 2.0.
I was wondering if there is a JSF component that supports an autocomplete function and that can hold multiple values (that binds to an array or a list). I don't have the time and knowledge to create such a component myself.
I know PrimeFaces has got the p:autoComplete (http://www.primefaces.org/showcase-labs/ui/autoCompletePojo.jsf) component, but it can only 'hold' one value. I'd need a component that can do what p:auotoComplete does, but multiple times; the textarea should be able to display multiple values. Is there a library that contains such a component?
Any help would be greatly appreciated.
The latest PrimeFaces snapshot 3.1 got AutoComplete - Multiple Selection
You can get it from here
3.1-SNAPSHOT
You might see this Richfaces example. I think that tokens and autoFill = "false" will work.

add the code for a widget (widget.xhtml) once but use it twice in same webpage, possible ? How?

I have a widget in my application that I need to display at two places(once in main page body and once through dialog box). Currently its code has been added twice in the page. Now I was thinking, If there was a way I could just include it only once and show the same instance in the dialog box, as in the main page body.
Can you suggest a way for this?
I'm Using:-
JSF 2.0 with Facelets
Primefaces 3.0 M3 Snapshot
JSF 2 has exactly the feature you want: it's called composite components. I bascially allows you to write a bunch of Facelet code into a file and use it just like any other JSF component, pass parameters to it, etc.

Suggest the appropriate method of managing beans in Richfaces

The scenario is like this. I have a rich:tabPanel with about 5 tabs. On first tab there is a rich:datatable. When I click on first column's element (a4j:commandLink), I get another rich:datatable. When I click on first column's element (a4j:commandLink) of this table, I change the tab where I have another rich:datatable and the same thing follows as above. The constraints from previous tab is used to get elements for the current one. If I click on the tab directly I get all elements related to that tab. Each rich:datatable refers to different tables. Each table is interrelated. Each tab refers to a single managed bean. I am using hibernate in backend.
The problem starts now. I dont want the managed beans to be session or application based since there are many variables to store. If I give request scope, the following thing happens. The first table in the tab renders perfectly, however when I click on the first column, the second table doesn't use all constraints since the scope is request, for example actionlistener. What am I supposed to do ?
One thing I can do is define one managed bean for each table. Or forcefully use session scope. Or is there any other way? Please help.
Thanks.
If you are using Richfaces 3.0.0 or above you can annotate your bean with #KeepAlive
or use the tag <a4j:keepAlive beanName="#{bean}" /> instead.
This is an equivalent to the view scope in JSF 2.0.
If you're already on JSF 2.0, use view scope. It's a scope which lives as long as you're interacting with the same page (independently of the browser tab/session!).
If you're still on JSF 1.x, use request scope with an <a4j:keepAlive beanName="#{bean}" /> declared in the view. It behaves like the JSF 2.0 view scope.

Resources