Using rendered with JSF [duplicate] - jsf

This question already has an answer here:
Why do I need to nest a component with rendered="#{some}" in another component when I want to ajax-update it?
(1 answer)
Closed 7 years ago.
How does rendered work? It hides h:form content completely and does not show it if expression.list is not empty.
<h:form id="stackForm" rendered="#{not empty expression.list}">
<p:orderList id="stack" value="#{expression.list}"...
...

It doesn't hide it - it doesn't render it at all, if rendered condition evaluates to false. In your case, if #{expression.list} is empty, form will not be rendered. Or, when rendered is translated to plain English, read it as Render the form if expression.list is not empty.

Related

p:selectBooleanCheckbox visibility property [duplicate]

This question already has answers here:
Conditionally displaying JSF components
(3 answers)
Closed 2 years ago.
I am new to primefaces and JSF. I want to make selectBooleanCheckbox visible by depending on some Boolean value in my bean. But there is no visibility feature. And if I add a panel the design changes. So do you have any suggestions?
<p:selectBooleanCheckbox id="idCheckbox" value="#{bean.object.value}" itemLabel="{bean.object.value.label}" styleClass="width100Percent" disabled="{bean.infomode}">
You can add "rendered" attribute to control whether the component is displayed.
<p:selectBooleanCheckbox id="idCheckbox"
value="#{bean.object.value}"
itemLabel="#{bean.object.value.label}"
styleClass="width100Percent"
disabled="#{bean.infomode}"
rendered="#{bean.showIt}"
>

Commandlink with ajax works only on second click [duplicate]

This question already has answers here:
h:commandButton/h:commandLink does not work on first click, works only on second click
(2 answers)
Closed 6 years ago.
What I'm trying to do is just a simple logout function. The main page will call a template page; consist of header and content. The header contains the logout button. There will be 2 forms in the page, one in the header (logout button), one in the content (few buttons,links, etc).
My problem is the page refresh when first click on the logout link and only proceed after second click. The problem starts to appear when I include primefaces or ajax code inside the content form. When I remove that particular code, the logout works as intended.
The logout form in main template templateUser.xhtml:
<h:form id="logout">
<h:commandLink action="#{tenantController.customLogout(e)}"
id="logoutBtn" immediate="true" value="Logout" />
</h:form>
The backing bean:
public String customLogout(ActionEvent e) {
return "login.xhtml";
}
FYI: the customLogout method also consist of session destroy, but I just put page redirect here.
In template client, the template is specified as:
<ui:composition template="/templateUser.xhtml">
As for the JSF library, currently use jsf 2.0
Solutions I've tried:
immediate="true"
put id for both form and commandLink (template form & content form)
use primefaces (<p:commandLink> with ajax false ==> this returb to the previous page; the method in backed bean is not running.
Below are few links I tried here:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated
How can I prevent page refresh on click of <h:commandLInk>
JSF PrimeFaces p:commandLink won't redirect to new page?
The problem starts to appear when I include primefaces or ajax code inside the content form. When I remove that particular code, the logout works as intended.
Your problem is caused by point 7 as described in commandButton/commandLink/ajax action/listener method not invoked or input value not updated. When you fire an ajax request using <f:ajax> and performs an update which also covers all other forms, then all those other forms will lose their view state. This causes that the 1st submit will always "do nothing", but the next submits will work, which matches exactly your problem symptoms.
You can solve this problem in one of the following ways:
Explicitly specify the client ID of all other forms in the <f:ajax render>. You can specify multiple client IDs space separated. E.g.
<f:ajax ... render="someComponent otherComponent :loginForm" />
Use the JavaScript based fix as proposed in this answer: h:commandButton/h:commandLink does not work on first click, works only on second click.

How to pass parameters panelgroup - binding, JSF [duplicate]

This question already has answers here:
How does the 'binding' attribute work in JSF? When and how should it be used?
(2 answers)
Closed 8 years ago.
I have a datatable that reads registers from a database.
In the datatable I have a panelgroup that is populated by binding
My problem is that I can not pass a parameter. I want to pass a value from the datatable variable, in that case preg, on each row I want to know the value of the register read to populate the panelgroup.
If I display the value it works fine for each row: #{preg.idpreg}
<h:dataTable var="preg" value="#{Pregbacking.list(Pregbacking.idenq)}">
<h:column>
#{preg.idpreg}
<h:panelGroup binding="#{Pregbacking.dynamicDataTableGroup(preg.idpreg)}"/>
</h:column>
</h:dataTable>
Does anybody know how can I solve this?
That should work just find but I believe that you need to make sure you are using a modern servlet spec (v3 I think). Use the latest Glassfish or Tomcat app server.

How to display html code which is load from db in jsf screen? [duplicate]

This question already has an answer here:
Component to inject and interpret String with HTML code into JSF page
(1 answer)
Closed 6 years ago.
I have html code in one column. Loaded html code to one bean.
My question is how to display this html code using jsf tags.
You can use a <h:outputText> component, and set escape="false".

JSF2 ignores Action attribut [duplicate]

This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
Closed 2 years ago.
my xhtml code:
<h:commandLink action="#{detailController.updateProject}" class="positive" >
<h:graphicImage library="img" name="tick.png" alt=""/>
<h:outputText value="Save" />
</h:commandLink>
This action (updateProject()) is not being called from JSF framework! Even if I delete it in the managedBean there is no exception thrown.
Does anybodyelse has had problems like that? I can't even explain that -.- I mean this action ethod is there!
ADD: Yes it is in a h:form tag! But I have two forms in that view! May that be the problem?
ADD2: I should also mention that if I hit the button it throws me back to the previous view! So my action method is being ignored and instead it opens another view ?!?!
To provide more information, my page is built like that:
panelGroup name=show rendered=!controller.edit
form
buttons
outputtext
/form
/panelGroup
panelGroup name=edit rendered=controller.edit
form
buttons
inputText
/form
/panelGroup
So I have both, edit and show of one entity at one file! But only the buttons in the bottom form show that strange behaviour (see above).
Answering BalusC:
1. I use two forms (they aren't nested!)
2. In the bottom form I had already placed a h:messages
I'm gonna try putting my controller into viewScop for checking 3 and 4
I don't know how to check 5.
Thank you for that..
This can have a lot of possible causes. #romaintaz has mentioned only the most obvious one (the most common beginner's mistake): UICommand components must be placed inside an UIForm component.
There are however more causes:
You have multiple nested forms. This is illegal in HTML. The behaviour is dependent on the webbrowser used, but usually the button won't do anything. You may not nest forms, but you can use them in parallel.
A validation or conversion error has occurred which is not been catched by a h:message. Normally this is logged to stdout, but you can also use h:messages to get them all.
The UICommand component is been placed inside an UIData component (e.g. h:dataTable) whose value is not been preserved the right way during the subsequent request. If JSF cannot find the associated data row, the action won't be invoked. Putting bean in view scope should help a lot.
The component or one of its parents has a rendered or disabled attribute which evaluated false during apply request values phase. JSF won't invoke the action then. Putting bean in view scope should help a lot.
Some PhaseListener, EventListener, Filter or Servlet in the request-response chain has changed the JSF lifecycle to skip the invoke action phase or altered the request parameters so that JSF can't invoke the action.
Just a quick question: is your <h:commandLink> nested inside a <h:form>?
If this is not the case, you must include your command link inside a form element, otherwise it will not work.
Just for code simplification, you can use the value attribute instead of adding a <h:outputText> component:
<h:commandLink action="#{detailController.updateProject}" class="positive" value="Save">
<h:graphicImage library="img" name="tick.png" alt=""/>
</h:commandLink>
Unfortunately, I don't know where the mistae was. I guess it was about wrong my JSF code.
I solved this problem by simplifying my code. From that xhtml page and that one controller I made 3 xhtml-pages and 3 Controller. After refactoring all that my code looks much easier and it works now :-)
Thank you for your helpful suggestions

Resources