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

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]

Related

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>

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

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)

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.

JSF remove invalid component from page

i'm using JSF 1.2 with IceFaces 1.8.
On my page i got an selectOneListbox, which content (e.g. EQUAL TO, BETWEEN, IN) triggers inputText fields to be rendered. If EQUAL TO is choosen one field is rendered else if BETWEEN is chossen two fields are rendered.
If my validation on the inputText field fails, and i change the content of the listbox the explained rendering does not work.
So has anyone a suggestion how to remove an "invalid" component from the html page?
I set invalid components to invisible.
I use the visible="#{myManagedBean.fieldVisible}" attribute for the component
in my JSF page
and
public boolean isFieldVisible() { return flag; }
in my Managed Bean to achieve this.

JSF: Unwanted page refresh on action call

Sometimes, if I click a commandButton that calls an action method, it will just do a page refresh without actually calling the method!
I set a breakpoint in that method and if this behavior takes place, the method is not called. What is also strange about it: It also does that if I didn't fill values in input components that have "required=true". I would expect that a valdiation error appears. The error appears only if the action method would be called fine. But not if it will just issue that strange page refresh.
The call looks pretty normal and works in most cases:
<h:commandButton value="Do something"
action="#{bean.doSomething(someBean.value)}" />
I can't exactly figure out when this behavior appears (and when not), but it should have something to do with the values chosen in some of the other components. But... how?
(I have two forms in a xhtml file. I just mention that because I don't know if it is important or not. However, there are no nested forms and h:messages displays nothing after page refresh.)
I'm using JSF 2 (MyFaces) + Tomahawk.
there are no nested forms and h:messages displays nothing after page refresh
You've likely a rendered attribute on the component or one of its parents which evaluated false during the processing of the form submit request. You need to ensure that it evaluates the same as it did during displaying the page. You can do this by putting the bean responsible for this in the view scope instead of the request scope.
See also:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated

Resources