I'm trying to nest a table inside a h:panelGrid component, and h:selectOneMenu is screwing-up the formatting by closing off the cell it appears within and creating a new (and unwanted) row.
My code looks something like this:
<h:panelGrid columns="2">
[Other rows that work just fine]
<h:outputText value="Match [Stuff] to [More Stuff]:" />
<table>
<tr>
<th>[Stuff]</th>
<th>[More Stuff]</th>
</tr>
<tr>
<td>
<h:outputText value="Manually Created First Element of Stuff" />
</td>
<td>
<h:selectOneMenu value="#{bean.moreStuffSetting}">
<f:selectItem itemLabel="--None--" itemValue="" />
<f:selectItem itemLabel="Manual First Choice" itemValue="manual" />
<f:selectItems
value="#{bean.listOfMoreStuff}"
var="moreStuff"
itemLabel="#{moreStuff.name}"
itemValue="#{moreStuff.value}" />
</h:selectOneMenu>
</td>
</tr>
<ui:repeat value="#{bean.listOfStuff}" var="stuff">
<tr>
<td>
<h:outputText value="#{stuff.name}" />
</td>
<td>
<h:selectOneMenu value="#{bean.moreStuffSetting}">
<f:selectItem itemLabel="--None--" itemValue="" />
<f:selectItem itemLabel="Manual First Choice" itemValue="manual" />
<f:selectItems
value="#{bean.listOfMoreStuff}"
var="moreStuff"
itemLabel="#{moreStuff.name}"
itemValue="#{moreStuff.value}" />
</h:selectOneMenu>
</td>
</tr>
</ui:repeat>
</table>
</h:panelGrid>
The problem occurs with that first h:selectOneMenu element. (The h:selectOneMenu element inside ui:repeat is doing exactly what I expect it to, however.) I'm expecting "Manually Created First Element of Stuff" and that drop-down to appear as two cells in the same row. However, this is what's showing up in the generated HTML:
<tr>
<td>Manually Created First Element of Stuff</td>
<td>
</td>
<td></td>
</tr>
<tr>
<td><select...
Two rows. However, in the nested one below, I get this:
<tr>
<td>[Label I'm expecting]
</td>
<td><select...
... which is exactly how I expected it to behave.
What am I doing wrong? Am I misusing JSF somehow? Is there some face-palm-worthy typo in there I'm not seeing?
The <h:panelGrid> picks the first sibling in the JSF component tree to start a new table cell. The plain HTML <table> element which you've there isn't a JSF component.
Wrap it in a <h:panelGroup>.
<h:panelGrid columns="2">
<h:outputText value="Match [Stuff] to [More Stuff]:" />
<h:panelGroup>
<table>
...
</table>
</h:panelGroup>
</h:panelGrid>
An alternative is to just use <h:dataTable> instead.
Related
I want to pass a parameter to get values for f:selectItem inside p:selectOneMenu. (I used this p:selectOneMenu inside a ui:repeat)
The values that will populate the select one menu needs to be changed depending on the parameter passed to the bean.
I tried as follows, but erros comes as "The class does not have the property
'proceduresPerformedInAProcedureRoom'.
How can I achieve that ?
JSF File
<table >
<tr>
<td>
<p:outputLabel value="Room" ></p:outputLabel>
</td>
<td>
<p:selectOneMenu value="#{ii.ci.institutionValue}" >
<f:selectItem itemLabel="Please select" ></f:selectItem>
<f:selectItems value="#{webUserController.loggableProcedureRooms}"
var="ipr"
itemLabel="#{ipr.name}"
itemValue="#{ipr}">
</f:selectItems>
<f:ajax event="change" execute="#this" render="prM lblPrM" ></f:ajax>
</p:selectOneMenu>
</td>
</tr>
<tr>
<td>
<p:outputLabel id="lblPrM" value="Procedures for #{ii.ci.institutionValue}" ></p:outputLabel>
</td>
<td>
<p:selectOneMenu id="prM" value="#{ii.addingItem.ci.itemValue}" >
<f:selectItem itemLabel="Please select" ></f:selectItem>
<f:selectItems value="#{relationshipController.proceduresPerformedInAProcedureRoom}"
var="li"
itemLabel="#{li.displayName}"
itemValue="#{li}">
<f:param name = "procedureRoom" value = "#{ii.ci.institutionValue}" />
</f:selectItems>
</p:selectOneMenu>
</td>
</tr>
</table>
Controller
public List<Item> proceduresPerformedInAProcedureRoom(Institution procedureRoom){
List<Relationship> rs = findRelationships(institution, RelationshipType.Procedure_for_institution);
List<Item> ps = new ArrayList();
for(Relationship r:rs){
ps.add(r.getItem());
}
return ps;
}
I am working with JSF 2.2 and Primefaces 6.0. I have a p:dataTable with different p:columns, and each column has many rows. I would like that, whenever column1 input changes, column2 input, in the same row, updates, however, it is not working; it doesn't render.
This is my xhtml code:
<p:dataTable value="#{myBean.objectsList}" var="object">
<p:column headerText="column1">
<table>
<tbody>
<ui:repeat value="#{object.subObjects}" var="object2">
<tr>
<td>
<c:set var="object3" value="#{object2.subObjects}"/>
<h:inputText id="value1#{myBean.toString(object3)}" value="#{object3.value1}">
<f:ajax event="change" listener="#{myBean.doSomething}"
execute="#this" render="#this"/>
</h:inputText>
</td>
</tr>
</ui:repeat>
</tbody>
</table>
</p:column>
<p:column headerText="column2">
<table>
<tbody>
<ui:repeat value="#{object.subObjects}" var="object2">
<tr>
<td>
<c:set var="object3" value="#{object2.subObjects}"/>
<h:inputText value="#{object3.value2}" disabled="disabled">
<f:ajax event="change" listener="#{myBean.doSomething2}"
execute="#this" render="value1#{myBean.toString(object3)}"/>
</h:inputText>
</td>
</tr>
</ui:repeat>
</tbody>
</table>
</p:column>
</p:dataTable>
Each object has many objects as a List.
In f:ajax tag of the first column (column1), you have given #this as value for the attribute render.
Instead, please try giving id of the component column2 or id of the p:dataTableitself.
I have a condition where i need to have two radio buttond with related data in the below the buttons.
i did something like below but the selected radio button value is not getting in the backed been. Please correct where i am going wrong
<table>
<tr>
<td>
<h:selectOneRadio value="#{beenObject.adressSelection}">
<f:selectItem itemValue="Employer" itemLabel="Employer" />
</h:selectOneRadio>.
</td>
<td>
<h:selectOneRadio value="#{beenObject.adressSelection}">
<f:selectItem itemValue="Consultant" itemLabel="Consultant" />
</h:selectOneRadio>.
</td>
</tr>
<tr>
<td>
<h:outputText value="#{beenObject.consultentDetailsString}">
</h:outputText>
</td>
</tr>
<tr>
<td>
<h:outputText value="#{beenObject.employerDetailsString}">
</h:outputText>
</td>
</tr>
</table>
I'm facing an issue similar as yours however I tried to replicate my situation at your code. While I was simplifying the lines I just end-up fixing your bug.
Below the code wich will work for you.
<table>
<tr>
<td>
<h:selectOneRadio value="#{beenObject.adressSelection}">
<f:selectItem itemValue="Employer" itemLabel="Employer" />
<f:selectItem itemValue="Consultant" itemLabel="Consultant" />
</h:selectOneRadio>
</td>
</tr>
<tr>
<td>
<h:outputText value="#{beenObject.consultentDetailsString}">
</h:outputText>
<h:outputText value="#{beenObject.employerDetailsString}">
</h:outputText>
</td>
</tr>
</table>
Explaining what I did:
I grouped the elements f:selectItem underneath f:selectItems like is shown in the sample at primeface showcase and it starts to work.
Hope it work as you want.
Cheers.
I 'm using the tag ui:repeat to display a list of pictures and their titles.
My code is:
<p:dialog id="idSchemaDlg5" widgetVar="schemaDlg" position="10" resizable="true" modal="true" header="Schéma des composants">
<h:panelGrid columns="1">
<ui:repeat value="#{imageStreamer.pictureNamesList}" var="imageName" >
<h:panelGrid columns="#{imageStreamer.pictureNamesList.size()}">
<p:graphicImage value="#{imageStreamer.image}" >
<f:param name="pictureName" value="#{imageName}" />
</p:graphicImage>
<h:outputText value="#{imageName}"/>
</ui:repeat>
</h:panelGrid>
</p:dialog>
I would to display the list of pictures horizontally but the list of pictures with this code was vertically displayed.
Any help is welcome.
I would to have this structure in output <table><tbody><tr><td><img1/><title1/></td><td><img2/><title2/></td><img3/><title3/><td></td></tr></table>
The <ui:repeat> inside <h:panelGrid> won't generate physically multiple table cells. It will generate only one table cell. In fact, each immediate child UI component of <h:panelGrid> counts as a single table cell. The <ui:repeat> is an UI component.
You need <c:forEach> instead. It's a taghandler and runs during building JSF component tree instead of during generating HTML output. It generates physically multiple JSF components, in contrary to <ui:repeat> which represents physically one JSF component which is reused everytime during generating HTML output.
<h:panelGrid columns="#{imageStreamer.pictureNamesList.size()}">
<c:forEach items="#{imageStreamer.pictureNamesList}" var="imageName">
<h:panelGroup>
<p:graphicImage value="#{imageStreamer.image}">
<f:param name="pictureName" value="#{imageName}" />
</p:graphicImage>
<h:outputText value="#{imageName}"/>
</h:panelGroup>
</c:forEach>
</h:panelGrid>
(note that you need to wrap the image and the text in a <h:panelGroup> to represent a single table cell)
Or, if you insist in using <ui:repeat>, then you have to write down the desired HTML output yourself.
<table>
<tbody>
<tr>
<ui:repeat value="#{imageStreamer.pictureNamesList}" var="imageName">
<td>
<p:graphicImage value="#{imageStreamer.image}">
<f:param name="pictureName" value="#{imageName}" />
</p:graphicImage>
<h:outputText value="#{imageName}"/>
</td>
</ui:repeat>
</tr>
</tbody>
</table>
See also:
JSTL in JSF2 Facelets... makes sense?
create table columns dynamically in JSF
you must change the order of the h:panelGrid and p:graphicImage. because you repeat the creation of the h:panelGrid with size() as number of columns. your code becomes:
<p:dialog id="idSchemaDlg5" widgetVar="schemaDlg" position="10" resizable="true" modal="true" header="Schéma des composants">
<h:panelGrid columns="#{imageStreamer.pictureNamesList.size()}">
<ui:repeat value="#{imageStreamer.pictureNamesList}" var="imageName" >
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td> <p:graphicImage value="#{imageStreamer.image}" >
<f:param name="pictureName" value="#{imageName}" />
</p:graphicImage>
</td>
</tr>
<tr>
<td ><h:outputText value="#{imageName}"/></td>
</tr>
</table>
</ui:repeat>
</h:panelGrid>
</p:dialog>
I need a way to create editable table like this. I interested is it possible to use h:panelGrid to display and edit the data. From my previews post I saw that it's possible to simple JSF table, but is this possible with h:panelGrid?
<table>
<ui:repeat var="elem" value="#{yourMB.yourDataList}">
<tr>
<td>#{elem.userid}</td>
<td>
<h:outputText value="#{elem.name}"
rendered="#{not elem.editable}" />
<h:inputText value="#{elem.name}" rendered="#{elem.editable}" />
</td>
<td>
<h:outputText value="#{elem.telephone}"
rendered="#{not elem.editable}" />
<h:inputText value="#{elem.telephone}"
rendered="#{elem.editable}" />
</td>
<td>
<h:commandLink value="Edit" rendered="#{not elem.editable}"
action="#{yourMB.editAction(elem)}" />
</td>
</tr>
</ui:repeat>
</table>
<h:commandButton value="Save Changes" action="#{yourMB.saveAction}" />
The answer is "NO". Try to use h:dataTable instead of h:panelGrid.