当前位置: 首页 > 知识库问答 >
问题:

jasperException:javax.el.PropertyNotFoundException:类“java.lang.String”没有属性“user”

单于庆
2023-03-14
<!-- header -->
<%@include file="../shared/flows-header.jsp"%>

<div class = "container">


<div class = "row">

<div class = col-sm-6>

    <div class = "panel panel-primary">

        <div class = "panel-heading">

            <h4>Personal Details</h4>

        </div>

        <div class = "panel-body">

            <!-- to display personal details -->
                    <div class="text-center">
                        <h3>Name : <strong>${registerModel.user.firstname} ${registerModel.user.lastname}</strong></h3>
                        <h4>Email : <strong>${registerModel.user.email}</strong></h4>
                        <h4>Contact : <strong>${registerModel.user.contactNumber}</strong></h4>
                        <h4>Role : <strong>${registerModel.user.role}</strong></h4>

                    </div>

                    <!-- anchor tag to move to personal details page to edit -->
                    <p>
                        <a href = "${flowExecutionUrl}&_eventId_personal" class = "btn btn-primary">Edit</a>        
                    </p>
        </div>

    </div>

</div>


<div class = col-sm-6>

    <div class = "panel panel-primary">

        <div class = "panel-heading">

            <h4>Billing Address</h4>

        </div>

        <div class = "panel-body">

            <!-- to display billing address -->
                    <div class="text-center">
                        <p>${registerModel.billing.addressLineOne}, </p>
                        <p>${registerModel.billing.addressLineTwo}, </p>
                        <p>${registerModel.billing.city} -  ${registerModel.billing.postalCode}, </p>
                        <p>${registerModel.billing.state}</p>
                        <p>${registerModel.billing.country}</p>
                    </div>      

            <!-- anchor tag to move to billing address page to edit -->
            <p>
                <a href = "${flowExecutionUrl}&_eventId_billing" class = "btn btn-primary">Edit</a>
            </p>

        </div>

    </div>

</div>

<div class = "row">

    <div class = "col-sm-4 col-sm-offset-4">

        <div class = "text-center">

            <!-- anchor tag to move to success page -->
            <a href = "${flowExecutionUrl}&_eventId_submit" class = "btn btn-primary">Confirm Submission</a>

        </div>

    </div>

</div>

</div>

</div>

<!-- footer -->
<%@include file="../shared/flows-footer.jsp"%>
<?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.xsd">

    <var  name = "user" class = "model.entity.User" />
    <var  name = "billing" class = "model.entity.Address" />

    <on-start>
        <evaluate expression="'registerHandler.init()'" result = "flowScope.registerModel" />
    </on-start>


    <!-- start state -->
    <view-state id = "personal" view = "flows/register/signup-personal" model = "'user'"><!-- model value is used as modelAttribute in spring form -->
        <transition on = "billing" to = "billing" /><!-- to billing view state -->
        <on-exit>
            <evaluate expression="'registerHandler.addUser(flowScope.registerModel , user)'" />
        </on-exit>
     </view-state>

    <view-state id = "billing" view = "flows/register/signup-billing" model = "'billing'">
        <transition on = "personal" to = "personal" />
        <transition on = "confirm" to = "confirm" />
        <on-exit>
            <evaluate expression="'registerHandler.addBilling(flowScope.registerModel , billing)'" />
        </on-exit>
     </view-state>

    <view-state id = "confirm" view = "flows/register/signup-confirm" model = "flowScope.registerModel">
        <transition on = "personal" to = "personal" />
        <transition on = "billing" to = "billing" />
        <transition on = "submit" to = "submit" />  
     </view-state>

    <action-state id="submit">
        <evaluate expression="'registerHandler.saveAll(flowScope.registerModel)'" />
        <transition on = "success" to = "success" />
    </action-state>

    <!-- end state -->
    <end-state id = "home" view = "externalRedirect:contextRelative:/" />
    <end-state id = "success" view = "flows/register/signup-success" />


    <!-- global transition -->
    <global-transitions>
        <transition on = "home" to = "home"/>
    </global-transitions>

</flow>

RegisterModel类是

package flow.model;

import java.io.Serializable;

import model.entity.Address;
import model.entity.User;

public class RegisterModel implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private User user;

    private Address billing;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Address getBilling() {
        return billing;
    }

    public void setBilling(Address billing) {
        this.billing = billing;
    }


}

RegisterHandler类

package handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import flow.model.RegisterModel;
import model.dao.IUserDAO;
import model.entity.Address;
import model.entity.Cart;
import model.entity.User;

@Component
public class RegisterHandler {

    @Autowired
    private IUserDAO userDAO;

    public RegisterModel init()
    {
        System.out.println(new RegisterModel().toString());
        return (new RegisterModel());
    }

    public void addUser(RegisterModel registerModel,User user)
    {
        registerModel.setUser(user);
    }

    public void addBilling(RegisterModel registerModel,Address billing)
    {
        registerModel.setBilling(billing);
    }

    public String saveAll(RegisterModel model)
    {
        String transitionValue = "success";

        //fetch user
        User user = model.getUser();

        if(user.getRole().equals("ROLE"))
        {
            Cart cart = new Cart();
            cart.setUser(user);
            user.setCart(cart);
        }

        //save user
        userDAO.addUser(user);

        //get address
        Address billing = model.getBilling();   
        billing.setUserId(user.getId());
        billing.setBilling(true);

        //save the address
        userDAO.addAddress(billing);

        return transitionValue;
    }

}

共有1个答案

邹华皓
2023-03-14

我看到了几个可能的误解,但我认为主要的一个是在属性周围使用了单引号,而不应该使用单引号。造成这个特殊问题的原因是:

<evaluate expression="'registerHandler.init()'" result = "flowScope.registerModel" />

您将字符串值“registerhandler.init()”放入flowscope.registermodel中,而不是调用registerhandler.init()的结果。

相反,删除单引号,如下所示:

<evaluate expression="registerHandler.init()" result = "flowScope.registerModel" />
   <view-state id = "billing" view = "flows/register/signup-billing" model = "'billing'">
   <view-state id = "billing" view = "flows/register/signup-billing" model = "billing">
 类似资料:
  • 当我试图创建一个帖子时,它会显示这个错误 而我的 view.py 是 追溯: 文件"/home/zola/lib/python3.5/site-pack/django/core/handler/exception.py"在内部39.响应=get_response(请求) 文件“/home/zola/lib/python3.5/site-packages/django/core/handlers/b

  • 您好,我正在建立一个动物园微服务,包括动物、员工、客户和价格表。我的动物微服务可以工作,但在我的员工微服务中,我遇到了一个错误,即没有为类型“EmployeeModel”找到属性“name”。在问这个问题之前,我已经在网上搜索了几个小时,还有一些类似的问题。我在模型中没有“名字”employee_name,我只是感到困惑,不知道如何修复它。任何指导/建议/信息将不胜感激:)第一次发布,所以我希望我

  • 我一直试图通过ArrayList在Servlet的帮助下在JSP内部打印ResultSet。JDBC部分似乎没有问题。ArrayList可以在JSP内部获得并打印。但是当我想用标记迭代传递到JSP上的列表时,它说我的bean类'purejavaclasses.EmployeeClass'没有属性'id'。我已经尝试了很多不同的解决方案,但都是徒劳的。我不知道该怎么做。我是一个完全的JavaEE初学

  • 我得到了这个错误,我不知道问题可能在哪里。“userid”列位于数据库和bean中。有人知道吗?

  • 我的spring应用程序无法将“日期”保存到“数据库”。错误在哪里? 错误 无法将类型为[java.lang.String]的属性值转换为属性bornDate所需的类型[java.sql.Date];嵌套的异常是java。lang.IllegalArgumentException:无法解析日期:无法解析的日期:“2016-11-02” mysql 实体 控制器 艾德曼。html

  • 我已经搜索了很多页,但没有找到答案,所以我粘贴了整个代码。我正在测试测试类,并得到这样的错误:“起因:org.springframework.beans.factory.BeanCreation异常:创建名为“userRepository”的bean时出错:初始化方法调用失败;嵌套异常java.lang.IllegalArgument异常:未能为方法公共抽象创建查询org.home.mysyste