由于某些自定义组件在其属性中需要bean名称(不是bean实例),我需要在页面之间传递实际的bean名称.由于bean本身也被非自定义组件使用,我想避免使用额外的ui:param(如此处所描述的在<rich:modalPanel>中传递操作),因为它基本上指定了相同的bean.
是否可以使用提供的bean名称指定组件的操作ui:param?
基本上我试图实现以下目标:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/template.xhtml">
<ui:param name="beanName" value="sessionBean"/>
...
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
和template.xhtml是
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
template="/someothertemplate.xhtml">
</ui:define name="somename">
<h:form>
<a4j:commandButton value="test" action="#{beanName.delete}"/>
</h:form>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
虽然删除方法已正确定义(验证action="#{sessionBean.delete}"),但上面的代码给了我
javax.faces.FacesException:#{beanName.delete}:javax.el.MethodNotFoundException:/template.xhtml @ 201,89 action ="#{beanName.delete}":找不到方法:sessionBean.delete()
我有一个来自Bean的ArrayList:
...
public ArrayList<String[]> getArticleList() {
...
}
...
Run Code Online (Sandbox Code Playgroud)
我需要在JSF2上使用EL来打印这些值(使用getter方法)(例如 #{bean.articlesLage}
我怎样才能做到这一点?干杯
我在Glassfish 3上运行的JSF中有以下身份验证表单:
<h:messages globalOnly="true" errorClass="erro" />
<h:form id="form-login">
<h:outputText value="User" />
<h:message for="login-user" />
<h:inputText id="login-user"
value="#{authenticationBean.user}" showMessages="true" />
<h:outputText value="Password" />
<h:inputSecret id="login-password"
value="#{authenticationBean.password}" />
<h:commandButton id="Log in"
action="#{authenticationBean.logIn}" value="Autenticar-se" />
</h:form>
Run Code Online (Sandbox Code Playgroud)
该authentication.logIn方法是以下的一个:
public String logIn() {
user = userDAO.authenticate(user, password);
if (user != null) {
FacesMessage message = new FacesMessage("Welcome!");
message.setSeverity(FacesMessage.SEVERITY_INFO);
FacesContext.getCurrentInstance().addMessage(null, message);
return "ok";
} else {
FacesMessage message = new FacesMessage("Authentication failed");
message.setSeverity(FacesMessage.SEVERITY_ERROR);
FacesContext.getCurrentInstance().addMessage(null, message);
if ("".equals(user)) {
message = new FacesMessage("You need to …Run Code Online (Sandbox Code Playgroud) 我有跟随xhtml文件vith rich:calendar,我试图使用这个例子禁用一些天.但javascript函数永远不会被调用.我不知道为什么.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html ... >
<f:view locale="en">
<script type="text/javascript">
function isDayEnabled(day){
var date = new Date(day.date);
return (date.getDay() == 6);
}
function getDisabledStyle(day){
if (!isDayEnabled(day)) return 'rich-calendar-boundary-dates disabledDay';
}
</script>
<h:head>
<style type="text/css">
.disabledDay { background-color:gray; }
</style>
</h:head>
<h:body>
<div id="workspace">
<h:form id="form">
<h:outputText value="Datum: " />
<rich:calendar mode="ajax" id="calendar"
isDayEnabled="isDayEnabled();" dayStyleClass="getDisabledStyle();">
</rich:calendar>
....
Run Code Online (Sandbox Code Playgroud)
你可以帮帮我吗?
我正在尝试在我的应用程序中为答案创建一个输入表单,我从四个"空"答案开始,视图循环并为其创建输入字段.我有一个添加答案按钮,我将一个问题添加到答案数组,然后视图再次呈现答案,但现在有一个额外的输入字段.支持bean是视图编组的.但是,如果我在没有按下添加答案按钮的情况下提交表单,则一切正常.数据保存在数据库中.但是如果我在四个填写完后添加答案,则最后一个不会从输入字段中获取数据(answer.description).如果我先按下添加答案(不填写任何输入字段),则根本不会捕获字段中的数据,所有数据都为空,因此数据库中不会保存任何数据.
我有以下形式:
<ui:repeat var="answer" value="#{bean.answers}">
<div class="field">
<h:outputLabel for="answerAlternative-#{answer.serialNumber}"
value="Svaralternativ #{answer.serialNumber}" />
<h:inputText id="answerAlternative-#{answer.serialNumber}"
value="#{answer.description}" size="40" />
</div>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
这是创建新输入字段的方法:
public String addAnswer() {
if (answers.size() + 1 < 6) {
Answer answer = new Answer();
answer.setSerialNumber(answerSerialNumber + "");
answerSerialNumber++;
answers.add(answer);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
用于使用四个空输入字段初始化answers数组:
@PostConstruct
public void initBean() {
answers = new ArrayList<Answer>();
for (int i = 0; i < 4; i++) {
addAnswer();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用如下所示的片段来实现pinterest的pinit按钮:
<h:outputLink value="http://pinterest.com/pin/create/button/" class="pin-it-button" count-layout="horizontal">
<f:param name="url" value="#{beanOne.someMethod}/sometext{prettyContext.requestURL.toURL()}"/>
<f:param name="media" value="#{beanOne.someOtherMethod}/sometext/somemoretext/#{beanTwo.someMethodTwo}-some-text.jpg"/>
<f:param name="description" value="#{beanTwo.someOtherMethodTwo}"/>
<img border="0" src="//assets.pinterest.com/images/PinExt.png" title="Pin It" />
</h:outputLink>
Run Code Online (Sandbox Code Playgroud)
这是陷阱:
a标签需要具有非标准count-layout="horizontal"属性现在我的问题是:
所需的标记可以在http://pinterest.com/about/goodies/上找到"网站的pin it按钮"部分.
我正在创建我的第一个facelets/JSF应用程序.在我的第一页中,我添加了一个facelet模板:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<f:view>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</h:head>
<body>
<ui:insert name='top'>
<ui:include src="/templates/template_a.xhtml"></ui:include>
</ui:insert>
</body>
</f:view>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的模板页面:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</h:head>
<body>
<ui:composition template="/inwert_a.xhtml">
<ui:define name="top">
<h2>naglowek</h2>
</ui:define>
</ui:composition>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但是当我在网络浏览器中查看页面源代码时,我看到了:
<?xml version="1.0" encoding="ISO-8859-1" …Run Code Online (Sandbox Code Playgroud) 我想知道如何List<T>在Facelet中显示如下所示:
public List<T> searchByString(String string) {
return getEntityManager().createNamedQuery("Userdetails.findByUsername").setParameter("username", "%" + string + "%").getResultList();
}
Run Code Online (Sandbox Code Playgroud)
会<h:dataTable>是一个合适的方式吗?
我正在用JSF做一个项目.我创建了一个显示某些电影信息的页面.到目前为止一切都有效.现在我想实现显示有关电视剧的信息的可能性.为此,我想将所有与显示电影有关的内容放入一个子项目中,该子项目将产生一个.jar文件,然后我将包含在我的主项目中.对于电视连续剧,我会做同样的事情.
目前我只有这个项目,它的结构就像这样(我只展示相关部分):
wgmdb.war
\_ src
\_ main
\_ webapp
\_ view
\_ overview.xhtml
\_ movies
\_ details.xhtml
Run Code Online (Sandbox Code Playgroud)
在我的overview.xhtml中,我包含details.xhtml,如下所示:
我的目标是实现如下所示的东西,其中wgmdb-movies.jar是主项目包含的库:
wgmdb.war
\_ src
\_ main
\_ webapp
\_ view
\_ overview.xhtml
wgmdb-movies.jar
\_ src
\_ main
\_ resources
\_ details.xhtml
Run Code Online (Sandbox Code Playgroud)
现在的问题是,我现在已经知道如何将库中的details.xhtml包含到主项目的overview.xhtml中.我必须使用什么src路径才能找到details.xhtml?
最好的祝福,
metalhamster
似乎使用passthrough命名空间使用某些HTML 5属性存在错误,即:
<h:inputText id="text1" p:autofocus p:placeholder="this is a placeholder text"></h:inputText>
Run Code Online (Sandbox Code Playgroud)
当我尝试在Glassfish中运行页面时出现此错误:
Error Parsing /index.xhtml: Error Traced[line: 19] Attribute name "p:autofocus" associated with an element type "h:inputText" must be followed by the ' = ' character.
Run Code Online (Sandbox Code Playgroud)
请注意,占位符属性可以正常工作,只需要不需要指定值(=""),例如autofocus失败.
这是一个已知的错误?