I have a page with p:datatable and dynamic columns.
I'm trying to add a command button to the headers with an f:attribute as a value for the command button click.
the problem is I don't get to the server at all when pressing the header button.
here is a code snipet
<p:dataTable >
<p:columns value="#{controller.columnsTitles}" var="column" columnIndexVar="colIndex">
<f:facet name="header">
<p:panel >
<table>
<tr>
<th>
<p:panel>
#{column.label}
</p:panel>
</th>
</tr>
<tr>
<th>
<h:panelGroup >
<p:commandButton value="Add" actionListener="#{controller.doStaff}">
<f:setPropertyActionListener value="#{column.value}" target=#{controller.selectedToEdit}" />
</p:commandButton>
</h:panelGroup>
</th>
</tr>
</table>
</p:panel>
</f:facet>
<p:column>
......
</p:column>
</p:columns>
</p:dataTable>
[Edit]
I found a solution for this issue.
To the commandbutton I added an onClick event that pass the parameter selectedToEdit to a javascript function that in her turn calls a p:remoteCommand that pass the parameter to the server. I also changed the actionListener of the commandButton to action and now it's working.
Now the code looks as follow:
<script>
function jsFunc(param)
{
command([{name:'selectedToEdit',value:selectedToEdit}]);
}
</script>
.....
<p:remoteCommand name="command" actionListener="#{controller.selectedToEdit}" />
<p:commandButton value="Add" action="#{controller.doStaff}" onclick="jsFunc('#{column.value}')" />
Related
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 '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 have button that when I click on it, the dialog appear and in that dialog , I have p:selectBooleanCheckBox and h:outputlable.
The first problem is when p:dialog appear I can not choose p:selectBooleanCheckBox separately. It means that when I click on one of them, all of p:selectBooleanCheckBox choose.
The second problem is when I click on p:commandButton in dialog , the actionListener work but it dos not disappaer and it shows permanently. I think the problem cause by Ajax. could you please tell me how can I fix this problem?
<h:panelGrid>
<p:dialog appendToBody="true" header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<p:dataGrid id="AcceptDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.filterBusinessRequest()}"
columns="1" >
<tr>
<td>
<p:selectBooleanCheckbox/>
</td>
<td>
<h:outputLabel value="test"/>
</td>
</tr>
</p:dataGrid>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}"
update="display" />
</h:panelGrid>
</p:dialog>
</h:panelGrid>
<table style="width: 100%" id="tabell">
<p:selectOneButton value="#{inviteRequestManagedBean.filterType}">
<f:selectItem itemLabel="#{inviteRequest_msg.request}" itemValue="request" />
<f:selectItem itemLabel="#{inviteRequest_msg.archive}" itemValue="archive" />
<f:ajax event="change" execute="#form" render="#form" />
<tr>
<td>
<p:panel></p:panel>
<p:dataGrid id="requestDataGrid" var="tBusinessPartnerRequestInfo"
value="#{inviteRequestManagedBean.filterBusinessRequest()}" columns="1" >
<p:column>
<div>
<table border="0" width="100%">
<tr>
<td>
<p:graphicImage value="#{tBusinessPartnerRequestInfo.partySender_imageUrl}"/>
</td>
<td>
<div>
<table border="0" width="100%">
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.requestDate}"/>
</td>
</tr>
<tr>
<td>
<h:outputLabel value="#{tBusinessPartnerRequestInfo.partySender_fullName}"/>
</td>
</tr>
</table>
</div>
</td>
here is where p:dialog call
<td>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
onclick="dlg.show()" />
</td>
<td>
<p:commandButton id="noNowCommonButton" value="#{inviteRequest_msg.notnow}"
actionListener="#{inviteRequestManagedBean.notNowRequest(tBusinessPartnerRequestInfo.id)}"
update="#form" />
</td>
<p:blockUI block="acceptCommonButton" trigger="acceptCommonButton"/>
<p:blockUI block="noNowCommonButton" trigger="acceptCommonButton"/>
<p:blockUI block="acceptCommonButton" trigger="noNowCommonButton"/>
<p:blockUI block="noNowCommonButton" trigger="noNowCommonButton"/>
<td>
<p:panel>
<p:ajaxStatus>
<f:facet name="start">
<p:graphicImage value="../resources/img/loading.gif"/>
</f:facet>
<f:facet name="complete">
<h:outputLabel value=""/>
</f:facet>
</p:ajaxStatus>
</p:panel>
</td>
</tr>
</table>
</div>
<hr/>
</p:column>
</p:dataGrid>
</td>
</tr>
</p:selectOneButton>
</table>
</h:panelGrid>
<h:panelGrid>
<p:dialog appendToBody="true" header="Selected Values" modal="false" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<p:dataGrid id="AcceptDataGrid" var="tBusinessPartnerRequestInfo" value="#{inviteRequestManagedBean.loadPartyRelationShipType()}"
columns="1" >
<tr>
<td>
<p:selectBooleanCheckbox/>
</td>
<td>
<h:outputLabel value="test"/>
</td>
</tr>
</p:dataGrid>
<p:commandButton id="acceptCommonButton" value="#{inviteRequest_msg.accept}"
actionListener="#{inviteRequestManagedBean.acceptRequest(tBusinessPartnerRequestInfo.id)}"
update="display" oncomplete="dlg.hide()" />
</h:panelGrid>
</p:dialog>
</h:panelGrid>
</ui:composition>
Your markup is a bit scary, I don't get why you've got so much thing in your <p:selectOneButton (all the <tr>'s) so instead of trying to correct everything as I start to understand what you try to achieve I'll give you a working example.
Sample.java
public class Sample implements Serializable {
private String name;
private boolean checked;
public Sample() {
}
public Sample(String name, boolean checked) {
this.name = name;
this.checked = checked;
}
// Getter and Setter for name and checked omitted
}
SampleBean.java
#ManagedBean
#ViewScoped
public class SampleBean implements Serializable {
private List<Sample> samples;
private Sample currentSample;
public void prepareEdit(Sample sample) {
this.currentSample = sample;
}
public void edit() {
// Do what you need to do with sample
// You can get it with : this.currentSample
RequestContext.getCurrentInstance().execute("dlg.hide()");
}
public List<Sample> getSamples() {
if (this.samples == null) {
this.samples = new ArrayList<Sample>();
for (int i = 1; i <= 10; ++i) {
this.samples.add(new Sample("Sample n°" + i, (i % 3 == 0)));
}
}
return samples;
}
public void setSamples(List<Sample> samples) {
this.samples = samples;
}
public Sample getCurrentSample() {
return currentSample;
}
public void setCurrentSample(Sample currentSample) {
this.currentSample = currentSample;
}
}
view.xhtml :
<h:form id="myForm">
<p:dataTable value="#{sampleBean.samples}" var="sample">
<p:column headerText="Name">
<h:outputText value="#{sample.name}" />
</p:column>
<p:column headerText="Checked?">
<h:outputText value="#{sample.checked}" />
</p:column>
<p:column style="width: 1px; text-align: center;">
<p:commandButton value="edit"
actionListener="#{sampleBean.prepareEdit(sample)}"
update=":dialog"
oncomplete="dlg.show()" />
</p:column>
</p:dataTable>
</h:form>
<p:dialog id="dialog" widgetVar="dlg" header="Editing">
<h:form rendered="#{!empty sampleBean.currentSample}">
<h:outputText value="Current sample is #{sampleBean.currentSample.name}" />
<br />
<p:selectBooleanCheckbox value="#{sampleBean.currentSample.checked}" />
<br />
<p style="width: 100%; text-align: center;">
<p:commandButton actionListener="#{sampleBean.edit()}"
value="Edit"
update="#form :myForm" />
</p>
</h:form>
</p:dialog>
As you can see I'm storing a currentSample (sampleBean must be #ViewScoped) which helps me to render a custom dialog with the correct current information.
My last comment from your question about the binding of the <p:selectBooleanCheckbox is important because you can get a custom checkbox value only if it's bound to a different endpoint based on the context (here currentSample).
Don't hesitate to comment if something is unclear for you!
On my page galleria was working fine before adding captcha to the code.
After adding captcha to the code galleria is not displaying on page.
I tried to keep both captcha on different form but still it is not working.
Captcha is working fine.
I've no idea what is problem with this.
<h:form id="frmTest">
<center >
<br/><br/>
<table width="70%" border="0">
<tr>
<td width="70%" align="center">
<p:panel >
<p:galleria value="#{LoginBean.imgList}"
var="image" effect="slide"
effectSpeed="1000"
panelWidth="500" panelHeight="300"
frameWidth="100" frameHeight="70"
rendered="true">
<p:graphicImage value="../resources/images/{image}"/>
</p:galleria>
</p:panel>
</td>
<td width="30%">
<p:panel>
<p:commandButton id="btnShowCaptcha"
process="#form"
onclick="captchaDlgWar.show()"
value="Show Captcha"/>
</p:panel>
</td>
</tr>
</table>
</center>
<p:dialog widgetVar="captchaDlgWar" id="capchaDlgId"
hideEffect="explode" showEffect="clip"
modal="true" closable="true" resizable="false"
header="Prove you are human..." width="360" height="190">
<h:panelGrid columns="1">
<p:captcha label="Captcha"
id="captchaId"
language="tr"
required="true"/>
<p:commandButton id="btnContinue"
ajax="false"
value="Continue"
action="#{MyBean.onContinueAction}"/>
</h:panelGrid>
</p:dialog>
</h:form>
MyBean
public String onContinueAction() {
RequestContext.getCurrentInstance().execute("captchaDlgWar.hide()");
return "somePage.xhtml";
}
Thnx.
try taking your dialog outside of your form and add another form inside your dialog
so you'll have one dialog with galeria inside and another dialog inside your dialog make sure you don't nest forms
<h:form.... <p:galleria...</h:form>
and
<p:dialog><h:form.... <p:captcha ...</h:form></p:dialog>
Also
I'd try to use p:panelGrid Primefaces PanelGrid instead of the table
In my application I have implemented an employee search functionality using the RichFaces 3.3 modal panel on Facelets. I'm trying to make this reusable across my application, so I have added the following code in facelet-taglib_1_0.xml
<tag>
<tag-name>employeeSearch</tag-name>
<source>employee-search.xhtml</source>
</tag>
The xhtml page contains the following components
search input field
search button
result datatable
I have also mapped a backing bean.
My issue is that I'm not able to get the value from the search input field
I wonder whether the approach given above is correct or if there's any better approach for this?
Thanks for your reply Arjan...i tried but result not binding in result datatable list. my code is here.
EmployeeSearchBean is request scope.
Calling reusable tag code :
<foo:employeeSearch orgSearchId="empHistSearch" bean="#{EmployeeSearchBean}" action="findEmployee" renderedVal="#{empHist.editable}" />
Model panel code :
<a4j:jsFunction name="submit" action="#{bean[action]}" />
<rich:modalPanel id="orgUnitSearchPanel_empHistSearch" autosized="true" width="450">
<f:facet name="header">
<h:outputText value="#{messages.mepit_OE_Search}" />
</f:facet>
<f:facet name="controls">
<h:panelGroup>
<h:graphicImage value="/pics/buttons/fenster_schliessen.gif" id="hideOrgUnitSearchPanel_#{orgSearchId}" styleClass="hidelink" />
<rich:componentControl for="orgUnitSearchPanel_#{orgSearchId}" attachTo="hideOrgUnitSearchPanel_#{orgSearchId}" operation="hide" event="onclick" />
</h:panelGroup>
</f:facet>
<table class="dispinputTable" cellspacing="2" cellpadding="0">
<tr>
<td style="width: 75px;">
<h:outputText value="#{messages.mepit_OE}" />
</td>
<td>
<h:inputText id="empHist_oeExecutingName" value="#{EmployeeSearchBean.empSearchCriteria}" styleClass="text" size="60" />
</td>
<td>
<a4j:commandButton styleClass="mepitButtons" onclick="submit();" value="#{dbMessages.db_search}" title="#{dbMessages.db_search}" reRender="orgUnitDT#{orgSearchId}" />
</td>
</tr>
<tr>
<td colspan="3" >
<rich:extendedDataTable width="425px" height="150px"
id="orgUnitDT#{orgSearchId}" cellspacing="0" cellpadding="0" border="0"
styleClass="inhalt" var="oeLst" value="#{EmployeeSearchBean.employeeList}" rowClasses="row0, row1">
<rich:column width="370px;" align="left">
<f:facet name="header">
<h:outputText value="#{messages.mepit_OE}" />
</f:facet>
<h:outputText id="empHist_OE" value="#{oeLst.name}" />
</rich:column>
<rich:column width="55px;">
<f:facet name="header">
<h:outputText value="#{messages.mepit_select}" />
</f:facet>
<h:commandLink value="" styleClass="edit">
<f:setPropertyActionListener value="#{oeLst}" target="#{SkillPM.executingOrgUnit}" reRender="empHist_orgUnit" />
</h:commandLink>
<h:commandLink styleClass="edit" onclick="#{rich:component(mepit:concat(orgSearchId,'orgUnitSearchPanel'))}.hide(); submit(); return false;" />
</rich:column>
</rich:extendedDataTable >
</td>
</tr>
</table>
</rich:modalPanel>
One thing that's immediately open for improvement is that you should not add your own tags to what looks like the standard facelets taglib file. Leave that file alone and create your own file.
If you pass a value binding to your tag, and bind your search input field to this, then it should work:
<foo:employeeSearch myValue="#{yourBackingBean.someValue}"/>
And then in employee-search.xhtml:
<h:inputText value="#{myValue}" />
Feel free to use some other name instead of myValue. The point is that the attribute name you use on your custom tag should match what the input text component binds to.