我正在尝试ajax更新有条件渲染的组件.
<h:form>
...
<h:commandButton value="Login" action="#{login.submit}">
<f:ajax execute="@form" render=":text" />
</h:commandButton>
</h:form>
<h:outputText id="text" value="You're logged in!" rendered="#{not empty user}" />
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用.我可以保证这#{user}实际上是可用的.这是怎么造成的,我该如何解决?
jsf rendered-attribute jsf-2 conditional-rendering ajax-update
如何为<f:selectItem>标记指定条件呈现.我需要<f:selectItem>根据特定用户的状态显示选项.
例如,我想要的东西如下:
<f:selectItem itemLabel="Yes! I need a girlfriend!"
rendered="false(or some boolean condition)"
itemValue="o1"/>
Run Code Online (Sandbox Code Playgroud) 我需要给出条件
if((a == 12 and b == 13) or(a == 12 and b == 15))
Run Code Online (Sandbox Code Playgroud)
在JSF渲染属性中.
有人可以帮忙吗?
我知道我们不能重复在同一个视图树中我们拥有的任何组件的ID.
我有一个页面,其中包含某些条件的其他页面像这样......
<h:panelGroup rendered="#{bean.insertMode == 'SINGLE'}">
<ui:include src="_single.xhtml" />
</h:panelGroup>
<h:panelGroup rendered="#{bean.insertMode == 'DOUBLE'}">
<ui:include src="_double.xhtml" />
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)
现在在这些页面中,我有"几乎"相同的组件层次结构(复杂)具有不同的操作行为(不仅方法调用,还有视图),例如:
_single.xhtml
<p:inputText id="fieldID" value="#{bean.value}" />
<p:commandLink actionListener="#{bean.singleAction()}" />
Run Code Online (Sandbox Code Playgroud)
_double.xhtml
<p:inputText id="fieldID" value="#{bean.value}" />
<p:commandLink actionListener="#{bean.doubleAction()}" />
Run Code Online (Sandbox Code Playgroud)
我的小例子工作正常,并按照预期渲染,但我得到了
java.lang.IllegalStateException: Component ID fieldID has already been found in the view.
我知道JSF会处理整个页面,即使它们没有被包含在内,这就是我得到这个例外的原因.
任何聪明的方法来解决这个问题,而无需更改包含页面内的组件的ID(虽然它的工作原理,但异常是烦人的,似乎有些不对劲).
我也不想用一些具有不同ID的容器组件来包装每个页面,因此它们将具有不同的FULL ID,如formId:fieldID,因为母版页也指这些组件中的这些组件!
我想按照以下方式做一些事情但是当我像这样使用它时,我得到一个解析错误告诉我实体需要直接跟随'&'字符:
<ice:selectManyCheckbox
rendered="#{!bean1.condition1 && bean2.condition2}"
value="#{bean1.selected}">
<f:selectItems value="#{bean2.items}" />
</ice:selectManyCheckbox>
Run Code Online (Sandbox Code Playgroud)
如何渲染以检查来自2个不同bean的条件?
我有一个简单的复合组件,带有一个可选的ajax监听器,使用richfaces a4j:ajax组件实现.
这是接口定义:
<!-- INTERFACE -->
<composite:interface name="inplaceInput">
<composite:attribute name="value" required="true" />
<composite:attribute name="render" default="@this" />
<composite:attribute name="ajaxListener" method-signature="void actionListener(javax.faces.event.AjaxBehaviorEvent)" />
</composite:interface>
Run Code Online (Sandbox Code Playgroud)
以下代码使用两个具有相反呈现条件的重复块正常工作:
<composite:implementation>
<rich:inplaceInput value="#{cc.attrs.value}" rendered="#{!empty cc.attrs.ajaxListener}">
<a4j:ajax event="change" render="#{cc.attrs.render}" execute="@this" listener="#{cc.attrs.ajaxListener}" />
</rich:inplaceInput>
<rich:inplaceInput value="#{cc.attrs.value}" rendered="#{empty cc.attrs.ajaxListener}">
<a4j:ajax event="change" render="#{cc.attrs.render}" execute="@this" />
</rich:inplaceInput>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)
但是我想避免重复,因为我的组件要复杂得多......
在a4j上使用渲染条件:ajax是我的第一个想法:
<rich:inplaceInput value="#{cc.attrs.value}">
<a4j:ajax event="change" render="#{cc.attrs.render}" execute="@this" listener="#{cc.attrs.ajaxListener}" rendered="#{!empty cc.attrs.ajaxListener}" />
<a4j:ajax event="change" render="#{cc.attrs.render}" execute="@this" rendered="#{empty cc.attrs.ajaxListener}" />
</rich:inplaceInput>
Run Code Online (Sandbox Code Playgroud)
但它不起作用,错误很明显:
javax.faces.FacesException: Unable to resolve composite component from using page using EL expression '#{cc.attrs.ajaxListener}' …Run Code Online (Sandbox Code Playgroud) 我有一个数字值p:dataTable.当值小于0时,应插入" - "符号而不是值.
我试过用c:if,哪个不行.我正在阅读,人们建议rendered国旗.
代码是:
<p:column headerText="Valor">
<h:outputText rendered="${valor.valor > 0}" value="${valor.valor}" />
<h:outputText rendered="${valor.valor <= 0}" value="${valorMB.noDato}" />
</p:column>
Run Code Online (Sandbox Code Playgroud)
并且服务器给我这个错误:
与元素类型"h:outputText"关联的属性"rendered"的值不得包含"<"字符
如果我使用c:if表没有数据:
<c:if test="#{valor.valor > 0}">
<h:outputText value="#{valor.valor}" />
<c:otherwise>
<h:outputText value="-" />
</c:otherwise>
</c:if>
Run Code Online (Sandbox Code Playgroud)
我该如何解决我的问题?
我不明白为什么这段代码工作正常:
<h:link value="Login" rendered="#{sessionBean.userInSessionBean == null}" />
Run Code Online (Sandbox Code Playgroud)
而这段代码不起作用:
<a jsf:rendered="#{sessionBean.userInSessionBean == null}">Login</a>
Run Code Online (Sandbox Code Playgroud) 我有一个<h:panelGroup>带有rendered属性的标签。它调用以确定它是否呈现的函数返回 true,我已经记录并打印了这一点以确保。
结构如下:
<h:form>
<div><!-- content --></div>
<h:panelGroup>
<h:panelGroup rendered="#{bean.function(parameter)} == true">
<!-- content -->
</h:panelGroup>
<h:panelGroup>
</h:form>
Run Code Online (Sandbox Code Playgroud)
即使函数返回 true,带有渲染标签的 panelGroup 也永远不会显示。知道为什么这不起作用吗?
我试过下面的代码
<h:form rendered="{#{cars.enabled} and #{cars.enabledEdit}}">
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
下表中显示的数据也会显示在我的网络应用程序中.除了BOOKINGNO列,而不是列h:commandButton.只有BOOKINGNO在相应行上的记录为null时,才应呈现commandButton .
目前,使用下面的代码,按钮不会呈现.
PLOTNO SITENO ACCOMNO STARTDATE ENDDATE BOOKINGNO
16 1 10 2014-10-01 2014-10-03 <null>
21 2 2 2014-09-26 2014-09-29 923291
22 2 3 2014-10-01 2014-10-03 <null>
23 2 7 2014-09-26 2014-09-29 457235
<h:dataTable>
...
<h:column>
<h:commandButton
onclick="if (!confirm('Do you want to book this holiday?')) return false"
value="Book"
action="#{dealsBean.book(item.plotNo)}"
rendered="#{dealsBean.bookingNo = null}">
</h:commandButton>
</h:column>
/<h:dataTable>
Run Code Online (Sandbox Code Playgroud)
我尝试了各种不同的rendered论点,但似乎都没有做我想要的.
我的语法是否正确?
Mojarra 2.1.
我检查public void execute(FacesContext facesContext) throws FacesException了班上的方法com.sun.faces.lifecycle.RestoreViewPhase.现在,一旦视图通过invokation恢复, viewRoot = viewHandler.restoreView(facesContext, viewId);我们就可以获得前一个请求中的竞争树(如果它是回发).
我检查了那棵树(手动迭代children调试器中组件的属性)并发现复合组件,声明如下:
<h:panelGroup rendered="#{bean.id == 1}">
<utils:dropDownListFilterItem />
</h:panelGroup>
<h:panelGroup rendered="#{bean.id == 2}">
<utils:dateFilterItem />
</h:panelGroup>
<h:panelGroup rendered="#{bean.id == 3}">
<utils:fieldFilterItem />
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)
都在那棵树里.尽管#{bean.id}被评估为2 ,但它很高兴.我发现唯一的<utils:dateFilterItem />实例将在树中.
所以,我的问题是renderedMojarra 如何处理属性?属性是否会影响唯一的渲染响应阶段?
由于我将在页面上显示表格,因此某些元素没有任何价值。但元素具有一个值,可以形成到另一个页面的链接。现在它什么也没显示,既没有价值也没有价值。
我是 Java 新手,不明白我的代码中写错了什么。
这是我的代码:
<h:link outcome="schoolclass-detail" value="#{la.participant.schoolclass.classname}" rendered="{!la.participant.schoolclass.classname==null}">
<f:param name="schoolclassId" value="#{la.participant.schoolclass.id}" />
</h:link>
Run Code Online (Sandbox Code Playgroud)
提前感谢所有帮助!