标签: facelets

facelets:使用ui:param将bean名称传递给action属性

由于某些自定义组件在其属性中需要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()

jsf facelets ajax4jsf

2
推荐指数
1
解决办法
1万
查看次数

JSF - 使用EL从ArrayList <String []>浏览和打印值

我有一个来自Bean的ArrayList:

...
public ArrayList<String[]> getArticleList() {
    ...
}
...
Run Code Online (Sandbox Code Playgroud)

我需要在JSF2上使用EL来打印这些值(使用getter方法)(例如 #{bean.articlesLage}

我怎样才能做到这一点?干杯

jsf facelets el jsf-2

2
推荐指数
1
解决办法
9851
查看次数

h:具有for属性的消息元素不在JSF 2中显示消息

我在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)

java glassfish facelets jsf-2

2
推荐指数
1
解决办法
5734
查看次数

<rich:calendar>客户端禁用周末

我有跟随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)

你可以帮帮我吗?

javascript jquery jsf richfaces facelets

2
推荐指数
1
解决办法
4625
查看次数

在表单提交期间不处理ui:repeat中动态添加的输入字段

我正在尝试在我的应用程序中为答案创建一个输入表单,我从四个"空"答案开始,视图循环并为其创建输入字段.我有一个添加答案按钮,我将一个问题添加到答案数组,然后视图再次呈现答案,但现在有一个额外的输入字段.支持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)

facelets jsf-2 uirepeat

2
推荐指数
1
解决办法
4144
查看次数

如何渲染<h:outputLink>的自定义属性?

我正在尝试使用如下所示的片段来实现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)

这是陷阱:

  • 整个标记是从两个不同bean的四种不同方法的组合以及一些静态文本创建的
  • url参数显然需要urlencoded,因此我在h:outputLink中使用f:param以便它们获得urlencoded
  • 生成的a标签需要具有非标准count-layout="horizontal"属性

现在我的问题是:

  • 如何将count-layout属性注入h:outputLink或生成的锚标记
  • 否则,如果我不能,那么另一种非侵入性(我不想改变bean方法)的方法来完成所需的pinit按钮标记?

所需的标记可以在http://pinterest.com/about/goodies/上找到"网站的pin it按钮"部分.

jsf facelets pinterest

2
推荐指数
1
解决办法
3569
查看次数

Facelet模板呈现两个HTML标记

我正在创建我的第一个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)

java jsf facelets

2
推荐指数
1
解决办法
2172
查看次数

如何遍历List <T>并渲染JSF Facelets中的每个项目

我想知道如何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 list facelets data-presentation

2
推荐指数
1
解决办法
5191
查看次数

如何从外部jar包含xhtml

我正在用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

jsf facelets jsf-2

2
推荐指数
1
解决办法
4136
查看次数

与元素类型"h:inputText"关联的属性名称"p:autofocus"必须后跟"="字符

似乎使用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失败.

这是一个已知的错误?

jsf html5 facelets jsf-2.2 passthrough-attributes

2
推荐指数
1
解决办法
1494
查看次数