I am trying to write a composite component in JSF 2.2.
This is it.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:cc="http://xmlns.jcp.org/jsf/composite">
<!-- INTERFACE -->
<cc:interface>
<cc:facet name="content"/>
<cc:facet name="menubar"/>
</cc:interface>
<!-- IMPLEMENTATION -->
<cc:implementation>
Content header
<cc:renderFacet name="content">
This is the default content.
</cc:renderFacet>
Spacer
<cc:renderFacet name="menubar">
This is the default menubar.
</cc:renderFacet>
</cc:implementation>
</html>
This is how it is used.
<dd:dummy>Hello hello</dd:dummy>
This is what is rendered to the client.
Why is the default content and default menubar not rendered?
This should work
<cc:implementation>
<c:if test="#{empty component.facets.content}" >
This is the default content.
</c:if>
<c:if test="#{not empty component.facets.content}">
<cc:renderFacet name="content"/>
</c:if>
<c:if test="#{empty component.facets.menubar}" >
This is the default menubar.
</c:if>
<c:if test="#{not empty component.facets.menubar}">
<cc:renderFacet name="menubar"/>
</c:if>
</cc:implementation>
Related
I got the problem when control to render cc:insertChildren dynamically.
<cc:implementation>
My text 1
<c:if test="#{testData}">
<cc:insertChildren /> <!-- My content will be loaded here-->
</c:if>
My text 2
<c:if test="#{!testData}">
<cc:insertChildren /> <!-- or other will be loaded here-->
</c:if>
</cc:implementation>
but the content rendered in both cc:insertChildren tags could not be rendered.
Do you have any ideas ?
Thank you.
I created a facelet template called loginRegisterTemplate.xhtml. When I use it in a template client and I place a in it, the method in the managed bean is not invoked. Without the template the button is working fine. Why is this happening?
<ui:composition template="resources/css/faceletsTemplates/loginRegisterTemplate.xhtml">
<ui:define name="top">
Login Page
</ui:define>
<ui:define name="content">
<div align="center">
<h:panelGrid columns="3" columnClasses="rightalign,leftalign,leftalign">
<h:outputLabel value="Username:" for="userName"/>
<h:inputText id="userName" label="Username" required="true" value="#{loginBean.userName}" />
<h:message for="userName" />
<h:outputLabel value="Password:" for="password"/>
<h:inputText id="password" label="Password" required="true" value="#{loginBean.password}" />
<h:message for="password" />
</h:panelGrid><br/>
<h:button value="Back to Home" outcome="home"/>
<h:commandButton id="login" value="Login" action="#{loginBean.doLogin}"/>
</div>
</ui:define>
</ui:composition>
</h:body>
The simple <h:button> next to it, on the other side, is working fine.
Here is the body of my template file:
<h:body>
<div id="top">
<ui:insert name="top">Top</ui:insert>
</div>
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
</h:body>
I have looked here: h:commandLink / h:commandButton is not being invoked but I couldn't find which problem causes that.
Thanks!
Why is the h:commandButton not working?
Your problem is number 1 in the answer you have checked.
UICommand and UIInput components must be placed inside an UIForm
component, e.g. <h:form>.
Why is the h:button working then ?
from the h:button docs:
Render an HTML "input" element of type "button". The value of the
component is rendered as the button text and the outcome of the
component is used to determine the target URL which is activated by
onclick.
So ...
JSF will put your h:button outcome value in a javascript function that will be executed at an onclick event. But it will execute the action of the h:commandButton on the form submit with the POST method, so there should be a form to submit.
I have the following in my jsf xhtml page:
<h:body>
<ui:define name="metadata">
<f:metadata>
<f:viewParam name="dummy"/>
<f:event type="preRenderView" listener="#{bean.getDataMethod}"/>
<f:attribute name="param1" value="${param.param1}"></f:attribute>
<f:attribute name="param2" value="${param.param2}"></f:attribute>
</f:metadata>
</ui:define>
<p:dialog header="Modify" widgetVar="modDialog" height="650" width="1500" resizable="false" showEffect="explode" modal="true" draggable="false" hideEffect="explode">
<p:panel id="modifyPanel">
<c:if test="#{null != bean.databean}">
<ui:include src="modifyData.xhtml"></ui:include>
</c:if>
</p:panel>
</p:dialog>
</h:body>
I need to display the modal dialog box after the preRenderView has been executed. And, I also need to make sure that all data will be displayed in the modal dialog box.
Just set its visible attribute to true.
<p:dialog ... visible="true">
If you intend to display it on a condition which is determined during preRenderView, then just bind it to a boolean bean property the usual way.
<p:dialog ... visible="#{bean.dialogVisible}">
See also:
Difference between rendered and visible attributes of <p:dialog>
I defined a custom tag like:
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:composite="http://java.sun.com/jsf/composite">
<!-- INTERFACE -->
<composite:interface>
<composite:attribute name="terminal" />
<composite:attribute name="prefix" />
</composite:interface>
<!-- IMPLEMENTATION -->
<composite:implementation>
<h:panelGrid columns="3" columnClasses="titleCell">
<h:outputLabel for="#{prefix}nodeId" value="Node Id" />
<h:selectOneMenu id="#{prefix}nodeId"
value="#{cc.attrs.terminal.nodeId}"
converter="javax.faces.Integer">
<f:selectItems
value="#{terminalController.availableNodeIds}" />
<rich:validator />
</h:selectOneMenu>
<rich:message for="#{prefix}nodeId" id="cnodeIdMsg" />
<h:outputLabel for="#{prefix}maxcon" value="Max Connections" />
<h:inputText id="#{prefix}maxcon"
value="#{cc.attrs.terminal.maxConnections}">
<rich:validator />
</h:inputText>
<rich:message for="#{prefix}maxcon" />
</h:panelGrid>
</composite:implementation>
</html>
When I use it within a rich:popupPanel
<my:terminalForm prefix="c" terminal="#{newTerminal}"/>
everything works fine.
At another place in the same file (also rich:popupPanel)
<my:terminalForm prefix="e" terminal="#{terminalController.editTerminal}"/>
all values in my form don't get the initialized. I suspected the expression #terminalController.editTerminal} to not get expanded correctly. But when I write the tags from the custom tag explicit
<h:inputText id="#{prefix}maxcon"
value="#{terminalController.editTerminal.maxConnections}">
<rich:validator />
</h:inputText>
everything would work also, but using the custom tag for only one expansion would be pointless.
What could be wrong?
Does anyone more experienced have an idea how I could debug this issue?
The cc.attrs is missing in front of prefix ?!
my problem is the following,
I have a template.xhtml that i uses for layout of the my web application
<div id="header">
<ui:insert name="header">
[Top Bar content will be inserted here]
</ui:insert>
</div>
<div id="main">
<ui:insert name="main">
[Nav Bar Left content will be inserted here]
</ui:insert>
</div>
<div id="button">
<ui:insert name="button">
[Nav Bar Left content will be inserted here]
</ui:insert>
</div>
then i have a addOrder.xhtml
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="/WEB-INF/template/popUpInsert.xhtml">
<ui:define name="header">
<h:outputLabel value="Status" />
<rich:inplaceInput value="#{ordineController.orderToSave.status}" />
<h:outputLabel value="Code" />
<rich:inplaceInput value="#{ordineController.orderToSave.code}" />
</ui:define>
<ui:define name="main">
Here there is a data table that contains lines of the order
</ui:define>
<ui:define name="button">
<h:form>
<a4j:commandButton value="Save" action="#{ordineController.addOrder()}" />
<h:form>
</ui:define>
but when i try to save the order both status and code are null , i try to change a scope to button save (execute="#all") but nothing
What's wrong?
Add this to your page <h:messages styleClass="message" />, you will see more warnings from JSF, in your case there should be a warning about missing forms because JSF knows which elements require to be inside one. In the end it is all HTML and JavaScript so inputs need to be inside the form if you want to do a submit.
You need to put the related input components in the same form as the command component. Any input components which are not in the same form as the command component are plain ignored in the submit. Note that this is a HTML restriction, not a JSF restriction.
So, this should do for you:
<h:form>
<div id="header">
<ui:insert name="header">
[Top Bar content will be inserted here]
</ui:insert>
</div>
<div id="main">
<ui:insert name="main">
[Nav Bar Left content will be inserted here]
</ui:insert>
</div>
<div id="button">
<ui:insert name="button">
[Nav Bar Left content will be inserted here]
</ui:insert>
</div>
</h:form>
And:
<ui:define name="header">
<h:outputLabel value="Status" />
<rich:inplaceInput value="#{ordineController.orderToSave.status}" />
<h:outputLabel value="Code" />
<rich:inplaceInput value="#{ordineController.orderToSave.code}" />
</ui:define>
<ui:define name="main">
Here there is a data table that contains lines of the order
</ui:define>
<ui:define name="button">
<a4j:commandButton value="Save" action="#{ordineController.addOrder()}" />
</ui:define>
Be careful that you don't create "God" forms this way.