属性 [path] 在标签错误中是必需的,但已指定路径。

huangapple go评论139阅读模式
英文:

attribute [path] is mandatory for tag error but path is specified

问题

我应用程序有两个部分,直到现在为止这两个部分是分开的。报表控制器处理报表,另一个处理显示其他信息。

现在在显示上有一个数字,当点击时,应该带用户转到报表,填充其搜索参数,并显示数字显示的结果。

所以下面是我正在尝试为其格式化数据的报表控制器的顶部部分:

@RequestMapping(value = "/searchReport", method = { RequestMethod.GET, RequestMethod.POST })
public String searchReport(@Valid @ModelAttribute("ReportModel") thisReport ReportModel, HttpServletRequest request, @RequestParam(required=false) String action, BindingResult result, Model model, HttpServletResponse response) {

我尝试了以下两种方法来解决我的绑定问题:

model.addAttribute("reportModel", new ReportModel());
model.addAttribute("reportModel", null);

这里是我试图在jsp页面上创建数据模型,以便报表控制器将其接受并显示所需结果。

<form:form method="post" id="reportForm" action="searchReport" modelAttribute="ReportModel">
	<form:input type="hidden" path="regionCode" id="regionCode" value="0" />
	<form:input type="hidden" path="locationCode" id="locationCode" value="0" />
	<form:input type="hidden" path="reportCode" id="reportCode" value="-1" />
	<form:input type="hidden" path="yearFrom" id="yearFrom" value="2020-07-22" />
	<form:input type="hidden" path="yearTo" id="yearTo" value="2020-07-22" />
	<form:input type="submit" value="submit" />
</form:form>

目前我得到的错误是

根据TLD或标签文件,属性[path]对于标签[input]是强制性的

这与其他一些问题相匹配,但它们的解决方案要么对我不起作用,要么我尝试错误地实施它们。

我以前也遇到过这个错误

我尝试过使用core_rt jar,但由于项目中没有这个jar,我不敢包含它。

当我尝试非Spring表单时,带有提交按钮的页面会加载,但是当点击提交按钮时,它会转到报表页面,但发送到控制器的对象是空的,所以我会得到一个错误Incorrect result size: expected 1, actual 0

英文:

I have two sections of my application that up until now were separate. The report controller handled the reports, and the other handled the displaying of other information.

Now on the display is a number, that when clicked, should take the user to the report and populate its search parameters and display the results that the number showed.

So below is the top of the report controller that Im trying to format the data for

@RequestMapping(value = &quot;/searchReport&quot;, method = { RequestMethod.GET, RequestMethod.POST })
	public String searchReport(@Valid @ModelAttribute(&quot;ReportModel&quot;) thisReport ReportModel, HttpServletRequest request, @RequestParam(required=false) String action, BindingResult result, Model model, HttpServletResponse response) {

Ive tried both of these to solve my binding issue(s)

model.addAttribute(&quot;reportModel&quot;, new ReportModel());
model.addAttribute(&quot;reportModel&quot;, null);

Here is where I try to create the data model on the jsp page so that the report controller will accept it and display the desired results.

&lt;form:form method=&quot;post&quot; id=&quot;reportForm&quot; action=&quot;searchReport&quot; modelAttribute=&quot;ReportModel&quot;&gt;
	&lt;form:input type=&quot;hidden&quot; path=&quot;regionCode&quot; id=&quot;regionCode&quot; value=&quot;0&quot; /&gt;
	&lt;form:input type=&quot;hidden&quot; path=&quot;locationCode&quot; id=&quot;locationCode&quot; value=&quot;0&quot; /&gt;
	&lt;form:input type=&quot;hidden&quot; path=&quot;reportCode&quot; id=&quot;reportCode&quot; value=&quot;-1&quot; /&gt;
	&lt;form:input type=&quot;hidden&quot; path=&quot;yearFrom&quot; id=&quot;yearFrom&quot; value=&quot;2020-07-22&quot; /&gt;
	&lt;form:input type=&quot;hidden&quot; path=&quot;yearTo&quot; id=&quot;yearTo&quot; value=&quot;2020-07-22&quot; /&gt;
	&lt;form:input type=&quot;submit&quot; value=&quot;submit&quot; /&gt;
&lt;/form:form&gt;

Currently the error I am getting is
>According to the TLD or the tag file, attribute [path] is mandatory for tag [input]

Which does match other questions that have been asked but their solutions are either not working for me or Im attempting to implement them wrong.

I also had this error at one point.

I have tried using core_rt jar instead, but as the project does not have that jar already, Im hesitant to include it.

When I try non-spring form, the page with the submit button loads, but when the submit is clicked, it goes to the report page, but the object sent to the controller is empty so I get an error Incorrect result size: expected 1, actual 0

答案1

得分: 0

以下是翻译好的内容:

我无法让我的解决方法正常工作,但我的其中一位同事从不同的角度着手,并帮助解决了问题。

<td class="col-md-2">
    <form:form method="post" id="Form" action="refreshTransferToReport">                               
    <button type="submit" class="btn btn-primary" name='action' value='searchBtn' id="searchBtn"><span class="glyphicon glyphicon-search" aria-hidden="true"></span>&nbsp;&nbsp;<spring:message code="common.search" /></button>
</form:form>
</td>
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes; // 没有添加此行,直到你运行时才会显示错误

@RequestMapping(value = "/refreshTransferToReport", method = {RequestMethod.GET, RequestMethod.POST})
public RedirectView refreshEnquiryToReport(HttpServletRequest request, @Valid @ModelAttribute("criteriaForm") CLU oForm, BindingResult result, Model model, @RequestParam(value="action", required=false) String action, RedirectAttributes redir)
{
    myModle thismodel = new myModel();
    
    thismodel.setRegionCode(0);
    thismodel.setLocationCode(0);
    thismodel.setCode("-1");
    thismodel.setStatusCode(0);
    thismodel.setYearFrom("2020-07-24");
    thismodel.setYearTo("2020-07-24");
    
    RedirectView redirectView = new RedirectView("/searchReport", true);
    redir.addFlashAttribute("myModel", thismodel);
    redir.addFlashAttribute("action", "searchBtn");
    return redirectView;
}
英文:

So I was unable to get my approach to the problem working, but one of my coworkers came at it from a different angle and helped to get it solved.

&lt;td class=&quot;col-md-2&quot;&gt;
    &lt;form:form method=&quot;post&quot; id=&quot;Form&quot; action=&quot;refreshTransferToReport&quot;&gt;                               
    &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; name=&#39;action&#39; value=&#39;searchBtn&#39; id=&quot;searchBtn&quot;&gt;&lt;span class=&quot;glyphicon glyphicon-search&quot; aria-hidden=&quot;true&quot;&gt;&lt;/span&gt;&amp;nbsp;&amp;nbsp;&lt;spring:message code=&quot;common.search&quot; /&gt;&lt;/button&gt;
&lt;/form:form&gt;
                            &lt;/td&gt;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes; //no errors are displayed until you run without this

@RequestMapping(value = &quot;/refreshTransferToReport&quot;, method = {RequestMethod.GET, RequestMethod.POST})
    public RedirectView refreshEnquiryToReport(HttpServletRequest request, @Valid @ModelAttribute(&quot;criteriaForm&quot;) CLU oForm, BindingResult result, Model model,@RequestParam(value=&quot;action&quot;, required=false) String action, RedirectAttributes redir)
    {
        myModle thismodel = new myModel();
        
        thismodel.setRegionCode(0);
        thismodel.setLocationCode(0);
        thismodel.setCode(&quot;-1&quot;);
        thismodel.setStatusCode(0);
        thismodel.setYearFrom(&quot;2020-07-24&quot;);
        thismodel.setYearTo(&quot;2020-07-24&quot;);
        
        RedirectView redirectView = new RedirectView(&quot;/searchReport&quot;,true);
        redir.addFlashAttribute(&quot;myModel&quot;,thismodel);
        redir.addFlashAttribute(&quot;action&quot;,&quot;searchBtn&quot;);
        return redirectView;
    }


huangapple
  • 本文由 发表于 2020年7月24日 03:56:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63062190.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定