How to break in a <ui:repeat> - jsf

Is there any easy way I can break in a ui:repeat loop ?
I'm trying to do it the following way, but it does not work. The idea is to print the image when, requestScope.counter == 1.
<c:set target="#{requestScope}" property="counter" value="0" />
<ui:repeat var="mediaVar" value="#{brandsVar.brandBrandMedia}" >
<ui:fragment rendered="#{mediaVar.bmType eq 'image'}">
<ui:param name="#{requestScope.counter}" value="#{requestScope.counter + 1}" />
</ui:fragment>
<h:graphicImage rendered="#{mediaVar.bmType eq 'image' && requestScope.counter == 1}"
height="100" width="100"
value="location of image" />
</ui:repeat>

You can't break in an ui:repeat. As to your concrete problem, use and instead of &&.

Related

h:panelGrid inconsistent allocation of cells

My page: ---
Something is causing panelGrid to create an empty cell in several rows.
I'd like to have a visible two column table, first column a label, second column an inputText element or a selectMenu with a tooltip.
My workaround was this, create a 3 column table, and when panelGrid decides not to create an empty cell, add a <br></br> to prompt it to do so.
<h:panelGrid columns="3" style="text-align:left">
<p:remoteCommand name="startJobActivate" actionListener="#{provisioningBean.startJobActivate}" />
<h:outputLabel for="longitudeIdAct" value="Longitude: " />
<p:inputText id="longitudeIdAct" value="#{provisioningBean.longitude}" title="Longitude" />
<p:watermark for="longitudeIdAct" value="Longitude" />
<h:outputLabel id="equipmentDropMenuActLabel" for="equipmentDropMenuAct" value="#{provisioningBean.accessDeviceLabel}" />
<p:selectOneMenu id="equipmentDropMenuAct" value="#{provisioningBean.equipment}" title="Not needed for CSI or SIP"
disabled="#{provisioningBean.equipDisabled}" style="width: 100% !important">
<f:selectItem itemLabel=" Equipment" itemValue="" noSelectionOption="true" />
<f:selectItems value="#{provisioningBean.equipments}" />
</p:selectOneMenu>
<p:tooltip for="equipmentDropMenuAct" />
<h:outputLabel for="rangeActId" value="Range: " />
<p:spinner id="rangeActId" value="#{provisioningBean.rangeAct}" min="1" title="Amount of telephone numbers to provide" size="3"
disabled="#{provisioningBean.rangeDisabled}" />
<br></br>
</h:panelGrid>
Is this a bug?
What am I missing here?
EDIT:
Oh neat! I managed to create a minimal example and it still has the same issue :D https://gist.github.com/WurmD/f3cb45669e6871acc77462f34891862f
screenshot - you need 10 rep to post images
So this is a 3 column h:panelGrid, but the third cell is being taken up by something
EDIT2: Same behavior with p:panelGrid
Thank you Kukeltje for this answer:
h:panelGrid columns="3" signify "start new row after each third element"
Thus, either put the watermarks (and other invisible elements) outside h:panelGrid, or use h:panelGroup to groups things that should only occupy one cell in the table:
<p:remoteCommand name="startJobActivate" actionListener="#{provisioningBean.startJobActivate}" />
<p:panelGrid columns="2" style="text-align:left">
<h:outputLabel for="orderIdAct" value="Order Number: *" />
<p:inputText id="orderIdAct" value="#{provisioningBean.orderNumberAct}" label="orderId" title="Order Number" />
<h:outputLabel for="customerNameIdAct" value="Customer: *" />
<h:panelGroup>
<!-- h:panelGroup to group things that should only occupy 1 cell in the table -->
<p:inputText id="customerNameIdAct" value="#{provisioningBean.customerName}" title="Customer Name" />
<p:watermark for="customerNameIdAct" value="Customer Name" id="watermarkcustomerNameIdAct" />
</h:panelGroup>
</p:panelGrid>
<p:panel id="executePanelAct">
<p:commandButton value="Execute Activation" id="actvateButton" update=":form:growl" styleClass="executeButton" />
</p:panel>
<!-- Items that don't need to be in panelGrid -->
<p:watermark for="orderIdAct" value="Order Number" id="watermarkorderIdAct" />

display images in a datatable according to the value of an attribute in tha database JSF

I want to display icons with colors (green, orange,red) in a column of a jsf datatable showing the urgency of a chirurgical operations. depending on an attribute in the database this icon will be displayed.
hwo can I do this?
Your question doesn't have much details, but you can simply do something like this using the rendered attribute and some state getter/setter on your operation Object.
<h:dataTable value="#{yourBean.list}" var="item">
<h:column>
<f:facet name="header">
Urgency
</f:facet>
<h:graphicImage rendered="#{item.state eq 1}" value="images/icon1.png" />
<h:graphicImage rendered="#{item.state eq 2}" value="images/icon2.png" />
<h:graphicImage rendered="#{item.state eq 3}" value="images/icon3.png" />
</h:column>
</h:dataTable>

Aligning Radio Button in a JSP/JSF with its label

I would like to achieve the following in a JSF1.1 environment:
Gender: RadioButtonForFemale FEMALE RadioButtonForMale MALE
<h:panelGroup>
<h:outputLabel for = "searchSex" value = "#{bundle.Sex_Label}" style ="width:15%;">
</h:outputLabel>
<h:selectOneRadio id="searchSex" value="#{yy.search_Sex}" style="verticle-align:top;font-size:95%;color:red;">
<f:selectItem itemLabel="F" itemValue="F" />
<f:selectItem itemLabel="M" itemValue="M"/>
</h:selectOneRadio>
</h:panelGroup>
Basically, all the radio button should be in the same row as the lable (Gender in our case).
Attached is my current code. the radio button appear in the next row. My PanelGrid has 1 column.
thanks,
Indeed, the <h:selectOneRadio> generates a <table> which is by default a HTML block element (i.e. always starts at a new line).
You'd need to set the CSS display property to inline-table.
<h:panelGroup>
<h:outputLabel for="searchSex" value="#{bundle.Sex_Label}" style="width: 15%;" />
<h:selectOneRadio id="searchSex" value="#{yy.search_Sex}" style="display: inline-table; verticle-align: top; font-size: 95%; color: red;">
<f:selectItem itemLabel="F" itemValue="F" />
<f:selectItem itemLabel="M" itemValue="M" />
</h:selectOneRadio>
</h:panelGroup>
But this is pretty clumsy. If you're already using a <h:panelGrid>, I'd recommend to just set its columns to 2 so that you can have labels in left column and inputs in right column.
<h:panelGrid columns="2">
<h:outputLabel for="searchSex" value="#{bundle.label_sex}" />
<h:selectOneRadio id="searchSex" value="#{yy.searchSex}">
<f:selectItem itemLabel="F" itemValue="F" />
<f:selectItem itemLabel="M" itemValue="M" />
</h:selectOneRadio>
<h:outputLabel for="somethingElse" value="Something else" />
<h:inputText id="somethingElse" value="#{yy.somethingElse}" />
...
</h:panelGrid>

Dynamic Columns into ui:define

I have a data table in an xhtml with "ui:insert" space...
In another xhtml i use ui:define to add some columns... the problem is that i have dynamic columns to insert..
i've already tryed with a4j:repeat, ui:repeat, c:foreach and rich:columns...
<rich:columns value="#{entity.dadosAdicionais}" var="col" >
<h:outputText value="#{col.valor}" escape="false" />
<h:outputText value="#{col.nome}" />
</rich:columns>
someone knows whats the problem with ui and rich components?
may be you can try like this.
<rich:columns value="#{entity.dadosAdicionais}" var="col" index="index">
<f:facet name="header">
<h:outputText value="#{col.valor}" />
</f:facet>
<h:outputText value="#{model[index].model}" />
</rich:columns>
value= the modelValue for column.

JSF: Empty space caused by rendered attribute

How can I get rid of the empty space by components not rendered via rendered attribute?
I want to display a list of objects in a dataTable and sort them by a property they have. I do it likes this:
view plaincopy to clipboardprint?
<t:dataTable value="#{someBean.values}" var="value">
<h:column>
<f:facet name="header">
<t:outputText value="X" />
</f:facet>
<h:panelGroup rendered="#{value.property eq 'X'}">
<!-- some stuff -->
</h:panelGroup>
</h:column>
<h:column>
<f:facet name="header">
<t:outputText value="Y" />
</f:facet>
<h:panelGroup rendered="#{value.property eq 'Y'}">
<!-- some stuff -->
</h:panelGroup>
</h:column>
</t:dataTable>
It will display one item every row only, because of the rendered thingy. How can I avoid this? I stumpled upon this also on other occasions...
Thank you!
It is obvious to display one item every row with datatable.
You can better have two different datatables, one rendering for x and other rendering for y and adjust your css accordingly that looks like two column of the same table. Or else using richfaces, <rich:subTable> would help you, such as having two subTable in a single dataTable
Use a single column and render in there.
<t:dataTable value="#{someBean.values}" var="value">
<h:column>
<f:facet name="header">
<t:outputText value="#{value.property}" />
</f:facet>
<h:panelGroup rendered="#{value.property eq 'X'}">
<!-- some stuff -->
</h:panelGroup>
<h:panelGroup rendered="#{value.property eq 'Y'}">
<!-- some stuff -->
</h:panelGroup>
</h:column>
</t:dataTable>

Resources