2015-07-13 23 views
0

我是新來的Play框架。我試圖按照樣例編譯我的play framework項目。當我編譯示例時,它工作正常,並且.scala.html視圖在目標中編譯爲.class。我添加了一個新的視圖,但沒有編入目標。任何建議如何解決這個問題?我嘗試使用命令行進行激活器編譯,清理並重新構建項目,單獨構建.scala.html,但沒有一個嘗試工作。如何在Play 2.4中添加新視圖並編譯它?編譯問題新視圖.scala.html到.class

package controllers; 

import models.Client; 
import models.Server; 
import models.TestEvent; 
import models.TestPlan; 

import play.data.Form; 
import play.mvc.Controller; 
import play.mvc.Result; 
import views.formData.testFormData; 

public class Application extends Controller { 

// Default path request 
// public Result index() {return ok(index.render("Your new application is ready."));} 


/* Index Route Page 
* Returns the page where the form is filled with the arguments passed 
* Or an empty form if the id is 0 
*/ 
public static Result getIndex(long id) { 
    testFormData testData; 
    // Find the corresponding index result to return (depends on the id) 
    if(id == 0) 
     testData = new testFormData(); 
    else 
     testData = models.TestEvent.makeTestFormData(id); 

    Form<testFormData> formData = Form.form(testFormData.class).fill(testData); 
    return ok(index.render(formData, 
      Client.getClientNameList(), 
      Server.getServerNameList(), 
      TestPlan.getTestPlanNameList())); 
} 


// Process a form submission 
// Bind HTTP Post data to an instance of testFormData 
// If errors are found, re-render the page displaying the error data 
// If errors are not found, re-render the page displaying good data 
public static Result postIndex() { 
    // Retrieve the formData 
    Form<testFormData> formData = Form.form(testFormData.class).bindFromRequest(); 

    // The retrieved formData has errors 
    if(formData.hasErrors()) { 
     return badRequest(index.render(formData, 
       Client.getClientNameList(), 
       Server.getServerNameList(), 
       TestPlan.getTestPlanNameList())); 
    } 

    // The formData does not have errors 
    else { 
     // Convert the form data into a testEvent Instance 
     TestEvent testEvent = TestEvent.makeTestEventInstance(formData.get()); 

     return ok(index.render(formData, 
       Client.getClientNameList(), 
       Server.getServerNameList(), 
       TestPlan.getTestPlanNameList())); 
    } 
} 
} 

路線:

GET /       controllers.Application.getIndex(id:Long ?= 0) 

POST /       controllers.Application.postIndex() 



# Map static resources from the /public folder to the /assets URL path 
GET  /assets/*file    controllers.Assets.versioned(path="/public", file: Asset) 
+0

您的服務器是否正在運行,並且您是否有控制器操作返回新創建的視圖?當您嘗試從Web瀏覽器調用控制器操作時,您會得到什麼?這也需要更改routes.conf。 –

+0

Web瀏覽器上的錯誤是「value getIndex不是controllers.Application的成員」:GET/controllers.Application.getIndex(id:Long?= 0)我配置了routes.conf以匹配來自應用程序的操作.java文件。但是這些觀點並不在目標之中。 – TypeSource

+0

不關心視圖,無論你的路線是錯誤的還是控制器。控制器未被調用。在需要時編譯視圖,因此首先嚐試解決此問題。 –

回答

0

如果服務器沒有運行,而你的編碼,更改將不會被編譯。您可以通過打開連續編譯功能來解決此問題,每次將更改寫入文件系統時都會進行編譯。

要做到這一點:

  1. 開始激活
  2. 使用~compile

~指示的變化,應立即編譯。

你可以對服務器做類似的事情。通過使用~run,更改將立即在文件系統更改上編譯,不會延遲,直到瀏覽器刷新。

+0

感謝您的建議;不幸的是,同樣的錯誤仍然存​​在。 – TypeSource