English 中文(简体)
Save the Value of TextArea From Form
原标题:Save The Value OF TextArea From Form

I m new to Struts2 and Hibernate. I am trying to save values from the form. On submit the value of the textarea will be saved null;

我的表象是这样。

 <s:form action="saveComment">
                        <s:push value="ai">
                            <s:hidden name="id"/>
                            <table cellpadding="5px">
                                <tr><td><s:textarea name="description" rows="5" cols="60" theme="simple" />
                                    </td>
                                    <td> <s:submit type="image" src="images/sbt.gif"  >

                                        </s:submit>
                                    </td></tr>

                            </table>
                        </s:push>
                    </s:form>

and my Action Method is like this-

  public String saveComment() throws Exception {

    Map session = ActionContext.getContext().getSession();
    ExternalUser user = (ExternalUser) session.get("user");
    AIComment aiComment = new AIComment();
    aiComment.setAi(ai);
    aiComment.setPostedOn(new java.util.Date());
    aiComment.setPostedBy(user);
    aiCommentDao.saveAIComment(aiComment);
    return SUCCESS;
}
最佳回答

努力2 建立了机制,将你的形式价值转让给你尊敬的行动阶层,你们都需要采取以下步骤。

  1. Create property in you action class with same name as the form fields name and provide there getters and setters.

Struts2 will match those action property names with the names of the fields being sent from the form and will populate them for you

在你看来,你们都需要做以下工作:

public class YourAction extends ActionSupport{

  private String id;
  private String description

  getter and setters for id and description fileds

   public String saveComment() throws Exception {
      //Your Method logic goes here
   }

}

因此,当你提交表格时,表格将包含作为形式值的复制和描述。 Struts2号拦截器(此处为第1段)将看到你的行动舱有这些特性,并将在<代码>saveComment()法实施之前将其填满。

希望能给你一些理解。

简言之,所有这些繁重的工作数据转移/类型转换都是由在现场的拦截者进行的。

read the interceptors details for better understanding

  1. interceptors
  2. parameters-interceptor
问题回答

首先,你的行动名称必须是你们的别名。 然后,请具体说明方法名称。

当然,你应当界定休战的行动和方法。

    <action name="Comment_*" method="{1}" class="com.yourproject.folder.Comment">
        <result name="input">/pages/page.jsp</result>
        <result name="success" type="redirectAction">nextAction</result>
    </action>   

因此,你可以写

<s:form action="Comment_saveComment">

以及

public class Comment extends ActionSupport {

  public String saveComment() throws Exception {
    Map session = ActionContext.getContext().getSession();
    ExternalUser user = (ExternalUser) session.get("user");
    AIComment aiComment = new AIComment();
    aiComment.setAi(ai);
    aiComment.setPostedOn(new java.util.Date());
    aiComment.setPostedBy(user);
    aiCommentDao.saveAIComment(aiComment);
    return SUCCESS;
  }
}

我不知道你如何掌握“i”和“user”的价值观。 如果你想从价调汇率中获取价值,你必须申报与投入名称相同的指示数。 在你的情况下,“描述”是投入价值。 如果你想从价调汇率中获取价值,你就应当宣布这些变量在你的类别中出现和确定。

阁下,“id”

 private String Id;
 private String Description;

public String getId() {
    return Id;
}

public void setId(String Id) {
    this.Id = Id;
}

 ...




相关问题
Multiple Hibernate instances using C3P0

I am facing a weird problem and it seems to be c3p0 related. I am starting two instances of an app in the same java vm which interact with each other. After some operations "APPARENT DEADLOCK" ...

Hibernate vs Ibatis caching

We can speed up a hibernate app easyly with 2nd level cache using infinispan or ehcache/terracotta,... but ibatis only have a simple interface to implement for caching. And hibernate knows more ...

Using annotations to implement a static join in hibernate

I m relatively new to hibernate and was wondering if someone could help me out. While I have no issues implementing a normal join on multiple columns in hibernate using the @JoinColumns tag, I m ...

Hibernate query with fetch question

I have a 2 entities in a One-To-Many relationship: OfficeView.java: public class OfficeView implements java.io.Serializable { private Integer officeId; private String addr1; private ...

hibernate interceptors : afterTransactionCompletion

I wrote a Hibernate interceptor : public class MyInterceptor extends EmptyInterceptor { private boolean isCanal=false; public boolean onSave(Object entity, Serializable arg1, Object[] arg2, String[]...

How to prevent JPA from rolling back transaction?

Methods invoked: 1. Struts Action 2. Service class method (annotated by @Transactional) 3. Xfire webservice call Everything including struts (DelegatingActionProxy) and transactions is configured ...

Hibernate/GORM: collection was not processed by flush()

I have an integration test in my Grails application that fails when I try to save an entity of type Member invitingMember.save(flush: true) This raises the following exception org.hibernate....

Hibernate Criteria API equivalent for "elements()"

Is it possible to implement the following query using Criteria API? select order from ORDER as order,ITEM as item where item.itemID like ITM_01 and item in elements(order.items)

热门标签