Spring Web-поток с оценкой JSF

Я новичок в Spring Web-потоке.

Это мой код.

основной поток.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
В дополнение к приведенному выше ответу вы можете использовать состояние решения в качестве более удобной альтернативы маршрутизации: ‹состояние решения id=test› ‹if test=hello.saytest() then=page1 else=page2 /› ‹/состояние решения› - person Ravi Kadaboina; 29.06.2012