I am migrating application from JSF1.2/MyFaces+Facelets TO JSF2.1/MyFaces. I have following template which used to work with JSF1.2/MyFaces+Facelets.
<ui:component>
<f:subview id="#{id}">
.
.
<script
function blockLinkClicks(){
//Disables all the HyperLink Controls to prevent repeated submits
var allLinks = document.getElementById("#{id}:treeNodeForm").getElementsByTagName('a');
var count = allLinks.length;
.
.
</script>
.
.
.
<h:form id="treeNodeForm">
<h:panelGroup id="treePanelId">
<t:tree2 id="tree2Id"
value="#{treeBean.treeModel}" var="node" varNodeToggler="t"
binding="#{treeBean.component}" clientSideToggle="false" showNav="false">
<f:facet name="selectableNode">
<h:panelGrid id="tree2PGridSelNodeId" columns="3" cellpadding="0" cellspacing="0" border="0">
.
.
.
After migration, I am getting the following error:
java.lang.IllegalStateException: component with duplicate id "mainLeftTree:treeNodeForm:tree2Id:tree2PGridSelNodeId" found
at org.apache.myfaces.view.facelets.compiler.CheckDuplicateIdFaceletUtils.checkIds(CheckDuplicateIdFaceletUtils.java:100)
at org.apache.myfaces.view.facelets.compiler.CheckDuplicateIdFaceletUtils.checkIds(CheckDuplicateIdFaceletUtils.java:116)
I have found similar questions here in SO but I was not able to relate the solutions, with my above issue. I have tried to find solution for many days/hours but could not.
Please help with your advice and pointers that I can try for a fix, as I am not sure if the issue is with f:subview or t:tree2 or jsf2 facelets.
Thank you very much in advance.
Regards,
Kumar.
I think the problem is caused by the use of <f:subview id="#{id}>", which obviously will break when PSS is enabled, because the EL is evaluated each time the view is built. Try first setting the web config parameter javax.faces.PARTIAL_STATE_SAVING to false. Or you can use the config parameter javax.faces.FULL_STATE_SAVING_VIEW_IDS to indicate which views needs full state saving. Maybe it is a good idea to avoid the EL in the id, and use other strategy in that part, but that could require some changes in the logic.
Related
I have tried setting the required attribute as follows in my input text:
required="#{ param['form:save'] == null}"
but the validation for required attribute are still being run .
I saw a few blogs where f:params are being used but the same cannot be set on the af:button. What other approach can be used here?
My save button code is:
<af:button actionListener="#{invokeActionBean.setAction}" id="save" textAndAccessKey="Save" styleClass="secondary-button" action="#{invokeActionBean.action}" partialSubmit="false" rendered="#{actionAvailable.updateAvailable}">
<f:attribute name="ACTION_MENU_ITEM" value="bindings.update" />
</af:button>
You set the immediate property of the button to true.
<af:button ... immediate="true"/>
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.
Although I have found a few questions related to this, none has quite addressed my specific situation. I have a PHP script that I want to call other scripts, without clicking. I have used this structure with success:
<body onload="form1.submit()">
<?php
.
.
.
if ($value=="yes"){
print<<<HERE
<form method="post" id="form1" action="nextapp.php">
<input="hidden" name="data" value="some data">
</form>
HERE
}
else
.
.
.
The above works perfectly. However, what if I want to be able to react to two different forms? This does NOT work:
<body onload="form1.submit(); form2.submit()">
nor does
<body onload="form1.submit()" onload="form2.submit()">
There were a few other weirder variations I tried that, not surprisingly (due to being so weird), didn't work.
Any ideas would be greatly appreciated!
I have a template and in its Definition I use several forms and buttons.
The problem is the definition (define) xhtml file does not know the component hierarchy.
And for example I want to update the element "table2" in a different form in the same define file.
Template Insert:
<p:tabView id="nav"> <!-- nav -->
<ui:insert name="content_nav">content navigation</ui:insert>
</p:tabView>
defines the first level of my hierarchy "nav"
Template define:
<ui:define name="content_nav">
<h:form id="form1"> <!-- nav:form1 -->
<h:dataTable id="table1"/> <!-- nav:form1:table1 -->
<p:inputText value="#{bean.value}"/>
<p:commandButton action="..." update="nav:form2:table2"/>
</h:form>
<h:form id="form2">
<h:dataTable id="table2"/> <!-- nav:form2:table2 -->
<!-- other elements -->
</h:form>
</ui:define>
In my define part I don't want to know "nav"!
How can I do this? or how can I move one naming component upwards?, or save the highest parent complete id in a variable?
sometimes i saw something like:
update=":table2"
But I could not find any informations about this?, the JavaEE 6 documentation just mentions the # keywords.
Ugly, but this should work out for you:
<p:commandButton action="..." update=":#{component.namingContainer.parent.namingContainer.clientId}:form2:table2" />
As you're already using PrimeFaces, an alternative is to use #{p:component(componentId)}, this helper function scans the entire view root for a component with the given ID and then returns its client ID:
<p:commandButton action="..." update=":#{p:component('table2')}" />
ugly answer works well
update=":#{component.namingContainer.parent.namingContainer.clientId}:form2:table2
mainly more useful updating from opened dialog to parent datatable
You may use binding attribute to declare EL variable bound to JSF component. Then you may access absolute client id of this component by using javax.faces.component.UIComponent.getClientId(). See example below:
<t:selectOneRadio
id="yourId"
layout="spread"
value="#{yourBean.value}"
binding="#{yourIdComponent}">
<f:selectItems value="#{someBean.values}" />
</t:selectOneRadio>
<h:outputText>
<t:radio for=":#{yourIdComponent.clientId}" index="0" />
</h:outputText>
Try this:
<h:commandButton value="Click me">
<f:ajax event="click" render="table" />
</h:commandButton>
Additionally to the solutions above I had the problem, that I had to dynamically generate the to-be-updated components (many) based on server-side logic (with maybe harder to find out nesting).
So the solution on the server-side is an equivalent to update=":#{p:component('table2')}"1 which uses org.primefaces.util.ComponentUtils.findComponentClientId( String designId ):
// UiPnlSubId is an enum containing all the ids used within the webapp xhtml.
// It could easily be substituted by a string list or similar.
public static String getCompListSpaced( List< UiPnlSubId > compIds ) {
if ( compIds == null || compIds.isEmpty() )
return "" ;
StringBuffer sb = new StringBuffer( ":" ) ;
for ( UiPnlSubId cid : compIds )
sb.append( ComponentUtils.findComponentClientId( cid.name() ) ).append( " " ) ;
return sb.deleteCharAt( sb.length() - 1 ).toString() ; // delete suffixed space
}
called via some other method using it, e.g. like ... update="#{foo.getCompListComputed( 'triggeringCompId' )}".
1: first I tried without too much thinking to return public static String getCompListSpaced0() { return ":#{p:component('table2')}" ; } in an ... update="#{foo.getCompListSpaced0()} expression, which of course (after thinking about how the framework works :) ) is not resolved (returned as is) and may cause the issues with it some users experienced. Also my Eclipse / JBoss Tools environment suggested to write :#{p.component('table2')} ("." instead of ":") which did not help - of course.
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.