我正在尝试使用Facelet标记文件在面板网格中获取可重用的jsf 1.2组件组,其中包含@ Balusc先前在How to make a grid of JSF composite component?的答案作为参考。我复制了/WEB-INF/tags/input.xhtml和example.taglib.xml以及主应用程序xhtml。但是,我遇到了一些问题 1.如果我没有通过身份证,只需做
<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 error的重复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中保留了一个输入类型的'text',现在我看到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:在标签文件中设置定义是我的td视图的一部分。
任何指针都将受到赞赏。
答案 0 :(得分:0)
对于Facelets 1.x,您需要在以下XML命名空间中声明JSTL核心taglib:
xmlns:c="http://java.sun.com/jstl/core"
请注意,Facelets 1.x的URI中没有/jsp
。