我刚开始使用JSF,在提交index.xhtml时遇到了这个问题:
/index.xhtml @ 11,65 value ="#{user.name}":目标无法访问,标识符'User'已解析为null
这是我的3个文件:index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
Hello from Facelets
<h:form>
<h:inputText id="inputText" value="#{user.name}" />
<h:commandButton id="submit" value="Submit" action="home"/>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
home.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Home</title>
</h:head>
<h:body>
Welcome.
<h:form>
<h4>#{user.name}</h4>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
User.java
package com.jsf;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name = "user")
@SessionScoped
public …Run Code Online (Sandbox Code Playgroud) 我在下面的会话作用域CDI托管bean:
@Named
@SessionScoped
public class RegisterController implements Serializable {
private static final long serialVersionUID = 1L;
@Inject
private MitgliedAbc mitgliedAbc;
public MitgliedAbc getMitgliedABC() {
return mitgliedAbc;
}
public void setMitgliedAbc (MitgliedAbc mitgliedAbc) {
this.mitgliedAbc = mitgliedAbc;
}
}
Run Code Online (Sandbox Code Playgroud)
并以JSF形式输入以下内容:
<h:inputText value="#{registerController.mitgliedAbc.mgEmail}" />
Run Code Online (Sandbox Code Playgroud)
部署到GlassFish 4.1并在浏览器中打开页面时,会引发以下异常:
javax.el.PropertyNotFoundException:/register.xhtml @ 27,66 value ="#{registerController.mitgliedAbc.mgEmail}":类'com.example.RegisterController'没有可读属性'mitgliedAbc'.
这是怎么造成的,我该如何解决?
我正在尝试通过反射从JSF页面的后备bean访问某些字段的值。问题是,当我使用getter时,我会得到正确的值,但是当我使用必要字段的get(obj)方法时,我总是会返回空值。
获取beanObject:
ELContext elcontext = FacesContext.getCurrentInstance().getELContext();
Object beanObject = FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elcontext, null, beanName);
Run Code Online (Sandbox Code Playgroud)
要在不使用getter的情况下获取字段值,请执行以下操作:
List<Field> fields = new ArrayList<Field>();
ParamsBuilder.getAllFields(fields, beanClass);
for(Field field: fields) {
field.setAccessible(true);
System.out.println(field.getName() + ": " + field.get(beanObject)); //just to see if it works
}
Run Code Online (Sandbox Code Playgroud)
getAllFields方法具有以下实现:
public static List<Field> getAllFields(List<Field> fields, Class<?> type) {
for (Field field: type.getDeclaredFields()) {
fields.add(field);
}
if (type.getSuperclass() != null) {
fields = getAllFields(fields, type.getSuperclass());
}
return fields;
}
Run Code Online (Sandbox Code Playgroud)
要使用getter获取值,请执行以下操作:
private ClassX getValue(Object beanObject, Class<?> beanClass) throws Exception {
Method getter = …Run Code Online (Sandbox Code Playgroud) 我在尝试使用对象currentActeurObjetProjet时遇到问题,并使用Primefaces在对话框中显示其属性,但它一直显示此错误:
注意:/infoprojet.xhtml @ 493159值= "#{} acteurObjetProjetBean.currentActeurObjetProjet.objets.nomObjet":目标不可达, 'OBJETS' 返回null javax.el.PropertyNotFoundException:/infoprojet.xhtml @ 493159值="#{acteurObjetProjetBean. currentActeurObjetProjet.objets.nomObjet}":目标无法访问,'objets'返回null
这是备份bean:
package com.mycompany.projet;
.......
/**
*
* @author Omar
*/
@Component("etatsBean")
@Scope("session")
public class ActeurObjetProjetBean implements Serializable{
.......
private ActeurObjetProjet currentActeurObjetProjet=new ActeurObjetProjet();
.......
////////////////////////////////////////////////////////// Méthodes & fonctions\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
////////////////////////////////////////////////////////// setters & getters \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
public void setCurrentActeurObjetProjet(ActeurObjetProjet currentActeurObjetProjet)
{
this.currentActeurObjetProjet=currentActeurObjetProjet;
}
public ActeurObjetProjet getCurrentActeurObjetProjet()
{
return currentActeurObjetProjet;
}
.......
}
Run Code Online (Sandbox Code Playgroud)
这是我的页面代码:
<p:dialog header="Editer Objet" widgetVar="editobjetDialog" resizable="true" width="300" height="300" showEffect="clip" hideEffect="clip" modal="true">
<p:outputPanel id="editobjetDetail" style="text-align:center;" layout="block">
<center>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel …Run Code Online (Sandbox Code Playgroud) 在部署GAE + primefaces应用程序时,我遇到以下错误:
com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException: Error Rendering View[/CreateEmployee.xhtml]
javax.el.ELException: /CreateEmployee.xhtml: Could not find property saveEmployee in class com.fetchinglife.domain.data.dao.EmployeeRepositoryImpl
at com.sun.faces.facelets.compiler.AttributeInstruction.write(AttributeInstruction.java:94)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:302)
at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185)
Run Code Online (Sandbox Code Playgroud)
甚至saveEmployee已经EmployeeRepositoryImpl上课了.这是怎么造成的,我该如何解决?是否有任何注释我需要额外添加?
让我解释一下这个场景,假设我有一个包含人员列表的类项目,你可以搜索一个人并在项目上写下他的任务.
好吧,所以,我有一个按钮来添加导致模态的人,填充字段和搜索按钮...这个搜索按钮,导致另一个模态,这是一个简单的人搜索,你输入名称,选择从列表中选择一个,搜索模式关闭,名称转到前一个模态的outputText.
问题是,我该如何验证这个字段?我的意思是,我可以放置其他字段required = true,设置requiredMessage和ap:message.
一切正常,值,按钮,所有工作,除了该字段的验证.为了给予更多的许可,这就是我需要的:
这是我的按钮,打开模态,只有在需要条件时才会渲染,一切都很好.
<p:commandButton icon="ui-icon-search" validateClient="true" type="button" onclick="PF('modalSearchPerson').show();" rendered="#{projectMB.projectParticipant.type == 'STUDENT'}"/>
Run Code Online (Sandbox Code Playgroud)
这是显示参与者姓名的文本,由modalSearchPerson更新.
<h:outputText id="personName" title="Participant" value="#{projectMB.projectParticipant.person.name}"/>
Run Code Online (Sandbox Code Playgroud)
在h:outputText字段中,我想要的是简单到必需的东西="true"requiredMessage ="你必须选择一个人.".
我希望我说清楚,谢谢.
编辑:它必须阻止提交,如果我只更新:在MB上设置错误消息的growl,模态将关闭,我不想要那个.
我用来关闭模态的按钮有:
oncomplete="if (args && !args.validationFailed) PF('modalAddParticipant').hide();"
Run Code Online (Sandbox Code Playgroud) 大家现在我正在使用JSF 2.0和EJB3,我使用Primefaces显示错误消息或成功消息,我有两个问题是当我把Button sumit(JSF命令按钮)下一页错误显示
/register.xhtml @ 26,172 value ="#{userController.user.username}":目标无法访问,'null'返回null
我的代码是
用户实体
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.demoejb.entity;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
*
* @author KencyWindy
*/
@Entity
@Table(name = "iuser")
@NamedQueries({
@NamedQuery(name = …Run Code Online (Sandbox Code Playgroud) 我测试了这个源代码:
豆角,扁豆:
private NewAccountObj na;
public class NewAccountObj {
private int userid;
............
public NewAccountObj(int userid.............) {
this.userid = userid;
............
}
public int getUserid() {
return userid;
}
...............
}
// Getters
public NewAccountObj getDataList() {
return na;
}
Run Code Online (Sandbox Code Playgroud)
JSF 页面:
<h:panelGrid columns="2">
<h:panelGroup>User ID</h:panelGroup>
<h:panelGroup>
<h:inputText id="userid" value="#{bean.dataList['userid']}">
</h:inputText>
</h:panelGroup>
......................
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)
当我提交表格时,我得到了Target Unreachable, 'null' returned null. 你能帮我找出问题所在吗?也许这不是访问 Java 对象的正确方法h:panelGrid?
附:
我在 Glassfish 日志中收到此错误消息:
javax.el.PropertyNotFoundException: /NewAccount.xhtml @38,126 value="#{NewAccountController.dataList['userid']}": Target Unreachable, 'null' returned null
Run Code Online (Sandbox Code Playgroud) 我正在使用Netbeans 8.0.2.我使用File - > New Project - > Java Web:Web Application创建了一个非常简单的(什么是JSF)Web应用程序.
我试图在我的index.xhtml页面中打印一个@Named bean的实例变量,但它没有按预期工作.我正在使用Netbeans中的绿色"运行项目"按钮部署应用程序,该按钮自动打包,部署和启动浏览器.
在web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>MyContext</param-name>
<param-value>null</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
Run Code Online (Sandbox Code Playgroud)
的index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Facelets Hello Greeting</title>
</h:head>
<h:body>
<!-- I am expecting the beans name …Run Code Online (Sandbox Code Playgroud) jsf ×8
managed-bean ×3
primefaces ×3
cdi ×2
el ×2
java ×2
jsf-2 ×2
ejb ×1
java-ee ×1
reflection ×1
validation ×1