有时,使用时<h:commandLink>,<h:commandButton>或者<f:ajax>,在action,actionListener或listener与标签相关的方法根本不被调用.或者,bean属性不会使用提交的UIInput值进行更新.
有什么可能的原因和解决方案?
我在JSF 2应用程序中使用Primefaces.我有一个<p:dataTable>,而不是选择行,我希望用户能够直接对各行执行各种操作.为此,我<p:commandLink>在最后一栏中有几个.
我的问题:如何将行ID传递给命令链接启动的操作,以便我知道要对哪一行进行操作?我尝试使用<f:attribute>:
<p:dataTable value="#{bean.items}" var="item">
...
<p:column>
<p:commandLink actionListener="#{bean.insert}" value="insert">
<f:attribute name="id" value="#{item.id}" />
</p:commandLink>
</p:column>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
但它总是产生0 - 显然在f呈现属性时行变量不可用(当我使用固定值时它可以工作).
有人有替代解决方案吗?
我们有一个更新动态包含的ajax导航菜单.包含文件各有各自的表单.
<h:form>
<h:commandButton value="Add" action="#{navigator.setUrl('AddUser')}">
<f:ajax render=":propertiesArea" />
</h:commandButton>
</h:form>
<h:panelGroup id="propertiesArea" layout="block">
<ui:include src="#{navigator.selectedLevel.url}" />
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)
它工作正常,但包含文件中的任何命令按钮在第一次单击时都不起作用.它仅适用于第二次点击.
我发现这个问题commandButton/commandLink/ajax动作/监听器方法没有被调用或输入值没有更新,我的问题在第9点描述.我明白我需要明确地包含在解决它的包<h:form>中的ID <f:ajax render>.
<f:ajax render=":propertiesArea :propertiesArea:someFormId" />
Run Code Online (Sandbox Code Playgroud)
但是,在我的情况下,表单ID事先是未知的.此表格最初也不会在上下文中提供.
上述方案有什么解决方案吗?
我正在尝试创建一个链接,在不同的窗口/选项卡中打开一个新页面,并显示一些来自支持bean的消息但是没有这样做,想知道为什么?
这是我的xhtml文件:
<html:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:body>
<h:form id="form66">
<p:commandLink actionListener="#{testing.getMessage}" action="msg.xhtml" target="_blank">get Msg</p:commandLink>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的Msg.xhtml页面
<HTML xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>testing</title>
</h:head>
<h:body>
<div class="div">
<p:panel>
<f:facet name="header">
testing
</f:facet>
<div class="paddingForPanel">
<h:outputText value="#{testing.msg}" escape="false"/>
</div>
</p:panel>
</div>
</h:body>
</HTML>
Run Code Online (Sandbox Code Playgroud)
这是我的testing.java
public void getMessage() {
this.msg = "haha";
}
private String msg;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
Run Code Online (Sandbox Code Playgroud)
上面的代码无法打开一个新的选项卡/窗口,我尝试像下面这样做,它成功在新选项卡中打开新页面但msg为空,当我调试时,它成功调用了监听器getMessage,我想知道为什么msg.xhtml页面中的msg为空?提前致谢....
<p:commandLink actionListener="#{testing.getMessage}" oncomplete="window.open('msg.xhtml')">broadcast …Run Code Online (Sandbox Code Playgroud) 我们正在使用JSF-2.1.7和我们所有的表单发布请求.我试图证明是否使用<h:commandButton>或<h:commandLink>.<h:commandLink>(href <a/>)的外观可以使用style和jQuery来控制.
哪个推荐<h:commandButton>或<h:commandLink>?有什么真正的优势吗?
当我使用以下命令链接时:
<h:commandLink action="student" value="students" />
Run Code Online (Sandbox Code Playgroud)
以下导航规则faces-config.xml:
<navigation-rule>
<from-view-id>/home.xhtml</from-view-id>
<navigation-case>
<from-outcome>student</from-outcome>
<to-view-id>/student.xhtml</to-view-id>
</navigation-case>
</navigation-rule>
Run Code Online (Sandbox Code Playgroud)
然后我得到以下开发阶段面部消息:
此链接已停用,因为它未嵌入JSF表单中.
这是怎么造成的,我该如何解决?
我知道这篇文章,我仔细检查了那里的所有可能性.
我在Glassfish 3上使用JSF 2.0和Mojarra实现.
我正在尝试使用两个简单的<h:commandLink>标签来更改应用程序语言.这是.xhtml页面:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>
<h:outputText value = "#{appMessage['page.welcome']}" />
</title>
<f:metadata>
<f:event type = "preRenderView" listener = "#{sessionController.changeLanguage}" />
</f:metadata>
</h:head>
<h:body>
<h1><h:outputText value = "#{appMessage['text.slide.welcome']}" /></h1>
<h:form id = "fm-language">
<h:commandLink action = "#{sessionController.changeLanguage('en')}" value = "#{appMessage['link.english']}" />
<h:commandLink action = "#{sessionController.changeLanguage('de')}" value = "#{appMessage['link.german']}" />
</h:form>
</h:body>
Run Code Online (Sandbox Code Playgroud)
这是HTML代码:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>The Maze Project</title>
</head>
<body>
<h1>Welcome</h1>
<form id="fm-language" …Run Code Online (Sandbox Code Playgroud) 我想从JSF页面中的链接重定向,我该怎么办?
在HTML中我可以使用<a>标签.但是在JSF中我使用<h:outputLink>或者<h:commandLink>可以有条件地渲染它们.我希望将链接重定向到同一应用程序中的其他页面或外部URL.我怎么能用JSF做到这一点?如何使用action在<h:commandLink>此?
如何<p:commandLink>不提交?仅适用于JS执行.因为<p:commandButton>我可以这样做:
<p:commandButton value="JS button" type="button" onclick="alert('clicked')"/>
Run Code Online (Sandbox Code Playgroud)
什么是模拟<p:commandLink>?
如何使用 commandLink 显示图标:
<p:commandLink
styleClass="ui-icon ui-icon-plus"
action="#{bean.doSomething}" >
<h:outputText value="Add" />
</p:commandLink>
Run Code Online (Sandbox Code Playgroud)
outputText (Add) 不可见。commandLink 支持图标的正确方法是什么?谢谢。
commandlink ×10
jsf ×8
jsf-2 ×6
primefaces ×3
action ×1
datatable ×1
icons ×1
javascript ×1
mojarra ×1
redirect ×1
undefined ×1