2010-03-09 4 views
0

Как я могу получить всплывающее окно с использованием commandButton в Тринидаде?Как получить всплывающее окно с помощью commandButton в Тринидаде?

Моя проблема заключается в том, что нажав кнопку Add от dialogdemo.jspx, не открывается ни всплывающее окно, ни диалоговое окно.

Это dialogdemo.jspx файл:

<jsp:root 
    xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:tr="http://myfaces.apache.org/trinidad" 
    version="1.2"> 
    <jsp:directive.page contentType="text/html;charset=utf-8" /> 
    <f:view> 
     <tr:document title="Dialog Demo"> 
      <tr:form> 
       <!-- 
        The field for the value; we point partialTriggers at the 
        button to ensure it gets redrawn when we return 
       --> 
       <tr:inputText label="Pick a number:" partialTriggers="buttonId" 
        value="#{launchDialog.input}" /> 
       <!-- 
        The button for launching the dialog: we've also configured 
        the width and height of that window 
       --> 
       <tr:commandButton text="Add" action="dialog:chooseInteger" 
        id="buttonId" windowWidth="300" windowHeight="200" 
        partialSubmit="true" useWindow="true" 
        returnListener="#{launchDialog.returned}" /> 
      </tr:form> 
     </tr:document> 
    </f:view> 
</jsp:root> 

Вот ассоциированная управляемый компонент LaunchDialogBean.java:

package jsfpkg; 

import org.apache.myfaces.trinidad.component.UIXInput; 
import org.apache.myfaces.trinidad.event.ReturnEvent; 

public class LaunchDialogBean { 
    private UIXInput _input; 

    public UIXInput getInput() { 
     return _input; 
    } 

    public void setInput(UIXInput input) { 
     _input = input; 
    } 

    public void returned(ReturnEvent event) { 
     if (event.getReturnValue() != null) { 
      getInput().setSubmittedValue(null); 
      getInput().setValue(event.getReturnValue()); 
     } 
    } 

} 

Вот всплывающий файл Popup.jspx:

<jsp:root 
    xmlns:jsp="http://java.sun.com/JSP/Page" 
    xmlns:f="http://java.sun.com/jsf/core" 
    xmlns:h="http://java.sun.com/jsf/html" 
    xmlns:trh="http://myfaces.apache.org/trinidad/html" 
    xmlns:tr="http://myfaces.apache.org/trinidad" 
    version="2.0"> 
    <jsp:directive.page contentType="text/html;charset=utf-8" /> 
    <f:view> 
     <tr:document title="Add dialog"> 
      <tr:form> 
       <!-- Two input fields --> 
       <tr:panelForm> 
        <tr:inputText label="Number 1:" value="#{chooseInteger.value1}" 
         required="true" /> 
        <tr:inputText label="Number 2:" value="#{chooseInteger.value2}" 
         required="true" /> 
       </tr:panelForm> 

       <!-- Two buttons --> 
       <tr:panelGroup layout="horizontal"> 
        <tr:commandButton text="Submit" action="#{chooseInteger.select}" /> 
        <tr:commandButton text="Cancel" immediate="true" 
         action="#{chooseInteger.cancel}" /> 
       </tr:panelGroup> 
      </tr:form> 
     </tr:document> 
    </f:view> 
</jsp:root> 

Для этого я написал фасоль ChooseIntegerBean.java

package jsfpkg; 

import org.apache.myfaces.trinidad.context.RequestContext; 

public class ChooseIntegerBean { 

    private Integer _value1; 
    private Integer _value2; 

    public Integer getValue1() { 
     return _value1; 
    } 

    public void setValue1(Integer value1) { 
     _value1 = value1; 
    } 

    public Integer getValue2() { 
     return _value2; 
    } 

    public void setValue2(Integer value2) { 
     _value2 = value2; 
    } 

    public String cancel() { 
     RequestContext.getCurrentInstance().returnFromDialog(null, null); 
     return null; 
    } 

    public String select() { 
     Integer value = new Integer(getValue1().intValue() + getValue2().intValue()); 
     RequestContext.getCurrentInstance().returnFromDialog(value, null); 
     return null; 
    } 

} 

Вот мой faces-config.xml:

<managed-bean> 
    <managed-bean-name>chooseInteger</managed-bean-name> 
    <managed-bean-class>jsfpkg.ChooseIntegerBean</managed-bean-class> 
    <managed-bean-scope>request</managed-bean-scope> 
</managed-bean> 

<managed-bean> 
    <managed-bean-name>launchDialog</managed-bean-name> 
    <managed-bean-class>jsfpkg.LaunchDialogBean</managed-bean-class> 
    <managed-bean-scope> 
     request 
    </managed-bean-scope> 
</managed-bean> 

<navigation-rule> 
    <from-view-id>/dialogdemo.jspx</from-view-id> 
    <navigation-case> 
     <from-outcome>dialog:chooseInteger</from-outcome> 
     <to-view-id>/dialogbox.jspx</to-view-id> 
    </navigation-case> 
</navigation-rule> 

ответ

-1

попробуйте удалить /dialogdemo.jspx из вас конфигурационный файл первой. второй раз просто удалите тег/in выше перед именем файла.

+1

Просто говоря, я пытался удаление «/», и это требование для целей навигации. Они должны начинаться с «/» (в соответствии с сообщением об ошибке, которое я получил). –

2

Я думаю, что действие вашего CommandButton неправильно:

<tr:commandButton text="Submit" action="#{chooseIntegerBean.select}" windowWidth="300" windowHeight="200"     
       partialSubmit="true" useWindow="true" /> 

и в вашем ChooseIntegerBean:

public String select() 
{ 
    //other things    
    return "dialog:chooseInteger"; 
} 

и в web.xml:

<context-param><param-name>org.apache.myfaces.trinidad.ENABLE_LIGHTWEIGHT_DIALOGS</param-name><param-value>true</param-value></context-param>