我开始使用JSF2.0我使用了一个教程作为参考,但我有以下问题:
本教程只使用2个库:jsf-api.jar
,jsf-impl.jar
(但也有JSTL)从钻嘴鱼科项目.
我试图下载它们但似乎网站无法访问.所以我使用Apache MyFaces,但运行示例我必须添加8个罐子(commons-*
,myfaces-*
).
如果我使用MyFaces,为什么还需要更多的罐子?我是否应该更喜欢Mojarra?下载页面确实是JSF Mojarra?
谢谢
从一些搜索来看,这似乎已经存在了一段时间的问题.我写了一个看起来如下的FacesConverter.对象Category是JPA实体,CategoryControl是获取它的DAO.
@FacesConverter(value = "categoryConverter")
public class CategoryConverter implements Converter {
@Inject private CategoryControl cc;
public CategoryConverter() { }
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (cc != null) return cc.getByName(value);
System.out.println("CategoryConverter().getAsObject(): no injection!");
return null;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
if (!(value instanceof Category)) return null;
return ((Category) value).getName();
}
}
Run Code Online (Sandbox Code Playgroud)
你可能已经猜到了,我从来没有注射过.我从这个页面得到了这个解决方法,看起来像这样:
Workaround for this problem: create this method in your localeController:
public Converter …
Run Code Online (Sandbox Code Playgroud) 在JSF中,有一个与每个页面关联的视图状态,它与提交等来回传递.
我知道viewstate是使用页面上各种控件的状态计算的,并且您可以将其存储在客户端或服务器端.
问题是:这个值是如何使用的?它是否用于验证在提交时发送的值,以确保不会发送相同的请求两次?
另外,它是如何计算的 - 我意识到富脸可能与myfaces的计算方式不同,但一个想法会很好.
谢谢.
我正在尝试使用MyFaces v 2.1与WebSphere Application Server Community Edition v3.0.0.1和Eclipse Juno创建一个简单的JSF Web应用程序,但是当我尝试运行该应用程序时,返回以下错误
java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
org.apache.geronimo.common.DeploymentException: java.lang.ClassNotFoundException: com.sun.faces.config.ConfigureListener
at org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder.createWebAppClassFinder(AbstractWebModuleBuilder.java:665)
at org.apache.geronimo.web25.deployment.AbstractWebModuleBuilder.configureBasicWebModuleAttributes(AbstractWebModuleBuilder.java:698)
at org.apache.geronimo.tomcat.deployment.TomcatModuleBuilder.addGBeans(TomcatModuleBuilder.java:469)
at org.apache.geronimo.j2ee.deployment.SwitchingModuleBuilder.addGBeans(SwitchingModuleBuilder.java:174)
at org.apache.geronimo.j2ee.deployment.EARConfigBuilder.buildConfiguration(EARConfigBuilder.java:764)
at org.apache.geronimo.deployment.Deployer.deploy(Deployer.java:255)
at org.apache.geronimo.deployment.Deployer.deploy(Deployer.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.geronimo.gbean.runtime.ReflectionMethodInvoker.invoke(ReflectionMethodInvoker.java:34)
at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:131)
at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:883)
at org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:245)
at org.apache.geronimo.kernel.KernelGBean.invoke(KernelGBean.java:344)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
at java.lang.reflect.Method.invoke(Method.java:611)
at org.apache.geronimo.gbean.runtime.ReflectionMethodInvoker.invoke(ReflectionMethodInvoker.java:34)
at org.apache.geronimo.gbean.runtime.GBeanOperation.invoke(GBeanOperation.java:131)
at org.apache.geronimo.gbean.runtime.GBeanInstance.invoke(GBeanInstance.java:883)
at org.apache.geronimo.kernel.basic.BasicKernel.invoke(BasicKernel.java:245)
at org.apache.geronimo.system.jmx.MBeanGBeanBridge.invoke(MBeanGBeanBridge.java:172)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:848)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:773)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1438)
at javax.management.remote.rmi.RMIConnectionImpl.access$200(RMIConnectionImpl.java:83)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1276)
at java.security.AccessController.doPrivileged(AccessController.java:284)
at …
Run Code Online (Sandbox Code Playgroud) 我正在调用模板,并传递如下参数:
<ui:include src="WEB-INF/Subviews/ProductEdit.xhtml">
<ui:param name="items" value="#{produtList}"></ui:param>
<ui:param name="itemToEdit" value="#{productToEdit}"></ui:param>
</ui:include>
Run Code Online (Sandbox Code Playgroud)
在ProductEdit.xhtml中,我有类似的东西
<ui:repeat value="#{items}" var="item">
<tr>
...
...
<td style="text-align: center">
<h:commandLink style="cssGenericColumn" action="#{productEditAction}">
<f:setPropertyActionListener target="#{itemToEdit}" value="#{item}"/>
</h:commandLink>
</td>
<tr>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.
我现在想在ProductEdit.xhtml中参数化#{productEditAction},所以我做了以下
<ui:include src="WEB-INF/Subviews/ProductEdit.xhtml">
<ui:param name="items" value="#{produtList}"></ui:param>
<ui:param name="itemToEdit" value="#{productToEdit}"></ui:param>
<ui:param name="itemEditAction" value="#{productEditAction}"></ui:param>
</ui:include>
Run Code Online (Sandbox Code Playgroud)
在第一页然后在ProductEdit.xhtml中我做
<ui:repeat value="#{items}" var="item">
<tr>
...
...
<td style="text-align: center">
<h:commandLink style="cssGenericColumn" action="#{itemEditAction}">
<f:setPropertyActionListener target="#{itemToEdit}" value="#{item}"/>
</h:commandLink>
</td>
<tr>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
这导致以下错误失败
javax.faces.el.EvaluationException: /WEB-INF/Subviews/ProductEdit.xhtml @45,89 action="#{itemEditAction}": Identity 'itemEditAction' does not reference a MethodExpression instance, returned type: java.lang.String …
Run Code Online (Sandbox Code Playgroud) 在我的JSF 1.2 webapp中,我有一个页面,<h:commandButton>
它在一个辅助bean上调用一个action方法.此操作将导致数据库中的数据被删除/替换,因此我希望避免用户意外单击命令按钮的任何情况.
我想实现一个简单的"你确定吗?" 使用JavaScript提示"是/否"或"确定/取消"选项.我对JavaScript并不擅长,之前我从未将JavaScript与JSF混合在一起.任何人都可以提供代码片段来向我展示如何实现这一点吗?
这是我的JSP页面的一部分,我在其中声明了命令按钮:
<h:commandButton
id="commandButtonAcceptDraft"
title="#{bundle.tooltipAcceptDraft}"
action="#{controller.actionReplaceCurrentReportWithDraft}"
image="/images/checkmark.gif">
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)
解:
BalusC提供的解决方案运作得很好.我还想提一下,使用资源包中的文本作为提示文本很容易.在我的页面上,我使用如下元素加载资源包:
<f:loadBundle basename="com.jimtough.resource.LocalizationResources" var="bundle" />
Run Code Online (Sandbox Code Playgroud)
的<f:loadBundle>
一定是你里面<f:view>
.然后我将BalusC提供的代码添加到我的命令按钮元素中,但用我的资源包中的字符串替换'你确定吗?' 文字,像这样:
<h:commandButton
id="commandButtonAcceptDraft"
title="#{bundle.tooltipAcceptDraft}"
action="#{controller.actionReplaceCurrentReportWithDraft}"
image="/images/checkmark.gif"
onclick="return confirm('#{bundle.confirmationTextAcceptDraft}')">
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)
我的英文资源文件中的行(只是一个带键/值对的纯文本文件)如下所示:
# text displayed in user prompt when calling confirm()
confirmationTextAcceptDraft=This will overwrite the current report and cannot be undone. Are you sure?
Run Code Online (Sandbox Code Playgroud) 在JSF应用程序中,参数javax.faces.FACELETS_REFRESH_PERIOD可用于启用/禁用XHTML文件的自动重新加载.
我目前正在研究正确的生产部署配置,并且偶然发现我们目前使用FACELETS_REFRESH_PERIOD = 1即使在生产中运行,这显然不是一个好主意.
这导致了一个问题:此参数的默认值是多少?
理想情况下,为了简单起见,我想从生产配置中省略FACELETS_REFRESH_PERIOD,并希望它使用"安全"默认值-1.但是,似乎并非如此,因为没有参数,似乎启用了刷新(使用Mojarra和MyFaces).
我检查了JSF规范,虽然它描述了参数,但它没有给出默认值.这是规范中的故意遗漏吗?
我一直试图让这个设置运行几天,但仍然没有运气.这是我一直在使用的测试应用程序:
@Named
@RequestScoped
public class Test {
private String test = "test";
public String getTest() { return test; }
public void setTest(String test) { this.test = test; }
}
Run Code Online (Sandbox Code Playgroud)
在jsf页面中:
<h:outputText value="#{test.test}"/>
Run Code Online (Sandbox Code Playgroud)
在没有MyFaces的情况下运行此示例工作正常(呈现"测试"应该如此),但是当我在WAR文件中部署MyFaces并在weblogic.xml中执行必要的配置时,CDI似乎停止工作(或者至少是JSF和CDI)并且输出html中没有显示任何内容.不过,MyFaces本身似乎没问题.
我的基本配置如下:
Weblogic.xml内容:
<prefer-application-packages>
<package-name>javax.faces.*</package-name>
<package-name>com.sun.faces.*</package-name>
<package-name>com.bea.faces.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>javax.faces.*</resource-name>
<resource-name>com.sun.faces.*</resource-name>
<resource-name>com.bea.faces.*</resource-name>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
<resource-name>META-INF/services/com.sun.faces.spi.FacesConfigResourceProvider</resource-name>
</prefer-application-resources>
Run Code Online (Sandbox Code Playgroud)
到目前为止我学到了什么:
到目前为止我尝试过的事情:
在保留CDI支持的同时在WL12c上使用MyFaces真的很难吗?或者我只是错过了明显的问题?谢谢你的帮助.
这是我的标记:
<h:commandLink value="#{partial}" action="#{hello.setCurrentPartial(partial)}">
<f:ajax render="include" listener="#{hello.renderFragments}"/>
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
我试图在Mojarra-2.2.8(wildfly 8.2.0.Final内置)和MyFaces-2.2.7(按照此处的指导安装)中运行此页面.令人惊讶的是,当点击链接时,mojarra hello.renderFragments
首先调用,然后hello.setCurrentPartial
MyFaces采用相反的顺序,即hello.setCurrentPartial
首先调用.
所以我的问题是在JSF Spec中是否有动作调用顺序和ajax监听器的定义.如果定义了订单,哪个实现是正确的?
我正在使用MyFaces在JSF中进行一些开发工作,我得到了这个警告.
*******************************************************************
*** WARNING: Apache MyFaces-2 is running in DEVELOPMENT mode. ***
*** ^^^^^^^^^^^ ***
*** Do NOT deploy to your live server(s) without changing this. ***
*** See Application#getProjectStage() for more information. ***
*******************************************************************
Run Code Online (Sandbox Code Playgroud)
开发和生产模式有什么区别?是否存在安全隐患?它只是性能增强吗?
myfaces ×10
jsf ×9
java ×3
jsf-2 ×3
cdi ×2
mojarra ×2
ajax ×1
facelets ×1
geronimo ×1
javascript ×1
jsf-2.2 ×1
performance ×1
richfaces ×1
weblogic12c ×1
websphere-ce ×1