相关疑难解决方法(0)

JSF2 Facelets中的JSTL有意义吗?

我想有条件地输出一些Facelets代码.

为此,JSTL标签似乎工作正常:

<c:if test="${lpc.verbose}">
    ...
</c:if>
Run Code Online (Sandbox Code Playgroud)

但是,我不确定这是否是最佳做法?还有另一种方法来实现我的目标吗?

jsf jstl facelets jsf-2

159
推荐指数
2
解决办法
8万
查看次数

何时使用<ui:include>,标记文件,复合组件和/或自定义组件?

我最近开始使用带有Facelets的JSF 2.0,并且对于了解<ui:include>Facelets 1.x提供的现有和其他模板技术的新复合组件感到困惑.

这些方法有什么区别?从功能上看,它们似乎提供了相同的:<ui:param>vs <cc:attribute>,<ui:insert>+ <ui:define>vs标记文件,重用现有模板.除了复合组件的语法和清晰的接口规范之外还有什么吗?性能会有所不同?

facelets tagfile custom-component composite-component jsf-2

95
推荐指数
1
解决办法
5万
查看次数

"绑定"属性如何在JSF中起作用?应该何时以及如何使用?

在JSF中有很多材料区分value属性和binding属性.

我对这两种方法如何彼此不同感兴趣.鉴于:

public class User {
    private String name;
    private UICommand link;

    // Getters and setters omitted.
}
Run Code Online (Sandbox Code Playgroud)
<h:form>
    <h:commandLink binding="#{user.link}" value="#{user.name}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)

value指定属性时会发生什么变化.getter运行以返回bean 的name属性值User.该值将打印到HTML输出.

但我无法理解它是如何binding运作的.生成的HTML如何维护与bean link属性的绑定User

下面是手动美化和注释后生成的输出的相关部分(注意id j_id_jsp_1847466274_1是自动生成的,并且有两个隐藏的输入小部件).我正在使用Sun的JSF RI 1.2版.

<form action="/TestJSF/main.jsf" enctype="application/x-www-form-urlencoded"
    id="j_id_jsp_1847466274_1" method="post"  name="j_id_jsp_1847466274_1">
    <input name="j_id_jsp_1847466274_1" type="hidden" value="j_id_jsp_1847466274_1">
    <a href="#" onclick="...">Name</a>
    <input autocomplete="off" id="javax.faces.ViewState" name="javax.faces.ViewState"
        type="hidden" value="-908991273579182886:-7278326187282654551">
</form>
Run Code Online (Sandbox Code Playgroud)

在哪里binding存放在这里?

jsf binding components jsf-2

74
推荐指数
1
解决办法
10万
查看次数

ui:decorate和ui:include之间真正的概念差异是什么?

它发生前我ui:decorate在功能一样ui:include,只是你也可以通过ui:paramui:define被包含文件.

我疯了吗?

编辑:虽然事实上你也可以传递ui:param给一个ui:include文件,但事实证明我已经在做了.也许你也可以通过ui:define,我会在这里检查和编辑.

jsf facelets

23
推荐指数
1
解决办法
3万
查看次数

如何创建动态JSF表单字段

我发现了一些像这样的类似问题,但是有很多方法可以做到这让我更加困惑.

我们正在获取XML正在阅读的文件.其中XML包含有关需要显示的某些表单字段的信息.

所以我创建了这个DynamicField.java包含我们需要的所有信息的自定义:

public class DynamicField {
  private String label; // label of the field
  private String fieldKey; // some key to identify the field
  private String fieldValue; // the value of field
  private String type; // can be input,radio,selectbox etc

  // Getters + setters.
}
Run Code Online (Sandbox Code Playgroud)

所以我们有一个List<DynamicField>.

我想迭代这个列表并填充表单字段,使它看起来像这样:

<h:dataTable value="#{dynamicFields}" var="field">
    <my:someCustomComponent value="#{field}" />
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)

然后<my:someCustomComponent>将返回相应的JSF表单组件(即label,inputText)

另一种方法是只显示<my:someCustomComponent>,然后返回一个HtmlDataTable带有表单元素.(我认为这可能更容易).

哪种方法最好?有人可以告诉我一些链接或代码,它显示我如何创建这个?我更喜欢完整的代码示例,而不是像"你需要一个子类javax.faces.component.UIComponent" 这样的答案.

jsf components facelets dynamic-forms

21
推荐指数
2
解决办法
5万
查看次数

在同一命名容器中重用facelets组合时避免重复的id

我有一个<ui:composition>包含一些带有显式id的元素和一些引用这些id进行部分处理/更新的ajax事件.我将xhtml的这个片段封装在组合中,这样我就可以在几个不同的地方使用它,而不必复制代码.但是,当我<ui:include>在页面中多次使用合成(with )时,我会得到重复的id异常.似乎JSF没有将每个组合包装在它自己的命名容器中(就像<ui:component>那样).

有没有一种简单的方法将我的作品包装在自己的命名容器中?或者,每次我想在公共命名容器中重用xhtml片段时,是否必须使用复合组件?

jsf facelets composition jsf-2

16
推荐指数
2
解决办法
7799
查看次数

Primefaces outputLabel用于复合组件

p:outputLabel在使用复合组件时遇到问题.我有复合组件与p:inputText字段(我从组件中删除了不相关的部分):

<cc:interface>
  <cc:editableValueHolder name="myInput" targets="myInput"/>
  <cc:attribute name="required" required="true" type="java.lang.Boolean" default="false"/>
</cc:interface>

<cc:implementation>
  <p:inputText id="myInput" required="#{cc.attrs.required}"/>
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)

现在,我不会将此组件用于p:outputLabel:

<p:outputLabel for="myComponent:myInput" value="#{resources['myLabel']}:"/>
<my:myComponent id="myComponent" required="#{myBean.required}"/>
Run Code Online (Sandbox Code Playgroud)

一切正常,需要验证,也会显示消息,但*标签上没有标记,因为我将标签直接连接到p:inputText组件时.如果是我,而另一方面,硬编码required="true"p:inputText一切工作正常.

我通过调试org.primefaces.component.outputlabel.OutputLabelRenderer并发现组件被识别为UIInput,但input.isRequired()返回false.进一步调试发现该required属性尚未在组件上定义,因此它返回false默认值i UIInput:

(Boolean) getStateHelper().eval(PropertyKeys.required, false);
Run Code Online (Sandbox Code Playgroud)

此外,如果我只是p:outputLabel在复合组件内移动一切正常.像EL一样,后来在复合元件内进行评估?

我正在使用Primefaces 3.5和Mojarra 2.1.14

primefaces composite-component jsf-2

11
推荐指数
1
解决办法
7419
查看次数

如何将旧JSP的片段重构为某些JSF等价物?

ORIGINAL JSP(WorkItem.jsp)

<c:forEach var="actionItem" items="${workItem.work_action_list}">
    <c:if test="${actionItem.workActionClass.work_action_type_id == '1'}" >
       <%@ include file="inc_done_button.jsp" %>
    </c:if>
    <c:if test="${actionItem.workActionClass.work_action_type_id == '2'}" >
         <c:set var="actionItem" value="${actionItem}" scope="request" />
         <c:set var="checklist" value="${actionItem.meat}" scope="request" />
        <jsp:include page="inc_dynamic_checklist_v.jsp" flush="true" />
    </c:if>
    etc...
</c:forEach>
Run Code Online (Sandbox Code Playgroud)

原始Java

for (ListIterator<WorkflowInstanceWorkItemAction> actionIter = wfiwi.getWork_action_list().listIterator(); actionIter.hasNext();) {
    if ("2".equals(work_action_type_id)) {
        ChecklistInstanceForm ciForm = new ChecklistInstanceForm(this, authenticatedUser);
         ChecklistInstance ci = null; 
        ci = (ChecklistInstance) ciForm.getChkLstInstanceByWfiWiaOwner(wfiWorkItemAction, authenticatedUser);
    // Get the meat details for this action and inject it into the object
        wfiWorkItemAction.setMeat(ci);
    } …
Run Code Online (Sandbox Code Playgroud)

jsf jsp facelets composite-component

7
推荐指数
1
解决办法
1177
查看次数

JSF 1.2:我可以在JSF视图中创建可重用的组件

在jsf中有可能是这样的吗?

<ui:composition>
  <x:reusableCode id="editScreen">InnerHtml ... </x:reusableCode>
  code...
  <x:use component="editScreen"/>
</ui:composition
Run Code Online (Sandbox Code Playgroud)

我知道我可以创建自己的组件并在jsf tagLib中注册它,但我只需要在jsf视图文件中重用HTML.

jsf code-reuse components

6
推荐指数
1
解决办法
2664
查看次数

JSF页面中的动态操作

我有一个JSF页面。我的CommandButton动作方法值取决于bean变量值。示例:Bean headerBean具有可变的actionValue,其值为“ someBean.doAction1()”

当我使用时,它说headerBean.actionValue不是正确的方法。

如何获得作为“ someBean.doAction1”而不是headerBean.actionValue的操作值。

谢谢,

jsf icefaces

4
推荐指数
1
解决办法
1137
查看次数

切换JSF页面的替代案例

除了c:if或者c:choose,有没有更好的方法来实现几个组件中的1个组件的条件渲染.像JSF页面的开关案例?

jsf jstl facelets jsf-2

4
推荐指数
1
解决办法
8038
查看次数

在两个不同的视图中重用表单JSF

在JSF中是否可以在两个不同的视图中重用表单?我知道,ui:include但是您将如何使用例如“提交”按钮上的操作呢?还是我需要复制表格?

jsf facelets

2
推荐指数
1
解决办法
1748
查看次数