p:input will not render value attribute - jsf

I have a problem rendering p:inputText from primefaces.
Their Demo at http://www.primefaces.org/showcase/ui/input/inplace.xhtml is working. If I change it to my requirements it fail.
In my .xhtml I've the following code. The first part will print out the given ipaddress as plain text,
#{hostEntryManaged.selectedEntry.ipAddress}
but the value attribute of the p:inputText keeps blank. Nothing to see in the final html.
<h:outputLabel for="ipaddr" value="IP: " />
<p:inplace id="ipaddr" editor="true" >
<p:inputText value="#{hostEntryManaged.selectedEntry.ipAddress}" required="true" label="text" />
</p:inplace>
I can add
value="#{hostEntryManaged.selectedEntry.ipAddress}" also to the p:inplace. There it works fine, till I click the field and it turns to the (desired) input field.
It feels that the <p:inputText..../> is out of scope, so it can't access my bean.
But there are no errors.

Related

JSF action not called OR selectbox value is null

i have another strange JSF problem here... I don´t really know why, but what ever i try to do, i have one out of two problems. Either the action method inside my popupPanel is not (means never) called or it is called, but the value from my selectBox is (always) null. Can´t figure out, what the problem is, but it seems to me, like it´s a XHTML property problem.
Already tried to put the popupPanel outside my h:form (helped me at some other locations...), i also tried to put it outside and put another form into my popup. Beyond that i was trying to change the attachment to parent/form and i changed the execute of the commandButton inside my popup to form/form-id/popuppanel-id and i guess there were some more things i did... but nothing helped.
The Bean is session scoped and i am using Richface 4.0 Final if it does matter at all.
What ever, the XHTML looks like this:
<rich:popupPanel
header="#{label['edit.title']} #{mandateAction.ccService.mandateList[mandateAction.currentIndex].id}"
id="addExternalSystem"
onmaskclick="#{rich:component('addExternalSystem')}.hide()"
domElementAttachment="form" autosized="true" layout="block">
<h:panelGrid columns="2">
<h:outputText value="#{label['login.username']}" />
<h:inputText
value="#{mandateAction.newExternalSystem.username}" />
<h:outputText value="#{label['login.password']}" />
<h:inputSecret
value="#{mandateAction.newExternalSystem.password}" />
<h:outputText value="#{label['mandate.externalSystem']}" />
<h:selectOneMenu
value="#{mandateAction.newExternalSystem.externalSystem}">
<f:selectItems
value="#{creditcardConfigurationService.externalSystems}"
itemLabel="#{system.name}" itemValue="#{system}"
var="system" />
<f:converter binding="#{externalSystemConverter}" />
</h:selectOneMenu>
....
<a4j:commandButton value="#{label['insert.save']}"
action="#{mandateAction.insertNewSystem}"
render="mandate_table" execute="#form"
oncomplete="if (#{facesContext.maximumSeverity==null}) {#{rich:component('addExternalSystem')}.hide();}" />
If your page have any of the required fields kept as empty the submit from the popup panel will not work. In that case include the popup panel inside a form and domElementAttachment="form" , and perform the submit.

inputtext only sets value after pressing enter

Maybe it's a trivial question but I need some understanding here.
I have a <h:inputText value="#{bean.name}"/> tag and a "Create" button that inserts the value in the database. If I just type the value and hit "Create", a ConstraintViolationException is thrown because the #{bean.name} value is null. I just found out that if I hit enter after typing the value, the string in set in the bound property and the bean is successfully persisted.
So, the question is: wich richfaces or a4j tags I must include around the inputText so that the component sets de bean's value automatically? The code is pretty straightforward:
<h:form>
<h:inputText id="name" value="#{bean.name}">
<h:commandButton value="Create" actionListener="#{bean.create}"/>
</h:form>
Update:
I've managed to reach the required behaviour by:
<h:inputText id="name" value="#{bean.name}">
<a4j:ajax event="keydown" execute="#form"/>
</h:inputText>
Is there a tag that I could wrap all the page input components in and remove the <a4j:ajax>tag?

Trying to understand why h:commandLink submits through validation and a4j:commandLink doesn't

First of all, i'm using Jsf 1.2...
I have a problem with submitting some values in a form to validation.
Specifically this code segement:
<h:panelGrid columns="4" id="StatusPanel">
<h:outputText value="#{msg.Phone_number_to_send_SMS_to}" />
<h:inputText id="phoneNumber" value="#{general.smsPhoneNumber}" required="true"
requiredMessage="Please enter a valid phone number." />
<a4j:commandLink value="#{msg.Submit_Button}"
reRender="pinCodeDeliveryMsgText, pinCodeDeliveryMsg, pinCodeDeliveryFailedMsg, pinCodeDeliveryMainPanel, LastPinCodeMsg, SendingSMSMSG"
action="#{general.submit}" />
<h:message for="phoneNumber" fatalClass="mandatoryFieldMissing" errorClass="mandatoryFieldMissing" tooltip="true" />
</h:panelGrid>
Which looks like this in the html page:
Whenever I press the submit link, the page doesn't really go through validation, it seems to go with the last successull values instead. The result being that, if the phone number field is left empty, it does nothing and doesn't even render the <h:message> tag.
Actually, I have a workaround fix that looks like this:
<h:commandLink value="#{msg.Submit_Button}">
<a4j:support event="onclick" reRender="pinCodeDeliveryMsgText, pinCodeDeliveryMsg, pinCodeDeliveryFailedMsg, pinCodeDeliveryMainPanel, LastPinCodeMsg, SendingSMSMSG"
action="#{general.submit}"/>
</h:commandLink>
But i'm really curious to know what's the difference between a4j:commandLink and h:commandLink that makes one woirk and the other not.
TnX
Have you tried to set the process attribute of a4j:commandLink to the id of the inputText? Looks like you are just triggering rerendering of some components, so no model update is performed at all.

Code picks up value from selectOneMenu and selectBooleanCheckbox, even though it is not rendered

I've got code the following code in my .xhtml
<t:panelGroup rendered="false">
<t:selectOneMenu id="id" value="#{row.someValue}" displayValueOnly="#{form.readState}">
<f:selectItems value="#{row.listOfValues}"/>
</t:selectOneMenu>
</t:panelGroup>
The listOfValues is set in a form populator, and is thus present in the form object. Also, as expected, the portion outlined above is not rendered in the output HTML.
But, when clicking the save button in the page the following code tries to get the value from the XHTML, even though it is not rendered. It will thus not copy the value present in the form, but set it to null (as it is not set in the XHTML).
object1.setSomeValue(form.getSomeValue());
As far as I can see this only happens with selectBooleanCheckbox and selectOneMenu. E.g. inputText works fine.
Any idea on how to fix it?
Try this:
<t:panelGroup>
<t:selectOneMenu id="id" value="#{row.someValue}" displayValueOnly="#{form.readState}">
<f:selectItems value="#{row.listOfValues}" rendered="false"/>
</t:selectOneMenu>
</t:panelGroup>

Sending JSF parameters within Richfaces a4j:repeat

I'm attempting to put a few drop down menus inside of an a4j:repeat. The values for the second drop down are dependent on the value selected in the first. Below is the code I am attempting to use, but it passes a blank parameter:
<a4j:repeat id="localRepeat" var="local" value="#{InstanceController.instance.locations}" rowKeyVar="row">
<h:panelGrid columns="2">
<h:outputLabel value="Theater:" />
<h:selectOneMenu id="theater" converter="#{TheaterConverter}" value="#{local.theater}">
<f:selectItems id="theaters" value="#{InstanceController.allTheaters}" />
<a4j:support event="onchange" action="#{InstanceController.getAllCountriesInTheater}" reRender="country" >
<f:param name="theater" value="#{local.theater.id}"/>
</a4j:support>
</h:selectOneMenu>
<h:outputLabel value="Country:" />
<h:selectOneMenu immediate="true" id="country" converter="#{CountryConverter}" value="#{local.country}">
<f:selectItems value="#{InstanceController.allCountriesInTheater}" />
<a4j:support event="onchange" reRender="state" />
</h:selectOneMenu>
</h:panelGrid>
<rich:spacer height="10px" />
</a4j:repeat>
If I change the f:param to send "1" instead of "#{local.theater.id}" it works as expected.
Is there a way to get the selected value of the first drop down and send it as a parameter?
This reason this doesn't work is that when the f:param tag is rendered, the current value of local.theater.id is already assigned to the parameter. So the theater param will contain the id of the theater that was selected when the page was rendered - probably null because no theater has been selected yet.
What you are trying to do is far more easy:
Just remove the f:param and use the property directly. When the a4j:support tag triggers because the selectbox value was changed, jsf will validate your form tags and assign the appropriate model values. So, when the getAllCountriesInTheater action gets executed, the local.theater property will already contain the selected theater.
Depending on how your backing beans are designed, you will probably need a parameter to identify the location for which the selectbox was changed, so the getAllCountriesInTheater action will know in which of the locations to look for the selected theater.

Resources