I have a loop for constructing 12 input fields:
<h:panelGroup id="panel">
<c:forEach id="iter" items="#{of:createIntegerArray(0,12)}" var="dVar" varStatus="dLoop">
<h:inputText id="input#{dLoop.index}" value="#{doc['input'+=dLoop.index]}" process="#form:panel" update="#form:panel" />
</c:forEach>
<o:validateMultiple id="validateFields" components="#{controller.componentsString}" validator="#{dValidator}" />
</h:panelGroup>
This works ok, until I put a standard validator on the input field. Then the #{dValidator} is not triggered.
So this is not triggering the validator in o:validateMultiple:
<h:panelGroup id="panel">
<c:forEach id="iter" items="#{of:createIntegerArray(0,12)}" var="dVar" varStatus="dLoop">
<h:inputText id="input#{dLoop.index}" value="#{doc['input'+=dLoop.index]}" process="#form:panel" update="#form:panel">
<o:validator validatorId="javax.faces.Length" minimum="5" />
</h:inputText>
</c:forEach>
<o:validateMultiple id="validateFields" components="#{controller.componentsString}" validator="#{dValidator}" />
</h:panelGroup>
Is this a bug in the library? Is there a workaround?
Thanks.
Related
I have a collection of items which each have a min, likely, and max value. There are validators to ensure the maximum is greater than the minimum etc. The validators use bindings so they can compare all three values the user has entered. Originally they were in a ui:repeat, but that was causing trouble with a dropdown and I found switching to a c:forEach fixed it. Unfortunately, it's also messed up the bindings. I'm hoping there's a way to fix them without going back to the ui:repeat.
Is it possible to have a binding in a c:forEach? Is there some way to add an id or a varStatus index to the binding so it isn't the same for every item in the list? e.g. in the example below I've tried things like
<h:inputText id="impactMin_#{impact.id}" binding="#{impactMin_#{impact.id}}">
<h:inputText id="impactMin_#{impact.id}" binding="#{impactMin}_#{impact.id}">
but unsurprisingly, those don't work. If anyone knows a sensible way of doing this, I'd be very grateful to hear it.
This is a simplified version of the code:
<c:forEach id="impacts" var="impact" items="#{mybean.impacts}" varStatus="i">
<h:panelGroup layout="block" id="impactContainer_#{impact.id}">
<h:outputText value="#{impact.score_impact_type_idInterface.score_impact_type_name}"/>
<h:panelGroup layout="block" class="row form-group" id="impactAssessment_#{impact.id}">
<h:panelGroup layout="block">
<h:inputText id="impactMin" value="#{impact.current_impact_min}" binding="#{impactMin}" label="Minimum">
<f:attribute name="impactMl" value="#{impactMl}"/>
<f:attribute name="impactMax" value="#{impactMax}"/>
<f:convertNumber locale="#{loginInfo.realLocale}" minIntegerDigits="1" maxFractionDigits="2" />
<f:validator binding="#{impactMinValidator}"/>
</h:inputText>
</h:panelGroup>
<h:panelGroup layout="block">
<h:inputText id="impactMl" value="#{impact.current_impact_ml}" binding="#{impactMl}" label="Most likely">
<f:attribute name="impactMin" value="#{impactMin}"/>
<f:attribute name="impactMax" value="#{impactMax}"/>
<f:convertNumber locale="#{loginInfo.realLocale}" minIntegerDigits="1" maxFractionDigits="2" />
<f:validator binding="#{impactLikelyValidator}"/>
</h:inputText>
</h:panelGroup>
<h:panelGroup layout="block">
<h:inputText id="impactMax" value="#{impact.current_impact_max}" binding="#{impactMax}" label="Maximum">
<f:attribute name="impactMin" value="#{impactMin}"/>
<f:attribute name="impactMl" value="#{impactMl}"/>
<f:convertNumber locale="#{loginInfo.realLocale}" minIntegerDigits="1" maxFractionDigits="2" />
<f:validator binding="#{impactMaxValidator}"/>
</h:inputText>
</h:panelGroup>
<div class="col-sm-12">
<h:message for="impactMin"/>
<h:message for="impactMl"/>
<h:message for="impactMax"/>
</div>
</h:panelGroup>
</h:panelGroup>
</c:forEach>
While trying to get a better understanding of bindings in general, I found this answer JSF 2 composites and binding for validation . While not quite the same thing, I found it could be adapted to a c:forEach like this:
<c:forEach id="impacts" var="impact" items="#{mybean.impacts}" varStatus="i">
<h:panelGroup layout="block" id="impactContainer_#{impact.id}">
<h:outputText value="#{impact.score_impact_type_idInterface.score_impact_type_name}"/>
<h:panelGroup layout="block" class="row form-group" id="impactAssessment_#{impact.id}">
<ui:param name="impactMin" value="impactMin_#{impact.id}" />
<ui:param name="impactMl" value="impactMl_#{impact.id}" />
<ui:param name="impactMax" value="impactMax_#{impact.id}" />
<h:panelGroup layout="block">
<h:inputText id="impactMin_#{impact.id}" value="#{impact.current_impact_min}" binding="#{requestScope[impactMin]}" label="Minimum">
<f:attribute name="impactMl" value="#{requestScope[impactMl]}"/>
<f:attribute name="impactMax" value="#{requestScope[impactMax]}"/>
<f:convertNumber locale="#{loginInfo.realLocale}" minIntegerDigits="1" maxFractionDigits="2" />
<f:validator binding="#{impactMinValidator}"/>
</h:inputText>
</h:panelGroup>
<h:panelGroup layout="block">
<h:inputText id="impactMl_#{impact.id}" value="#{impact.current_impact_ml}" binding="#{requestScope[impactMl]}" label="Most likely">
<f:attribute name="impactMin" value="#{requestScope[impactMin]}"/>
<f:attribute name="impactMax" value="#{requestScope[impactMax]}"/>
<f:convertNumber locale="#{loginInfo.realLocale}" minIntegerDigits="1" maxFractionDigits="2" />
<f:validator binding="#{impactLikelyValidator}"/>
</h:inputText>
</h:panelGroup>
<h:panelGroup layout="block">
<h:inputText id="impactMax_#{impact.id}" value="#{impact.current_impact_max}" binding="#{requestScope[impactMax]}" label="Maximum">
<f:attribute name="impactMin" value="#{requestScope[impactMin]}"/>
<f:attribute name="impactMl" value="#{requestScope[impactMl]}"/>
<f:convertNumber locale="#{loginInfo.realLocale}" minIntegerDigits="1" maxFractionDigits="2" />
<f:validator binding="#{impactMaxValidator}"/>
</h:inputText>
</h:panelGroup>
<div class="col-sm-12">
<h:message for="impactMin_#{impact.id}"/>
<h:message for="impactMl_#{impact.id}"/>
<h:message for="impactMax_#{impact.id}"/>
</div>
</h:panelGroup>
</h:panelGroup>
</c:forEach>
Note the ui:param bits near the top. That seems to do the trick. Thanks BalusC!
I've got a JSF page with <rich:tabPanel> which contains 4 tabs.
On the 4th tab I'm trying to use <a4j:commandButton> to execute the action and render resulTable.
Here is the shorten example
<rich:tab header="Journal">
<h:form id="filterForm">
<a4j:jsFunction name="submitByEnter"
action="#{smsLogList.refresh}" render="smsTable" />
<s:div id="divSearch">
<rich:collapsiblePanel header="#{messages['search']}"
switchType="client">
<h:panelGrid column="1">
<s:decorate template="/layout/edit.xhtml">
<ui:define name="label">Package number</ui:define>
<h:inputText id="packNum" style="width:200px"
value="#{smsLogList.packNum}">
<a4j:ajax event="keyup" listener="#{smsLogList.refresh}"
ignoreDupResponses="true" requestDelay="1500"
render="smsTable" />
</h:inputText>
</s:decorate>
<!---some other search elements-->
<s:div styleClass="actionButtons">
<a4j:commandButton id="search" value="#{messages['search']}"
render="smsTable" action="#{smsLogList.go}" />
<a4j:commandButton id="reset" value="#{messages['clear']}"
onclick="document.getElementById('filterForm').reset();"
action="#{smsLogList.clear}" render="divSearch,smsTable" />
</s:div>
</h:panelGrid>
</rich:collapsiblePanel>
</s:div>
<!--- results table-->
<h:panelGrid id="smsTable">
<s:div>
<rich:dataTable value="#{smsLogList.resultList}" var="sms"
id="table" rendered="#{not empty smsLogList.resultList}">
<rich:column>
<f:facet name="header">Type</f:facet>
<h:outputText value="#{sms.smsType}" />
</rich:column>
<!---- some other columns-->
</rich:dataTable>
<rich:dataScroller for="table" />
</s:div>
</h:panelGrid>
</h:form>
</rich:tab>
So, when I'm clicking on the <a4j:commandButton> - nothing happens, but if I'm switching to the other tab and back - the result is as necessary.
I tried to change a4j to <h:commandButton>, but after it's pressed the page switches to the first tab.
Is any solution how to work this out?
The solution is quite simple.
I used <h:form> inside other <h:form>. It will not work anyway. When I remove internal - the jsf works smooth and as it should.
i want to inplace edit a autoComplete text field:
<h:panelGroup>
<ui:repeat value="#{cc.attrs.relations}" var="ur">
<p:panel headerText="Relation">
<p:inplace editor="true" >
<!-- <p:inputText value="#{ur.relation.name}"
required="true" label="text"/>-->
<p:autoComplete
value="myval"
/>
</p:inplace>
</p:panel>
</ui:repeat>
</h:panelGroup>
However, this does not work (autocomplete is not shown.).
Do you know how to accomplish this?
The reason autocomplete is not shown is that inplace does not get its label as with i.e. inputText.
adding label="TheLabel" solves the problem.
<h:panelGroup>
<ui:repeat value="#{cc.attrs.relations}" var="ur">
<p:panel headerText="Relation">
<p:inplace editor="true" label="TheLabel">
<!-- <p:inputText value="#{ur.relation.name}"
required="true" label="text"/>-->
<p:autoComplete
value="myval"
/>
</p:inplace>
</p:panel>
</ui:repeat>
</h:panelGroup>
I have the following in a JSF 2.0 page:
<rich:column styleClass="tbl-weight" id="weight">
<f:facet name="header">
<h:outputText value="Weight" />
</f:facet>
<h:outputLabel value="lbs" for="lbs" />
<h:inputText size="3" id="lbs" label="lbs"
validatorMessage="Lbs must be from 0 to 999"
value="#{weighFamilyBacking.weightDecoratorMap[child].lbs}">
<f:validateLongRange minimum="0" maximum="999" />
<f:ajax event="change" render="#form" immediate="true"/>
</h:inputText>
<h:outputLabel value="oz" for="oz" />
<h:inputText size="3" id="oz" label="oz"
validatorMessage="Oz must be from 1 to 15"
value="#{weighFamilyBacking.weightDecoratorMap[child].oz}">
<f:validateLongRange minimum="0" maximum="15" />
<f:ajax event="change" render="currentPayoutOutput" />
</h:inputText>
<h:message styleClass="error" for="lbs" />
<h:message styleClass="error" for="oz" />
</rich:column>
<rich:column styleClass="tbl-payout" id="currentPayout">
<f:facet name="header">
<h:outputText id="payout" value="Payout" />
</f:facet>
<h:outputText id="currentPayoutOutput"
value="#{weighFamilyBacking.weightDecoratorMap[child].payout}" />
</rich:column>
When looking at this the f:ajax on the "lbs" and "oz" inputs should update set their values and then cause the currentPayoutOutput to render. This works fine only on the first change to the input field.
This is the same results if I use #form or if I use the currentPayoutOutput. Using a phase listener I see it jump from processValidations right to renderResponse. None of the validator messages are showing up.
The problem ended up being the following:
<f:metadata>
<f:viewParam name="familyId" value="#{weighFamilyBacking.familyId}" required="true"></f:viewParam>
<f:event type="preRenderView"
listener="#{weighFamilyBacking.loadFamily}" />
</f:metadata>
This page takes a familyId as a parameter and it was specified as required. Once I removed this things worked as expected. I assume that since the parameter was there initially it worked the first time. Then on subsequent posts the familyId parameter was no longer there (since it wasn't a hidden form field) and therefor I was jumping from validation right to render phase since the validation of the required "viewParam" was failing.
I have bean struggling to understand how to use the rich:popupPanel component in the right way. There are (at least not that I could find) few post about how to use the rich:popupPanel and how to submit values from it.
To make matter worse the panel seams to add (when checking the html) a hard coded "_content" to its component id name (to the div generated). I have tried to use aj4:region tag to partial render the complete form. But that didn't seamed to work, cause nothing where posted to managed bean. So now I have one option left, where the panel has its own form, outside the main one on the page.
I can see that the evaluation of the form (popup) values is happening, but not the execution of the bean function that persist the values (I see the POST request of the command button). The only reason I can think of at the moment, is that the pop-up panel use another bean to persist the values that the main form on the page (both of them are session scoped).
I am thinking of omit the pop-up panel all together, since it seams so hard to make this work. Maybe its a well know secret, since it so few post about it. It behaves the same if if use componentController or only a a4j:commanLink.
How is it possible to submit values from a rich:popupPanel and invoke a backing bean function to persist the pop-up form values ?
Appreciate if someone can shed some light on this, greetings Chris.
I use Richfaces 4.0-final on Glassfish 3.1
<h:form id="main_form">
<!-- Command for popup -->
<a4j:commandLink actionListener="#{userController.prepareCreateSysRequest}" oncomplete="#{rich:component('popup_sys_user_req_form:popup_sys_user_req')}.show(); return false;"
execute="#this" value="Request New Sector/Category" />
...
<a4j:commandButton action="#{projectController.Create}" ...>
</h:form>
<h:form id="popup_sys_user_req_form">
<rich:popupPanel id="popup_sys_user_req" modal="true" autosized="true" resizeable="false">
<f:facet name="header">
<h:outputText value="New Project Request" />
</f:facet>
<f:facet name="controls">
<h:outputLink value="#"
onclick="#{rich:component('popup_sys_user_req')}.hide(); return false;">
X
</h:outputLink>
</f:facet>
<h:panelGrid columns="2">
<h:outputLabel value="Request New:" />
<h:selectOneMenu id="sys_req_type" value="#{userController.selectedSysRequestType}" required="true" requiredMessage="Request Type is required" title="Request Type">
<f:selectItems value="#{userController.getSysRequestTypeItems()}">
</f:selectItems>
</h:selectOneMenu>
<h:outputLabel value="Description:" />
<h:inputTextarea id="user_req_desc" value="#{userController.selectedSysUserRequest.description}" required="true" requiredMessage="Decription is missing" />
</h:panelGrid>
<a4j:commandButton action="#{userController.CreateSysUserRequest}" onclick="#{rich:component('popup_sys_user_req')}.hide(); return false;" execute="#form" render="popup_sys_user_req_form" value="Send Request" />
</rich:popupPanel>
</h:form>
For what I have done I used to have the issue to got to submit twice only the first time.
To fix it the form got to be outside the popupPane. And also that the popupPanel should have the attibute domElementAttachment="form".
Example.
<h:form>
<rich:popupPanel id="shipmentItemUpdateDialog"
autosized="true"
domElementAttachment="form">
<f:facet name="header">
<h:panelGroup>
<h:outputText value="#{shipmentBundle.shipmentItemDetailsHeader}" />
</h:panelGroup>
</f:facet>
<f:facet name="controls">
<h:commandLink>
<h:graphicImage value="/core/images/modal/close.png"/>
<rich:componentControl target="shipmentItemUpdateDialog" operation="hide" />
</h:commandLink>
</f:facet>
<h:outputText for="shipmentItemName"
value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemName}"
/>
<h:inputText id="shipmentItemName"
disabled ="false"
required ="true"
value="#{shipmentItemController.shipmentItemUI.value.name}"
label="#{shipmentBundle.shipmentItemName}"
size="40" >
</h:inputText>
<h:outputText for="shipmentItemCode"
value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemCode}"
/>
<h:inputText id="shipmentItemCode"
disabled ="false"
required ="true"
value="#{shipmentItemController.shipmentItemUI.value.code}"
label="#{shipmentBundle.shipmentItemCode}"
size="40" >
</h:inputText>
<h:outputText value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemAmount}"
/>
<h:inputText id="shipmentItemAmount"
disabled ="false"
required ="true"
value="#{shipmentItemController.shipmentItemUI.value.amount}"
label="#{shipmentBundle.shipmentItemAmount}"
size="4" >
<f:validateLongRange minimum="1"/>
</h:inputText>
<h:outputText value="#{coreBundle.requiredChar} #{shipmentBundle.shipmentItemNeedsCooling}"
/>
<h:selectBooleanCheckbox id="shipmentItemNeedsCooling"
disabled ="false"
required ="true"
value="#{shipmentItemController.shipmentItemUI.value.needsCooling}"
label="#{shipmentBundle.shipmentItemNeedsCooling}"
/>
<h:outputText for="shipmentItemDetails"
value="#{shipmentBundle.shipmentItemDetails}"
/>
<h:inputTextarea id="shipmentItemDetails"
disabled ="false"
required ="true"
value="#{shipmentItemController.shipmentItemUI.value.details}"
label="#{shipmentBundle.shipmentItemDetails}"
cols="38"
rows="5"
/>
</h:panelGrid>
<h:panelGrid columns="1" dir="LTR">
<h:panelGrid columns="2" dir="LTR">
<a4j:commandButton value="#{coreBundle.acceptButton}"
action="#{shipmentItemController.onUpdate()}"
render="shipmentItemsTable">
</a4j:commandButton>
<h:commandLink value="#{coreBundle.closeLink}"
immediate="true">
<rich:componentControl target="shipmentItemUpdateDialog" operation="hide" />
</h:commandLink>
</h:panelGrid>
<h:outputText value="#{coreBundle.requiredText}"/>
</h:panelGrid>
</rich:popupPanel>
</h:form>
I hope this helps.
I think you got it right.. think of the pop-up as a regular page. To submit and close the pop-up, do something like this:
<a4j:commandButton value="Save" onclick="#{rich:component('panelId}.hide();" render="..."/>
Hope this helps..