Jsf 2 如何使用Trinidad和facelets创建模态对话框
我试图创建一个模式对话框,当按下Jsf 2 如何使用Trinidad和facelets创建模态对话框,jsf-2,dialog,servlet-3.0,websphere-8,trinidad,Jsf 2,Dialog,Servlet 3.0,Websphere 8,Trinidad,我试图创建一个模式对话框,当按下tr:commandNavigationItem时弹出。 我可以得到一个弹出窗口,当我单击我创建的“取消”按钮时,它将调用returnListener,但弹出窗口本身不会消失。调用“提交”按钮会导致异常 网站正在使用facelets,因此调用页面具有它使用的模板 我在日志中收到以下警告: W org.apache.myfaces.trinidad.component.UIXComponentBase getClientId getClientId should n
tr:commandNavigationItem
时弹出。
我可以得到一个弹出窗口,当我单击我创建的“取消”按钮时,它将调用returnListener,但弹出窗口本身不会消失。调用“提交”按钮会导致异常
网站正在使用facelets,因此调用页面具有它使用的模板
我在日志中收到以下警告:
W org.apache.myfaces.trinidad.component.UIXComponentBase getClientId getClientId should not be called while the view is being constructed. Component ID: holdOrder_hold
及
这是调用页面(.xhtml):
...
...
以下是完整的对话框页面(.xhtml):
下面是使用的单个支持bean:
@ManagedBean
@ViewScoped
public class TaskHandler implements Serializable {
...
public void holdToDo(ActionEvent event) {
System.out.println("putting on hold");
HashMap<Object, Object> returnMap = new HashMap<Object, Object>();
try {
boolean response = ToDoHold.execute(task);
if(!response) {
returnMap.put("returnValue", "no validation errors");
}
} catch (Exception e) {
System.out.println("exception in holdToDo");
e.printStackTrace();
}
RequestContext.getCurrentInstance().returnFromDialog(Boolean.TRUE, returnMap);
}
public void handleReturnHoldDialog(ReturnEvent event) {
System.out.println("returning hold Dialog");
}
public void cancelDialog(ActionEvent event) {
System.out.println("cancelling dialog");
try {
HashMap<Object, Object> returnMap = new HashMap<Object, Object>();
returnMap.put("returnValue", "cancel");
RequestContext.getCurrentInstance().returnFromDialog(Boolean.FALSE, returnMap);
} catch(Exception e) {
System.out.println("cancelling dialog: exception");
e.printStackTrace();
}
}
...
}
@ManagedBean
@视域
公共类TaskHandler实现可序列化{
...
public void holdToDo(ActionEvent事件){
System.out.println(“暂停”);
HashMap returnMap=新的HashMap();
试一试{
布尔响应=ToDoHold.execute(任务);
如果(!响应){
returnMap.put(“returnValue”,“无验证错误”);
}
}捕获(例外e){
System.out.println(“holdToDo中的异常”);
e、 printStackTrace();
}
RequestContext.getCurrentInstance().returnFromDialog(Boolean.TRUE,returnMap);
}
public void handleReturnHoldDialog(ReturnEvent事件){
System.out.println(“返回保持对话框”);
}
公共作废取消对话框(ActionEvent事件){
System.out.println(“取消对话框”);
试一试{
HashMap returnMap=新的HashMap();
returnMap.put(“returnValue”、“cancel”);
RequestContext.getCurrentInstance().returnFromDialog(Boolean.FALSE,returnMap);
}捕获(例外e){
System.out.println(“取消对话框:异常”);
e、 printStackTrace();
}
}
...
}
使用的版本:
特立尼达2.0.1
JSF2.0
Servlet 3所以我从来没有完全解决过这个问题,但事实证明,问题是在对话框中使用了
(上面的XHTML可用)才是导致问题的原因,删除facet导致两个按钮开始正常工作。这可能是一个错误,但由于公司的指导原则,我使用的是特立尼达岛(1.26)的非最新版本。这是一个瞎猜,但不应该是:public void cancelDialog(ReturnEvent事件)感谢您的帮助!但它不起作用。cancelDialog只是对话框中应该关闭对话框的按钮。因此,我将其作为对话框内CommandButton上的ActionListener实现。将其更改为接受ReturnEvent会导致一个错误,表明它找不到该方法(因为ActionListener需要ActionEvent)。
<tr:navigationPane hint="bar" inlineStyle="width:100%;" id="completeNavBar">
...
<tr:commandNavigationItem id="holdButton" text="#{odMessages['BUTTON_HOLD_ORDER']}" partialSubmit="true" useWindow="true" rendered="#{taskHandler.holdAndReleaseEnabled}" action="dialog:holdOrder" immidiate="true" returnListener="#{taskHandler.handleReturnHoldDialog}" windowHeight="350" windowWidth="800"/>
...
</tr:navigationPane>
<ui:composition
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:tr="http://myfaces.apache.org/trinidad"
xmlns:trd="http://myfaces.apache.org/trinidad/demo"
xmlns:trh="http://myfaces.apache.org/trinidad/html">
<jsp:directive.page contentType="text/html;charset=utf-8"/>
<f:view>
<tr:document title="Put Order On Hold">
<tr:form>
<tr:messages globalOnly="true"/>
<tr:panelFormLayout>
<tr:inputText id="holdOrder_comment" rows="5" label="Comment:" value="#{taskHandler.task.holdObj.holdComment}" />
<f:facet name="footer">
<tr:commandButton id="holdOrder_hold" actionListener="#{taskHandler.holdToDo}" text="Submit" partialSubmit="true"/>
<tr:commandButton id="holdOrder_cancel" actionListener="#{taskHandler.cancelDialog}" text="cancel" partialSubmit="true"/>
</f:facet>
</tr:panelFormLayout>
</tr:form>
</tr:document>
</f:view>
</ui:composition>
@ManagedBean
@ViewScoped
public class TaskHandler implements Serializable {
...
public void holdToDo(ActionEvent event) {
System.out.println("putting on hold");
HashMap<Object, Object> returnMap = new HashMap<Object, Object>();
try {
boolean response = ToDoHold.execute(task);
if(!response) {
returnMap.put("returnValue", "no validation errors");
}
} catch (Exception e) {
System.out.println("exception in holdToDo");
e.printStackTrace();
}
RequestContext.getCurrentInstance().returnFromDialog(Boolean.TRUE, returnMap);
}
public void handleReturnHoldDialog(ReturnEvent event) {
System.out.println("returning hold Dialog");
}
public void cancelDialog(ActionEvent event) {
System.out.println("cancelling dialog");
try {
HashMap<Object, Object> returnMap = new HashMap<Object, Object>();
returnMap.put("returnValue", "cancel");
RequestContext.getCurrentInstance().returnFromDialog(Boolean.FALSE, returnMap);
} catch(Exception e) {
System.out.println("cancelling dialog: exception");
e.printStackTrace();
}
}
...
}