Spring Web Flow พร้อมการประเมิน JSF

ฉันยังใหม่กับ Spring Webflow

นี่คือรหัสของฉัน

main-flow.xml

  <?xml version="1.0" encoding="UTF-8"?>
  <flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
    http://www.springframework.org/schema/webflow
    http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
    <var name="hello"    class="org.springframework.webflow.samples.booking.hello"/>
<view-state id="hello">
<transition on="click" to="test"></transition>
</view-state>
<action-state id="test">
<evaluate expression="hello.saytest()">
</evaluate>
<transition on="yes" to="page1" ></transition>
<transition on="no" to="page2"></transition>

</action-state>
<view-state id="page1"></view-state>
<view-state id="page2"></view-state>

  </flow>

สวัสดี.java

        package org.springframework.webflow.samples.booking;

     import java.io.Serializable;

   public class hello implements Serializable {

   String name;

  /**
   * 
   */

@Override
public String toString() {
return "hello [name=" + name + "]";
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

private static final long serialVersionUID = 1L;

public boolean saytest() {

System.out.println(name);
String test = "new";
if (name == test) {
    return true;

} else {
    return false;
}
   }
}

สวัสดี.xhtml

       <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     <ui:composition xmlns="http://www.w3.org/1999/xhtml"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:p="http://primefaces.org/ui"
            template="/WEB-INF/layouts/standard.xhtml">
     <ui:define name="notes">
<p>
    Check the calendar widget and the tooltips on the credit card fields.
    The form uses Ajax-based validations to redisplay server-side errors without refreshing the entire page.
    The booking bean backing the form is a flow-scoped object (see   <strong>booking-flow.xml</strong>).        
</p>
</ui:define>
<ui:define name="content">
 <h:form>
<h:outputLabel for="price">Enter the Name:</h:outputLabel>
<h:inputText id="name" value="#{hello.name}">
</h:inputText>
<p:commandButton id="click" action="click" value="click" />
</h:form>
</ui:define>
   </ui:composition>

ที่นี่ฉันกำลังพยายามรับค่าบางอย่างจาก hello.xhtml และลองประเมินค่าใน main-flow.xml

หากค่าที่ฉันลองเป็นค่าใหม่ จะต้องไปที่เพจ 1 หรือต้องไปที่เพจ 2.xhtml ตอนนี้ในกรณีของฉัน แม้ว่าฉันจะป้อนใหม่ในกล่องข้อความอินพุต มันก็พาฉันไปที่เพจ 2 เท่านั้น ใครสามารถช่วยฉันได้บ้าง


person bharathi    schedule 28.06.2012    source แหล่งที่มา


คำตอบ (1)


เปลี่ยน

if (name == test)

to

if (name.equals(test))

หรือเพียงแค่

if (name.equals("new"))

ดู http://www.javabeginner.com/learn-java/java-string-comparison

person dbreaux    schedule 28.06.2012
comment
นอกจากคำตอบข้างต้นแล้ว คุณสามารถใช้สถานะการตัดสินใจเป็นทางเลือกสำหรับการกำหนดเส้นทางได้ ซึ่งสะดวกกว่าเช่นนี้: ‹decision-state id=test› ‹if test=hello.saytest() then=page1 else=page2 /› ‹/สถานะการตัดสินใจ› - person Ravi Kadaboina; 29.06.2012