Struts2's judgment on the value and Struts2's judgment

Source: Internet
Author: User

Struts2's judgment on the value and Struts2's judgment
The purpose is to input the input in jsp:
<Input class = "inputstyle" type = "text" value = "<s: property value =" # result. maritalStatus "/>" name = "updatePersonalInfo. maritalStatus"/>
Select from JSP:
<Input style = "display: none;" type = "text" id = "selectMerrageValue" name = "updatePersonalInfo. maritalStatus"/>
<Select class = "selectstyle" id = "selectMerrage">
<S: if test = "# result. maritalStatus = null">
<Option value = "-- select --"> -- select -- </option>
<Option value = "yes"> Yes </option>
<Option value = "no"> NO </option>
</S: if>
<S: else>
<S: if test = "# result. maritalStatus = 'is'. toString ()">
<Option value = "yes" selected = "selected"> Yes </option>
<Option value = "no"> NO </option>
</S: if>
<S: else>
<S: if test = "# result. maritalStatus = 'no'. toString ()">
<Option value = "yes"> Yes </option>
<Option value = "no" selected = "selected"> NO </option>
</S: if>
<S: else>
<Option value = "-- select --"> -- select -- </option>
<Option value = "yes"> Yes </option>
<Option value = "no"> NO </option>
</S: else>
</S: else>
</S: else>

</Select>

And JS values:
$ (Function (){

Var maritalStatus = document. getElementById ("selectMerrage"). value

$ ("# SelectMerrageValue"). val (maritalStatus );
});

But the problem persists.

The test section is as follows:

<Input type = "text" value = "<s: property value =" # result. maritalStatus "/>"/>
Value;
<S: property value = "# result. maritalStatus"/>
Firebug check that there are values in html;
$ {Result. maritalStatus}
Firebug: Check that there are values in html.

The final result is <s: if test = "# result. maritalStatus = 'Yes' "> and <s: if test =" # result. maritalStatus = 'No' "> two sentences
The final result is that the # result. maritalStatus field is of the String type and must be set to '. toString ().


Add the found help blog: http://guokejia1986.blog.sohu.com/174626148.html

Blog content:

Struts2 uses s: if test to determine whether the attribute values of objects of the String type are equal to those of a single character.

First, the single character here is in the form of Y, male.

There are two methods:

A. <s: if test = 'news. sfsecret = "yes" '>

B. <s: if test = "news. sfsecret = 'Yes'. toString ()">

Explanation:

Because java is a strongly typed language, single quotation marks indicate the char type, while double quotation marks indicate the String type. Therefore, a can be used normally, while B needs to use the toString () method to convert the char type to the String type.



In fact, you can also use this method to change the input to select. select the JSP part:

<Input style = "display: none;" type = "text" id = "selectMerrageValue" name = "updatePersonalInfo. maritalStatus"/>

<Select class = "selectstyle" id = "selectMerrage">
<Option value = "yes" id = "selectYes"> Yes </option>
<Option value = "no" id = "selectNo"> NO </option>
</Select>

And JS values:

$ (Function (){
Var maritalStatus = "<s: property value = '# result. maritalStatus' escape = 'false'/> ";
If (maritalStatus = "yes ")
$ ("# SelectYes"). attr ("selected", selected );
Else
$ ("# SelectNo"). attr ("selected", selected );
});

In this case, the <s: if test = ""> function of Struts is not used to determine the value of a variable.



Struts2 identifies an existing tag

<S: if test = "# session. User! = Null ">
Show User Content
</S: if>
<S: else>
Show logon box
</S: else>

In this way, you can

If the struts2 if tag determines whether the list Value retrieved by the Action is null online =

<S: if test = "list = null"> the list value is empty </s: if>
<S: else> the value in the list is not empty </s: else>
Only one sentence is prompted. You can perform other operations.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.