简体   繁体   English

JSP中的表单字段不会更改Java变量

[英]form field in jsp not change java variable

I can't change the data information in my jsp page when I submit the form and call a java function(When the button is pressed). 当我提交表单并调用java函数(按下按钮时)时,无法更改jsp页面中的数据信息。

This is a peace of code used in my .jsp form field: 这是我的.jsp表单字段中使用的代码的简洁性:

...
<h:form>
<h:panelGrid columns="3">
<h:outputLabel for="contactName" value="#{msj.contactName}"/>
<h:inputText id="contactName" value="#{CustodiaBean.name}" required="true">
<f:validator validatorId = "TextValidator" />
</h:inputText>
<h:message for="contactName" styleClass="errorMessage" style="color:red"/>

<h:outputLabel for="contactLastName" value="#{msj.contactLastName}"/>
<h:inputText id="contactLastName" value="#{CustodiaBean.last_name}" required="true" >
<f:validator validatorId = "TextValidator" />
</h:inputText>
<h:message for="contactLastName" styleClass="errorMessage" style="color:red"/>
</h:panelGrid>

<div id="button">
<h:commandLink styleClass="hoveringLink3doubleGreen" action="#{CustodiaBean.updateAccount}">
<h:outputText id="save_button" value="#{msj.save_changes}"/>
</h:commandLink>
<h:commandLink styleClass="hoveringLink3double" action="myAccountCustodia">
<h:outputText id="cancel_button" value="#{msj.cancel}"/>
</h:commandLink>
</div>
</h:form>
...

This is the same piece of code used in other pages like login and register user. 这与其他页面(例如登录和注册用户)中使用的代码相同。 The form fields get the current values in "CustodiaBean", but i try to change the value in the form and when I press the button to check the value(call a function in "CustodiaBean"), I always get the previous value (The new form value is not changed in my class "CustodiaBean"). 表单字段获取“ CustodiaBean”中的当前值,但是我尝试更改表单中的值,当我按下按钮以检查值时(在“ CustodiaBean”中调用函数),我总是获取先前的值(我的类“ CustodiaBean”中的新表单值未更改)。

I'm using a tomcat server and eclipse. 我正在使用tomcat服务器和Eclipse。

Is necesary to force the field to be bloqued and save the changes when the button is pressed?? 按下按钮时是否有必要强制将该字段涂满并保存更改?

I don't know why this is happen. 我不知道为什么会这样。 Can anyone help me or give me some advice?? 谁能帮我或给我一些建议吗?

Thanks a lot in advance 在此先多谢

Does h:inputText etc also has a property name? h:inputText等是否也具有属性名称? Try to see what html is generated. 尝试看看生成了什么html。 It may be possible that your data is not getting submitted properly. 您的数据可能未正确提交。 Any HTML form directly submit feilds which are non disabled with the name property of each field. 任何HTML表单都将直接提交使用每个字段的name属性禁用的字段。 IF id is present and not name, it wont be submitted correctly. 如果存在id而不是name,则不会正确提交。 Try debugging at browser level or via some firefox plugin like tamper data. 尝试在浏览器级别或通过一些firefox插件(例如篡改数据)进行调试。

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM