我正在尝试使用 Facelet 标记文件和 @Balusc 在如何制作 JSF 复合组件网格?作为参考。我已经复制了 /WEB-INF/tags/input.xhtml 和 example.taglib.xml 以及主应用程序 xhtml。但是,我遇到了一些问题。
1.如果我不传递 id 而只是做
<my:input id="cat" type="text" label="FirstName" bean="#{bean}" property="fName" required="true" />
<my:input id="dog" type="text" label="LastName" bean="#{bean}" property="lName" required="true />
在我的主 xhtml 并打开该页面,我得到 java.lang.IllegalArgumentException 和异常跟踪:
java.lang.IllegalArgumentException
at javax.faces.component.UIComponentBase.validateId(UIComponentBase.java:543)
at javax.faces.component.UIComponentBase.setId(UIComponentBase.java:351)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:151)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.ui.CompositionHandler.apply(CompositionHandler.java:119)
at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:248)
at com.sun.facelets.impl.DefaultFacelet.include(DefaultFacelet.java:294)
at com.sun.facelets.impl.DefaultFaceletContext.includeFacelet(DefaultFaceletContext.java:268)
at com.sun.facelets.tag.UserTagHandler.apply(UserTagHandler.java:98)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
at com.sun.facelets.tag.jsf.ComponentHandler.applyNextHandler(ComponentHandler.java:314)
at com.sun.facelets.tag.jsf.ComponentHandler.apply(ComponentHandler.java:169)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.compiler.NamespaceHandler.apply(NamespaceHandler.java:49)
at com.sun.facelets.tag.CompositeFaceletHandler.apply(CompositeFaceletHandler.java:47)
at com.sun.facelets.compiler.EncodingHandler.apply(EncodingHandler.java:25)
at com.sun.facelets.impl.DefaultFacelet.apply(DefaultFacelet.java:95)
at com.sun.facelets.FaceletViewHandler.buildView(FaceletViewHandler.java:524)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:567)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
2.为了克服这个问题,当我在我的标签中传递 id 值时
<my:input id="cat" type="text" label="FirstName" bean="#{bean}" property="fName" required="true" />
<my:input id="dog" type="text" label="LastName" bean="#{bean}" property="lName" required="true />
我得到一个组件 j_id2:cat 错误的重复 ID。
java.lang.IllegalStateException: duplicate Id for a component j_id2:cat
at org.ajax4jsf.application.TreeStructureNode.apply(TreeStructureNode.java:68)
at org.ajax4jsf.application.TreeStructureNode.apply(TreeStructureNode.java:92)
at org.ajax4jsf.application.TreeStructureNode.apply(TreeStructureNode.java:92)
at org.ajax4jsf.application.TreeStructureNode.apply(TreeStructureNode.java:92)
at org.ajax4jsf.application.AjaxStateManager.getTreeStructureToSave(AjaxStateManager.java:187)
at org.ajax4jsf.application.AjaxStateManager.buildViewState(AjaxStateManager.java:498)
at org.ajax4jsf.application.AjaxStateManager.saveSerializedView(AjaxStateManager.java:451)
at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:615)
at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
3.为了解决这个问题,我删除了所有 c:when 并在 input.xhtml 中保留了一种输入类型的“文本”,现在我看到呈现了 2 个文本框,但是当我查看源代码时,我看到了
<tr>
<td>
<c:set var="id" value="cat"></c:set>
<c:set var="required" value="true"></c:set>
</td>
<td><label for="j_id2:cat">First Name: * </label></td>
<td><input id="j_id2:cat" type="text" name="j_id2:cat" value="Smith" /></td>
</tr>
<tr>
<td></td>
<td>
<c:set var="id" value="dog"></c:set>
<c:set var="required" value="true"></c:set>
</td>
<td><label for="j_id2:dog">Last Name: * </label></td>
</tr>
<tr>
<td><input id="j_id2:dog" type="text" name="j_id2:dog" value="Joe" /></td>
<td></td>
</tr>
我期待 2 行,但看到 3 行。我也不期待标记文件中的 c:set 定义成为我的 td 视图的一部分。
任何指针将不胜感激。