What does <p:commandButton global="false"> attribute do? - jsf

What is difference between when setting the global attribute of <p:commandButton> to false or setting it to true. I was going through the primefaces showcase but couldn't understand the difference.

Form the Primefaces TLD:
Defines whether to trigger ajaxStatus or not.
If global is true and you defined ajaxStatus
on your page, then the status is shown if you click the button.

In easy words, if you don't want the "processing" dialog to be shown, set global to false. By default, this field is set to true, so it will always show you that "loading" dialog (also called ajaxStatus)

Related

When is the attribute's value of a Primefaces component updated?

I would like to understand when and how often an attribute's value is updated. I often see that component's attributes are updated even thought I didn't explicitly call an update on the component.
For example:
<p:panel id="panelA"
styleClass="#{controller.conditionA ? '.styleA' : 'styleB'}"
rendered="#{controller.conditionB() }">
</p:panel>
When the conditionB changes from true to false, the panels rendered attribute is updated as well without me calling an updated on the panel with panelA.
How are the both attributes styleClass and rendered evaluated and when?
Are all attributes, which have a non-static value, evaluated and updated periodically?
Instead of the panel, styleClass and rendered there could be other Primefaces components and attributes. I am interested in the general mechanism behind that.

Disable dynamically created button from managed bean

I have a problem with dynamicaly created CommandButton in Primefaces.
I want to disable button after user click (submit). I've tried in two ways:
By adding widgetWar (commandButton.setWidgetVar("pony");) property to my commandButton and setting onclick behaviour (commandButton.setOnclick("PF('pony').disable();");). WidgetVar property is unique among all elements on page. This approach doesn't work - my button after click turns into disable and then immediately goes back to enable.
From managedBean by calling setDisabled method on button UiComponent ((CommandButton) component).setDisabled(true);. This also doesn't work.
Is there any other way to disable CommandButton from Java code or am I missing something?
I'm generating my page dynamically so I cannot use disabled property in xhtml.
I also set my commandButton update property to update parent p:outputPanel.
Thanks in advance.
my button after click turns into disable and then immediately goes back to enable.
That will happen if the ajax update covers the button itself. Just exclude the button from it and specify only the parts which really need to be updated.
you can a declare field in your bean
boolean disable = false;
after click on button in your listener:
disable = true;
in your button use this code:
<p:commandButton id="x" disabled="#{bean.disable}" update="#form:x" />

Action/ActionListener method checked even if rendered=false

I have a composite component representing a table, that depending on the editable attribute (which I have created) may or may not display links to edit a row.
The edit links are of type <h:commandLink> and have actionListeners pointing to a method in a backing bean. The backing bean for handling editing is provided as a <cc:attribute name="editBean"... /> like the attribute editable, when I want the table to be editable.
If I don't need the table to be editable I set the editable attribute to false and the links rendered attribute gets set to false as well.
My problem is that if I set editable to false and therefore don't set the attribute editBean either, I get errors pointing out that there is no method for handling editing (e.g. java.lang.String does not have the property xxxxx).
I had hoped that as the links are set to not be rendered at all, what has been specified in the action/actionListener would be ignored. To me it feels logical to first check the rendered attribute and then, if it's set to true, check the other attributes.
So, my questions are: why does it work like this and if there's an elegant way of handling this scenario?
Use JSTL <c:if> to conditionally build the component in JSF component tree instead of rendered attribute to conditionally render the HTML output (it's that you're using JSF 2.2, otherwise I'd have explicitly mentioned that this requires a minimum of Mojarra 2.1.18 to avoid broken view state).
<c:if test="#{cc.attrs.editable}">
<h:commandLink ... />
</c:if>

Difference between rendered and visible attributes of <p:dialog>

I am using PrimeFaces 3.2 in my project. I wanted to know what is the difference between setting the rendered attribute of a <p:dialog> as against setting the visible attribute. When should I use either of these attributes?
The rendered attribute is server-side and the visible attribute is client-side. The rendered attribute tells whether JSF should generate the dialog's HTML representation or not. The visible attribute tells whether HTML/CSS/JS should immediately show the dialog on browser's page load or not.
If the dialog isn't rendered, then you won't be able to display it by for example JavaScript dialogWidgetVar.show() without reloading the page or ajax-updating one of the dialog's parent components that way so that the dialog's rendered condition evaluates to true. Also the visible attribute won't have any effect if the dialog is not rendered simply because there's nothing being rendered to the resulting HTML output which could be shown/hidden by JavaScript.
If the dialog is rendered, then it is by default hidden. You can set visible to true to force it to display the dialog immediately whenever the page is opened. Or you can invoke JavaScript dialogWidgetVar.show() in some onclick or oncomplete attribute to show it.
Use the rendered attribute if you don't want to render the dialog at all, for example because it wouldn't ever be used anyway in the currently requested page composition.
According to the documentation for those attributes, section 3.28:
rendered: Boolean value to specify the rendering of the component, when set to
false component will not be rendered [default value: TRUE]
visible: When enabled, dialog is visible by default [default value: FALSE]

JSF component is not getting reloaded for page refresh

I am new to JSF framework and Facelets as view, I am stuck with a problem now. I have got a page where i show some dropdown menu using <h:selectOneMenu> tag. On each selection i used to fire an ajax event using <f:ajax> event it all are working fine. But my problem is, if i select an option 2 on a select box and if I reloads the page again that particular select box will be selected with option 2 by default. I dont need this. I have to reload the select boxes along with page refresh. Please help me to solve this issue.
The selectbox shows the option that is set in the backing bean (and bound by the value attribute of <h:selectOneMenu>). The behavior after a page refresh depends on the scope of your backing bean. If it is session scoped, a page refresh doesn't reset the bean. You could change the scope to #ViewScoped to get the desired behavior. The bean then will be recreated after a full request.
Just set null to backing bean property that used in selectonemenu value after the selected action or set default value in property get method.

Resources