JSF 2.0 Warning about a component not surronded by an h:form tag [duplicate] - jsf-2

I am getting the following error on my Facelet page, which simply consists of an IceFaces form with two fields and two buttons:
The form component needs to have a UIForm in its ancestry. Suggestion: enclose the necessary components within <h:form>
Here is the form:
<ice:form id="form1" partialSubmit="false">
<ice:panelLayout id="panelLayout3">
<ice:graphicImage id="graphicImage1" url="/resources/images/LoginImage.jpg" width="560" />
<ice:outputLabel for="j_username" id="outputLabel1" value="Username:"/>
<ice:outputLabel for="j_password" id="outputLabel2" value="Password:"/>
<ice:inputText binding="#{login.username}" id="j_username" required="true" />
<ice:inputSecret binding="#{login.password}" id="j_password" required="true" />
<ice:commandButton actionListener="#{login.login}" id="loginBtn" value="Login"/>
<ice:commandButton action="#{login.reset}" id="resetBtn" value="Reset"/>
<ice:outputText id="errorMessage" />
<ice:message errorClass="errorMessage" for="j_username" fatalClass="fatalMessage" id="messages1" infoClass="infoMessage" showSummary="false" warnClass="warnMessage"/>
</ice:panelLayout>
</ice:form>
How is this caused and how can I solve it?

This is not an error. This is a warning. The code looks fine, all input components are inside a form, it seems that it should run and work fine. If it indeed works fine, just ignore the warning. This warning is displayed only when the context parameter javax.faces.PROJECT_STAGE is set to Development anyway .
As to the false warning message itself, this check was introduced in Mojarra 2.1.1 as per issue 1663. However, as per issue 2147 it turns out to have some bugs and is been further improved in Mojarra 2.1.3. I'd imagine that the false warning is in your particular case caused by having an <ice:panelLayout> between the form and the input elements.
If you aren't on Mojarra 2.1.3 yet, you may want to consider upgrading to see if it removes the false warning message.

Related

prime faces ajax not working

We have a JSF project with the following versions of JARs:
Prime Faces 5.1
JSF 2.0
Javaee-api 5
But the Project Facets(in eclipse) defines JSF 2.2, we never changed it.
JPA 2 ( javaee-api 5)
Ejb 3.0
Our ajax is not working.
<p:selectOneRadio id="enrolledInPlanFlag" value="#{phInfoBean.enrldPlanFlag}" label="Action" >
<f:selectItem itemLabel="Yes" itemValue="Yes" />
<f:selectItem itemLabel="No" itemValue="No" />
<p:ajax process="enrolledInPlanFlag" update="#form"/>
</p:selectOneRadio>
<p:dialog id="dialog" header="APTC Warning" widgetVar="dlg1" modal="true" height="200" width="500" resizable="false" rendered="#{phInfoBean.enrldPlanFlag eq 'Yes'}">
I am trying to display dialog based on the selectOneRadio. But the AJAX is not working and we have the wierd situation where sometimes it works and sometimes it not.
We have annotated managed bean with #ViewScoped.
Please help.
Make it work
You never show your dialog in your code. You could attach an oncomplete event to your p:ajax
<p:ajax process="enrolledInPlanFlag" update="#form" oncomplete="PF('dlg1') != null ? PF('dlg1').show() : ''" />
The condition PF('dlg1') != null is required as if you choose "No" your dialog is no longer rendered in your page, therefore PF('widgetVarOfDialog') is unreachable.
Additional notes
I would improve this code by:
Changing enrldPlanFlag to a boolean instead of a string (cleaner IMO)
Display the dialog programatically in an listener (called from your p:ajax) if the boolean is true
Why? To leave the logic in your bean instead of your .xhtml page

client side validation and tooltip

I have jsf validation on form where the invalid fields are highlighted based on
styleClass="#{component.valid ? 'reportInput' : 'reportInput_invalid'}"
and a tooltip is being used for displaying the error message as follows
<p:tooltip for="inputFieldId">
<p:message for="inputFieldId" />
</p:tooltip>
Everything works as expected but i want to improve user experience and want to introduce pure client side validation using
<p:clientValidator />
I tried this but it didnt work when onBlur event is fired on inputfield i got the following JS error
'null' is Null or no Object
in validation.js.jsf and the line code is
d.data("uiMessageId",b.attr("id"))
Is it possible to achieve?
An example of my input field is:
<p:inputText id="bic"
styleClass="#{component.valid ? 'reportInput' : 'reportInput_invalid'}"
value="#{bean.bic}"
required="true" requiredMessage="Field value is required" >
<p:watermark for="bic" value="CMHJKLIL" />
<pe:keyFilter regEx="/[a-z0-9]/i" />
<f:validateLength minimum="8" />
<p:clientValidator/>
</p:inputText>
I am using Primefaces 4 with the following maven dependency
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>4.0</version>
</dependency>
Here as it looks in jsf page head section
Here is the validation.js file that is being used
validatuion.js here
i had the exact same error.
it seems that the validator.js code searches for a message container attached to the field, and, if cant find one, it searches one in the nearest form "e.findUIMessage(a,d.closest("form").find("div.ui-message"))"
what you need is to have an tag,
that is, a message assigned for the inputtext, so, when the validator generates an error, it can post the text in that message container.

How to invoke a JSF composite within composite:implementation?

How could you invoke a JSF2 composite (widget) within anothers composite's implementation tag?
When I do so, I get the following error: /resources/widgets/tileContainer.xhtml #25,45 <mywidgets:tileContainer> Tag Library supports namespace: http://java.sun.com/jsf/composite/widgets, but no tag was defined for name: tileContainer
The code snippet is:
<composite:interface name="tileContainer">
<composite:attribute name="pubCategoryId" type="java.lang.Long" required="true" />
</composite:interface>
<composite:implementation>
<div class="tileContainer">
<ui:repeat value="#{pubController.getPubsByCategory(cc.attrs.pubCategoryId)}" var="pub">
#{pub.title}
<mywidgets:tileContainer title="Private">
<mywidgets:tileSmallPictureTitle
title="Bulk Dispatch Lapse stressed with application protocols">
</mywidgets:tileSmallPictureTitle>
</mywidgets:tileContainer>
</ui:repeat>
</div>
</composite:implementation>
Any other design recommendations on how to handle this?
Thank you for sharing your thoughts.
This is recognizable as Mojarra issue 2437 which was fixed in Mojarra 2.1.10 (released 25 july 2012). It look like you're using a rather outdated Mojarra version. It's currently already at 2.1.25 (2.2.x is even already out, but I wouldn't recommend switching to 2.2 right now, let them fix all childhood diseases first).
Okay, I moved the namespace declaration of my composite directory from the <html xmlns... tag down to the <composite:implementation> tag.
So the composite looks like this:
<composite:implementation xmlns:mywidgets="http://java.sun.com/jsf/composite/widgets">
Otherwise, the namespaces of the parent and child composite will resolve wrongly.

Composite component parameter does not evaluate when it is a ui:repeat var attribute

I have a composite component that takes a specific object type as its value attribute. It looks like this:
<cc:interface>
<cc:attribute name="value"
type="com.myapp.Tally"
required="true"
</cc:interface>
The component merely produces a h:panelGrid with data elements from the object.
I have never had trouble with it until I tried using it inside a ui:repeat structure like this:
<ui:repeat value="#{myApp.tallyList}" var="tally">
<p>
<qc:tallySummaryH value="#{tally}" />
</p>
</ui:repeat>
When this page is requested, it throws an exception:
javax.faces.view.facelets.TagException: /table.xhtml #86,66 <qc:tallySummaryH> The following attribute(s) are required, but no values have been supplied for them: value.
at com.sun.faces.facelets.tag.composite.InterfaceHandler.validateComponent(InterfaceHandler.java:233)
at com.sun.faces.facelets.tag.composite.InterfaceHandler.apply(InterfaceHandler.java:125)
at javax.faces.view.facelets.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:98)
at com.sun.faces.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:93)
at com.sun.faces.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:86)
at com.sun.faces.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:152)
at com.sun.faces.facelets.tag.jsf.CompositeComponentTagHandler.applyCompositeComponent(CompositeComponentTagHandler.java:349)
Other references to #{tally} inside the ui:repeat loop do not have any problem. They operate as expected. Is this a Mojarra bug or is there something in the JSF specification I didn't understand?
This is on Mojarra 2.1.0 (FCS 2.1.0-b11) in GlassFish 3.1.1
This is related to a bug which was fixed in Mojarra 2.1.1. Consider upgrading. I believe it's (in)directly the result of the visit hint fixes as mentioned in this overview of issues fixed in Mojarra 2.1.1.

Why does my s:selectItems throws no such element exception?

I'm getting this error java.util.NoSuchElementException when i tried to check one of my checkbox under h:selectManycheckBox when i submit the form.
The many checkbox is dynamically populated from the bean. Here is my code.
<h:form id="eF">
<h:inputText id="i" value="#{aklat.suggest}">
<a4j:support event="onkeyup" action="#{aklat.complete}" reRender="m"></a4j:support>
</h:inputText>
<s:div>
<h:selectManyCheckbox value="#{aklat.selectedBooks}" layout="pageDirection" id="m">
<s:selectItems value="#{aklat.books}" var="_book" itemLabel="#{_book}" itemValue="#{_book}" label="#{_book.bookName}"/>
</h:selectManyCheckbox>
<a4j:commandButton value="Add Users" action="#{aklat.fire}"></a4j:commandButton>
</s:div>
</h:form>
The weird part is it renders some data output but when i checked the source code. there are no input type checkbox element.
Is something I am missing.
I assume your managed bean is request scope...
because you are making an ajax request, you have to enable "aklat.books" to persist its value longer than request but shorther than session scope.
If you have tomahawk between your app libraries you can use savestate like this (put it after the h:form tag) :
<t:saveState value="#{aklat.books}"/>
if no tomahawk, you can use a4j:keepAlive:
<a4j:keepAlive beanName = "#{aklat.books}"/>

Resources