Model not updated if a4j:ajax renders #form instead of other specific component - jsf

In view I have this:
<h:selectOneMenu id="makeSelect" value="#{bean.selectedMake}">
<f:selectItem itemLabel="---" itemValue="#{null}" />
<f:selectItems value="#{bean.availableMakeList}"/>
<a4j:ajax listener="#{bean.updateModelList}" render="#form"/>
<h:messages/>
</h:selectOneMenu>
bean.selectedMake gets updated only on the first time I change the selection.
If I change render="#form" to render="someOtherComponent", bean.selectedMake is updated normally. But I want to rerender all form.
Why model is not updated if I rerender all form?

Related

PrimeFaces dialog doesn't use the information I provide in the view

I have a view which contain the following fields:
<p:selectOneMenu style="width:40px" value="#{capacityFamilyBean.capacityFamily.bottleneck}">
<f:selectItems value="#{capacityFamilyBean.availableCapFamilyBottlenecks()}"/>
</p:selectOneMenu>
<p:inputText id="capacityFamilyName" binding="#{capacityFamilyName}" style="margin-left:20px" value="#{capacityFamilyBean.capacityFamily.name}">
<p:ajax event="change" update="newBundleButton"/>
</p:inputText>
<p:commandButton id="newBundleButton" icon="ui-icon-plus" disabled="#{empty capacityFamilyName.value}" value="${msgs.New}" oncomplete="PF('capacityFamilyDialog').show();"/>
you can see the value properties are {capacityFamilyBean.capacityFamily.prprty}
capacityFamilyDialog uses the same properties, but they are not pre-filled
<p:selectOneMenu value="#{capacityFamilyBean.capacityFamily.bottleneck}">
<f:selectItems value="#{capacityFamilyBean.availableCapFamilyBottlenecks()}" />
</p:selectOneMenu>
<p:inputText id="capacityFamilyName" style="margin-left:20px" value="#{capacityFamilyBean.capacityFamily.name}"/>
I'm assuming they refer to different capacityFamily object, but how can I counter that?
The dialog is delivered with the page. So it's completely empty.
oncomplete="PF('capacityFamilyDialog').show();"
is pure javascript and only shows this empty popup. If you like to have a dialog with actual values, you have to update it in an ajax-call like your commandButton.
<p:commandButton value="${msgs.New}" update="capacityFamilyDialog_ID" oncomplete="PF('capacityFamilyDialog').show();"/>
The dialogue is functional when you click the button. I think you should update the id for dialogue box.
JSF Code
<p:commandButton id="impBtb"
process="#this" icon="ui-icon-plus" disabled="#{empty capacityFamilyName.value}"
value="${msgs.New}" oncomplete="PF('capacityFamilyDialog').show();" update="#form:capacityFamilyDialog">
</p:commandButton>
So, you may have to perform a ajax-call from your commandbutton to update the dialog box.
Hope it helps!!

how to display value data from bean to radio button jsf

Is it possible to display values from my bean to radio button in the view?
I'm using jsf.
<h:outputLabel value="Gender"/>
<h:selectOneRadio value="#{ctrlLogin.session.gender}" readonly="true">
<f:selectItem itemValue="Male" itemLabel="Male" itemDisabled="true" />
<f:selectItem itemValue="Female" itemLabel="Female" itemDisabled="true"/>
</h:selectOneRadio>
i already have a user bean that carries the actual value from the database
Of course it is possible. I assume that you have some kind of list in a bean? You really should provide some code. Anyway, the solution below should give you an idea how to populate radio buttons with values.
<h:selectOneRadio id="radio"
value="#{bean.selectedOption}">
<f:selectItems value="#{bean.listOfOptions}" var="item" itemLabel="#{item}" itemValue="#{item}" />
</h:selectOneRadio>

How to Freeze JSF Radio Buttons

i have the following jsf code:
<h:selectOneRadio value="#{ref.arrive.boardingInformation}">
<f:selectItems value="#{newMessage.boardingInformationSelectItemList}" />
</h:selectOneRadio>
Is it possible to freeze this kind of selectradiobutton in that way, that my user canĀ“t change the value?
This radiobuttons are only for reading and not for writing or changing.
Try this:
<h:selectOneRadio value="#{ref.arrive.boardingInformation}" disabled="true">
<f:selectItems value="#{newMessage.boardingInformationSelectItemList}" />
</h:selectOneRadio>
Here are the available properties: http://www.tutorialspoint.com/jsf/jsf_selectoneradio_tag.htm

p:watermark clears on updating Component even if there is no value

I'm using Primefaces p:watermark on a p:inputText. Its working fine.
When ever I update the component its loosing watermark,even when there is no content inside the p:inputText
<h:form id="reg_frm">
<p:inputText id="name" value="#{user.name}"/>
<p:watermark value="your name" for="name" id="name_watermark" />
<p:selectOneMenu value="#{user.drpvalue}">
<f:selectItem itemLabel="One" itemValue="1"/>
<f:selectItem itemLabel="two" itemValue="2"/>
<f:selectItem itemLabel="three" itemValue="3"/>
<f:selectItem itemLabel="four" itemValue="4"/>
<p:ajax event="change" update="name name_watermark"/>
</p:selectOneMenu>
</h:form>
How do I retain the Watermark when there is no content in the
p:inputText after update?
Note: Primefaces version - 3.5
According to the PrimeFaces showcase for watermarks: "Watermark displays a hint about input fields by using native placeholder in supported browsers and a javascript solution in others browser compatibility."
PrimeFaces probably adds some hidden javascript stuff to the element which is a parent of both components (input and watermark). In your case that's the form which you would need to update. If you don't want that, put a new panelgroup around both elements and update that, which will have the same effect.
Try this attribute:
oncomplete="PrimeFaces.showWatermarks()"
It was given in Primefaces User's Guide.

How to use h:selectOneMenu in f:selectItem?

<h:selectOneRadio id="profiles" layout="pageDirection" value="#{bean.selectedProfile}" style="font-size:12px;">
<f:selectItem itemValue="0" itemLabel="#{messages.msg_profile1} ">
<h:selectOneMenu id="countries" value="#{bean.selectedCountry}" required="false" style="width:190px">
<f:selectItems value="#{bean.countries}" />
</h:selectOneMenu>
</f:selectItem>
<f:selectItems value="#{fraudBinPageBean.profiles}"/>
</h:selectOneRadio>
I have written above code in my app. It is working fine.
But select box displaying above the radio button.
My requirement display the select box beside the radio button.
Can you please help me what is the problem?
Are you sure that it is working correctly? Referring to this answer it is not possible since the body of the f:selectItem tag must be empty.
Try to redesign your form that you get along without the nested h:selectOneMenu.
You want to keep your radio button and Select box in same line. This is more related to CSS.
Try This code.
<h:selectOneRadio id="profiles" layout="pageDirection"
value="#{bean.selectedProfile}" style="font-size:12px;display:inline">
<f:selectItems value="#{fraudBinPageBean.profiles}"/>
</h:selectOneRadio>
<f:selectItem itemValue="0" itemLabel="#{messages.msg_profile1} ">
<h:selectOneMenu id="countries" value="#{bean.selectedCountry}" required="false" style="width:190px">
<f:selectItems value="#{bean.countries}" />
</h:selectOneMenu>
as shown in above code Add CSS property Display:inline to your style attribute of selectoneradio

Resources