Ajax is not always working - jsf

below you see some part of my code, i just want to select the first value in a form and the rest should be updated via ajax, for example if you select PK than, MccName, MccVorname,MccDepartment should be shown via ajax after this selection.
This should also be possible in other forms indepently,
<h:panelGrid columns="4">
<h:form id="formmcc10">
<h:outputText value="Pls select PK: " />
<p:selectOneMenu value="#categorymcc.mcccatname}" id="mcccat"
immediate="true" valueChangeListener="#categorymcc.processScat}">
<f:selectItem itemLabel="#categorymcc.mcccatname}"itemValue="" />
<f:selectItems value="#categorymcc.categoryName}" />
<p:ajax update="formmcc10:mccscat1 formmcc10:mccscat2 formmcc10:mccscat3" event="change" />
</p:selectOneMenu><h:outputText value="Mcc Name" />
<p:selectOneMenu value="#{categorymcc.submcccatname}"id="mccscat1">
<f:selectItemsvalue="#{categorymcc.subCategoryName}" />
</p:selectOneMenu>
<h:outputText value="Mcc Vorname" />
<p:selectOneMenu value="#{categorymcc.subsubmcccatname}"id="mccscat2">
<f:selectItems value="#{categorymcc.subSubCategoryName}" />
</p:selectOneMenu>
<h:outputText value="Mcc Department:" />
<p:selectOneMenu value="#{categorymcc.abteilung}" id="mccscat3">
<f:selectItems value="#{categorymcc.abteilungCategoryName}" />
</p:selectOneMenu>
</h:form>
</h:panelGrid>

This could be anything, but I encountered one interesting problem like that recently. I tried to output a bean property like #{myBean.otherBean.name} and it worked when I loaded the page by normal request, but it didn't work with AJAX. When I tried #{myBean.otherBean.id}, it worked in both cases.
The problem was, that backend system didn't fill all data for otherBean on AJAX request, it filled only id (probably for better performance). I had to prepare a getOtherBeanById method and when I called that, AJAX started to work as expected.
I'm not an expert on this field, perhaps someone has a more precise explanation for that.

Related

p:commandLink not getting updated

I am using Primefaces 4.0.
Problem i am facing is CommandLink not Getting updated on change event of SelectOnemenu.Code as Follows:-
<p:selectOneMenu id="List"
value="#{Bean.selectedId}" style="width:230px">
<f:selectItem itemLabel="--Select--" />
<f:selectItems value="#{Bean.SelectItemList}" />
<p:ajax event="change" update="enableGo,disableGo"></p:ajax>
</p:selectOneMenu>
<p:commandLink id="enableGo" value="GO" styleClass="blueButton"
rendered="#{Bean.selectedId != null}"
action="#{note.load}">
</p:commandLink>
<p:commandLink id="disableGo" value="GO"
styleClass="disabledButton"
rendered="#{Bean.selectedId == null}">
</p:commandLink>
I also tried updating with the formid eg: ":formid:enableGo,:formid:disableGo" but it didnt work!.
The client side javascript won't be able to find either of the components to update. You'll need to wrap them (the <p:commandLink>s) in a wrapper and then update the wrappers. See BalusC's answer for more details and an example.

Update components without processing in Primefaces

I would like to update a component without processing it. I use a binding get the value of a checkbox and decide if the other component should be rendered. Unfortunately, the update? or the binding? doesn't work as i would.
<p:selectBooleanCheckbox id="isPercentage" value="#{myBean.isDiscountInPercentage}"
label="Percentage" binding="#{discountInPercentage}">
<p:ajax process="" update="outpDiscountValue" />
</p:selectBooleanCheckbox>
<p:outputPanel id="outpDiscountValue">
<h:outputLabel value="$" rendered="#{!discountInPercentage.value}" />
<h:outputLabel value="%" rendered="#{discountInPercentage.value}" />
</p:outputPanel>

Primefaces SelectOneMenu not rendering properly with text

I am trying a userform with primefaces 3.5, all the components are working fine except selectonemenu, which not render correctly.
Its text field is not showing on selection of any drop down field.
i can't post image as i don't have that much reputation
Code
<p:panelGrid id="jobsGrid" columns="2" style="width:100%;margin-bottom:20px;margin-top:20px; margin-left:20px;margin-right:20px;text-align:left;">
<f:facet name="header"> ----- Quick Job Posting -----</f:facet>
<h:outputText value="OLF Number " />
<p:inputText value="#{jobs.jobDetail.OLF_No}" />
<h:outputText value="RRF Number " />
<p:inputText value="#{jobs.jobDetail.RRF_No}" />
<h:outputText value="OLF Status " />
<p:selectOneMenu value="#{jobs.jobDetail.OLF_Status}" style="margin-top:0px;margin-bottom:0px;height:5px;font-size:10px">
<f:selectItem itemLabel="---- Select ----" itemValue="" />
<f:selectItem itemLabel="Approved" itemValue="Approved" />
<f:selectItem itemLabel="Pending Approval" itemValue="Pending Approval" />
<f:selectItem itemLabel="New" itemValue="New" />
</p:selectOneMenu>
<h:outputText value="RRF Type " />
<p:selectOneMenu value="#{jobs.jobDetail.RRF_type}" style="margin-top:0px;margin-bottom:0px;height:5px;font-size:10px">
<f:selectItem itemLabel="---- Select ----" itemValue="" />
<f:selectItem itemLabel="Growth" itemValue="Growth" />
<f:selectItem itemLabel="Replacement" itemValue="Replacement" />
</p:selectOneMenu>
Screen Shot
How can i fix this ?
I fixed this this problem by adding following CSS to my page:
.ui-selectonemenu label.ui-selectonemenu-label{
width:100% !important;
}
I also have fixed widths on my selectonemenus.
Hope this helps in your case also. ;)
This is definitely a problem in Primefaces 3.5. I had the exact same issue, and downgrading to 3.4 solved it.
As a data point, it is worth noting that the rendering problem only existed when I navigated to the page through a p:remoteCommand. Normal action-based navigation works correctly, at least for me.
You can post your code some here, or if not try checking BalusC http://balusc.blogspot.nl/2007/09/objects-in-hselectonemenu.html
If you see that your bean annotations are correct, try using primefaces 3.4 or lower versions.

Export JasperReports to XSL (Excel) or DOC (Word)

I have a situation. I want to generate a report and open it in another window in the JSF platform using JasperReports framework. Right now, I am able to generate the PDF version of the report. The following is the JSF view for the report:
<h:panelGrid columns="2">
<h:outputText value="#{lang.member}: *" />
<h:selectOneMenu converter="memberConverter" value="#{memberProcesListBean.member}" required="true" requiredMessage="#{lang.memberGroupIntroduction_memberGroupName_req_txt}">
<f:selectItem itemLabel="#{lang.select}..."/>
<f:selectItems value="#{memberProcesListBean.memberMenu}"/>
</h:selectOneMenu>
<h:outputText value="#{lang.startDate}: *" />
<p:calendar pattern="dd.MM.yyyy" required="true" requiredMessage="#{lang.defaultProcesses_defaultDate_req_txt}" value="#{memberProcesListBean.startDate}"/>
<h:outputText value="#{lang.endDate}: *" />
<p:calendar pattern="dd.MM.yyyy" required="true" requiredMessage="#{lang.defaultProcesses_defaultDate_req_txt}" value="#{memberProcesListBean.endDate}"/>
<h:outputText value="#{lang.metalCode}: *" />
<h:selectOneMenu converter="metalCodeConverter" value="#{memberProcesListBean.metalCode}" required="true" requiredMessage="#{lang.memberGroupIntroduction_memberGroupName_req_txt}">
<f:selectItem itemLabel="#{lang.select}..."/>
<f:selectItems value="#{memberProcesListBean.metalCodeMenu}"/>
</h:selectOneMenu>
<h:outputText value="#{lang.reportFormat}: *" />
<h:selectOneMenu id="ReportFormat" value="#{memberProcesListBean.fileFormat}">
<f:selectItems value="#{generalInfoBean.fileFormatsList}" />
</h:selectOneMenu>
</h:panelGrid>
<br/>
<br/>
<h:commandLink value="Download" action="#{uyeIslemListesiBean.retrieveReport}" target="_blank" />
However, I weren't able to retrieve and open in another window in the Excel and Word formats of the report. Should I change something in the view segment?
Yours sincerely...
I shouldn't say this, but there is a plugin that may help you to achieve that: JasperReports JSF Plugin. Take a look to its documentation and check if it fits your needs. But I would do, basically, is replace your for a . Since the report is generated in a secondary request you can still bind it to the values of your backing bean, maybe, by means of a custom report source.

<p:selectOneMenu> getting null on submit/next

I am using primefaces wizard. During wizard flow all parameters saved correctly . However <p:selectOneMenu> items getting NULL on submit.Also on 'back', it will not show what I have selected. Same for <p:selectManyMenu> also. Any solution ?
Here is the code snippets.I'm using primefaces-3.0.M3 and jsf2.
<h:outputText value="Employee Status" />
<p:selectOneMenu id="employeeStatus"value="#{employeeRepositoryImpl.employeeStatus.title}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItem itemLabel="Permanent" itemValue="Permanent" />
<f:selectItem itemLabel="Contract" itemValue="Contract" />
<f:selectItem itemLabel="Part-Time" itemValue="Part-Time" />
<f:selectItem itemLabel="Training" itemValue="Training" />
</p:selectOneMenu>
<p:message id="employeeStatusId" for="employeeStatus" />
This is in a <p:wizard> tab, while clicking next button or submit button, the itemValues getting null.Sorry for the re-post.
Have you deleted the previous post?
Anyway, firstly, you should upgrade to Primefaces 3.0.M4!
Secondly, it would be better to use a list along with f:selectItems and all those String values to be stored in a list(this way you have more control over what's in the list and what should the list return), but if you want to stick with f:selectItem try using it with the enclosing tag (it may be a bug without it):
<f:selectItem itemLabel="Permanent" itemValue="Permanent" ></f:selectItem>
Also, I repeat myself, upgrade to Primefaces 3.0.M4!
I have solved it by using primefaces AJAX
<p:ajax update="employeeStatus" listener="#{employeeRepositoryImpl.employeeStatusAjax}" />
inside my </p:selectOneMenu> and I check/process this in side employeeStatusAjax().

Resources